symplify / symfony-static-dumper
Dump Symfony application to Static Website
Package info
github.com/deprecated-packages/symfony-static-dumper
Type:symfony-bundle
pkg:composer/symplify/symfony-static-dumper
Requires
- php: >=8.1
- symfony/config: ^6.2
- symfony/console: ^6.2
- symfony/dependency-injection: 6.1.*
- symfony/filesystem: ^6.2
- symfony/finder: ^6.2
- symfony/http-foundation: ^6.2
- symfony/routing: ^6.2
- symplify/autowire-array-parameter: ^11.2
- symplify/package-builder: ^11.2
- symplify/smart-file-system: ^11.2
- symplify/symplify-kernel: ^11.2
Requires (Dev)
- php-parallel-lint/php-parallel-lint: ^1.3
- phpstan/extension-installer: ^1.2
- phpstan/phpstan: ^1.9.7
- phpunit/phpunit: ^9.5.26
- rector/rector: ^0.15.10
- symfony/framework-bundle: 6.1.*
- symfony/twig-bundle: 6.1.*
- symplify/easy-ci: ^11.1
- symplify/easy-coding-standard: ^11.1
- symplify/phpstan-extensions: ^11.1
- tomasvotruba/unused-public: ^0.0.34
This package is auto-updated.
Last update: 2023-02-18 15:21:49 UTC
README
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.