定制 symplify/symfony-static-dumper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

symplify/symfony-static-dumper

最新稳定版本:11.1.26

Composer 安装命令:

composer require symplify/symfony-static-dumper

包简介

Dump Symfony application to Static Website

README 文档

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.

统计信息

  • 总下载量: 60.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 55
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 55
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固