symplify/symfony-static-dumper

This package is abandoned and no longer maintained. The author suggests using the a static website service package instead.

Dump Symfony application to Static Website

Installs: 60 263

Dependents: 0

Suggesters: 0

Security: 0

Stars: 55

Watchers: 4

Forks: 2

Type:symfony-bundle

11.1.26 2023-02-02 05:04 UTC

This package is auto-updated.

Last update: 2023-02-18 15:21:49 UTC


README

Downloads total

Dump your Symfony app to HTML + CSS + JS only static website. Useful for deploy to Github Pages and other non-PHP static website hostings.

Install

composer require symplify/symfony-static-dumper

Add config to config/config.php:

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyStaticDumper\ValueObject\SymfonyStaticDumperConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator->import(SymfonyStaticDumperConfig::FILE_PATH);
};

Controller with Argument

To make Controller with argument, eg: /blog/{slug}, statically dumped, you have to implements Symplify\SymfonyStaticDumper\Contract\ControllerWithDataProviderInterface and implements 3 methods:

  • getControllerClass()
  • getControllerMethod()
  • getArguments()

For example, with the following provider:

namespace TomasVotruba\SymfonyStaticDump\ControllerWithDataProvider;

use Symplify\SymfonyStaticDumper\Contract\ControllerWithDataProviderInterface;
use TomasVotruba\Blog\Controller\PostController;
use TomasVotruba\Blog\Repository\PostRepository;

final class PostControllerWithDataProvider implements ControllerWithDataProviderInterface
{
    private PostRepository $postRepository;

    public function __construct(PostRepository $postRepository)
    {
        $this->postRepository = $postRepository;
    }

    public function getControllerClass(): string
    {
        return PostController::class;
    }

    public function getControllerMethod(): string
    {
        return '__invoke';
    }

    /**
     * @return string[]
     */
    public function getArguments(): array
    {
        $slugs = [];

        foreach ($this->postRepository->getPosts() as $post) {
            $slugs[] = $post->getSlug();
        }

        return $slugs;
    }
}

For the following controller:

namespace TomasVotruba\Blog\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use TomasVotruba\Blog\Repository\PostRepository;
use TomasVotruba\Blog\ValueObject\Post;

final class PostController extends AbstractController
{
    private PostRepository $postRepository;

    public function __construct(PostRepository $postRepository)
    {
        $this->postRepository = $postRepository;
    }

    /**
     * @Route(path="/blog/{slug}", name="post_detail", requirements={"slug"="\d+\/\d+.+"})
     */
    public function __invoke(string $slug): Response
    {
        $post = $this->postRepository->getBySlug($slug);

        return $this->render('blog/post.twig', [
            'post' => $post,
            'title' => $post->getTitle(),
        ]);
    }
}

Use

vendor/bin/console dump-static-site

The website will be generated to /output directory in your root project.

Do you want to modify the /public directory yourself?

vendor/bin/console dump-static-site --public-directory another-public --output-directory custom-output

To see the website, just run local server:

php -S localhost:8001 -t output

And open localhost:8001 in your browser.


Report Issues

In case you are experiencing a bug or want to request a new feature head over to the Symplify monorepo issue tracker

Contribute

The sources of this package are contained in the Symplify monorepo. We welcome contributions for this package on symplify/symplify.