survos/maker-bundle

用于生成管理界面的控制器和模板的工具

资助包维护!
kbond

安装次数: 1,635

依赖: 0

建议者: 0

安全: 0

星标: 3

关注者: 3

分支: 0

开放问题: 0

类型:symfony-bundle

1.5.340 2024-09-16 11:21 UTC

This package is auto-updated.

Last update: 2024-09-24 13:45:16 UTC


README

一些替代 Symfony maker 命令的选择。

survos:make:controller

Symfony make:controller 命令非常有限。它创建一个文件和模板,但无法设置路由或方法名,仅提供 app_app 和 index.html.twig。

survos:make:controller 命令允许创建控制器类和单个控制器方法。

bin/console survos:make:controller-class Admin \
  --inject "App\\Repository\\UserRepository"
  --route="admin_list_users"
  --method="listUsers"
  --security="IsGranted('ROLE_ADMIN')"

唉。大部分都是过时的,需要清理。抱歉。

关于 survos:make:bundle 的特别说明

仅限在 survos 内创建包。实际上,由于这个限制,它甚至不应该包含在 maker-bundle 中,尽管理论上它应该可以工作。

从 survos/survos 仓库运行

bin/console survos:make:bundle foo-bundle

nette 生成器错误

symfony new bug --webapp && cd bug
composer require nette/php-generator
cat > src/Controller/AppController.php << 'END'
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Nette\PhpGenerator\ClassType;
class AppController extends AbstractController
{
    #[Route('/', name: 'app_generate_class')]
    public function generateClass(): Response
    {
      $class = new ClassType('DemoController');
      
      $class
          ->setFinal()
          	->setExtends(AbstractController::class)
//      	->addImplement(Countable::class)
          ->addComment("Class description.\nSecond line\n")
          ->addComment('@property-read Nette\Forms\Form $form');

// generate code simply by typecasting to string or using echo:
        return new Response($class, 200, ['Content-Type' => 'text/plain']);
    }
}

END

symfony server:start -d
symfony open:local
symfony new --webapp maker-demo && cd maker-demo
composer require survos/maker-bundle --dev
composer require survos/core-bundle

# make an entity, using the symfony command

# Create a command line program to load the data.  
bin/console survos:make:command app:load-congress -barg purge
cat < EOL | bin/console survos:class:update -m __invoke \n
  --use Doctrine\ORM\EntityManagerInterface \n
  --inject EntityManagerInterface$em
dd('test')  
EOL

bin/console survos:make:command app:show-congress --oarg pattern "Show a list of representatives" --oint-arg limit 



此包依赖于 Symfony 的 Maker Bundle,因此请先安装它。

composer req symfony/maker-bundle --dev

composer config minimum-stability dev
composer config prefer-stable true


composer config repositories.survos_maker_bundle '{"type": "vcs", "url": "git@github.com:survos/AdminMakerBundle.git"}'
composer req survos/maker-bundle 


composer config repositories.survos_base_bundle '{"type": "vcs", "url": "git@github.com:survos/BaseBundle.git"}'
composer req survos/base-bundle:"^2.0.3"

composer config repositories.ux-datatable '{"type": "vcs", "url": "git@github.com:tacman/ux-datatable.git"}'
composer req tacman/ux-datatable

composer require umbrella2/adminbundle
php bin/console make:admin:home

composer config repositories.survos_workflow '{"type": "vcs", "url": "git@github.com:survos/workflow-bundle.git"}'

bin/console make:entity -a Entity

bin/console survos:make:crud Entity

将创建

@TODO

  • 从伞扩展
  • 添加 DataTableBundle(ux 组件)
  • 将 #[RouteParameter] 添加到实体属性。
  • 让 ParamConverter 通过属性监听
  • 添加 LandingBundle(make:landing)
  • Symfony 5.4 或 6

Survos Admin Bundle

一个有一定偏见的包,可以快速使用 Symfony。
特别是,它设置了以下内容

  • AdminLTE4(Bootstrap 5)
  • Knp Menu 用于侧边栏和顶部导航
  • webpack encore
  • 可选 jQuery(用于 js-tree 和 datatables)

假设

尽管以下内容可以禁用,但默认情况下,该包假设您想要以下内容

  • 身份验证
  • 用户和管理员角色
  • 用户
  • API(用于 Vue、DataTables)
  • Bootstrap 5、图标
  • 可在 Heroku 上部署

流程

转到 ... 并填写表单,运行脚本以创建 Symfony shell。


Then in app.js

```javascript
require('adminkit/static/js/app');
require('../css/app.scss');

以及 app.scss

@import "~adminkit/static/css/app.css";

更改 app.js

require('@popperjs/core');
require('bootstrap');
require('Hinclude/hinclude');
require('./css/app.scss');
@import "~bootstrap/dist/css/bootstrap.min.css";
@import "../../public/bundles/survosbase/volt-dist/css/volt.css";

目标

此包最初创建是为了隔离其他包的问题,并尽可能快速且轻松地获取网站上的数据。

一些值得检查的主题

https://github.com/xriley/portal-theme-bs5(请检查许可证) https://github.com/zuramai/voler

要求

  • composer
  • PHP 7.2+
  • yarn
  • Symfony CLI(用于运行本地服务器、创建项目等。)

创建 GitHub 项目

在 github.com 上创建项目,无文件(无 README 或许可协议),克隆到某个目录并进入。

 REPO=base-bundle-demo 
 git clone git@github.com:survos/$REPO.git && cd $REPO 
  • 创建不带 git 仓库的 Symfony 框架,然后添加该仓库。允许配方
rm -f LICENSE && rm -f README.md && mv .git .. && symfony new --full . --no-git --version=5.4 && mv ../.git . && git checkout .
composer config extra.symfony.allow-contrib true
composer req webapp && yarn install && yarn encore dev
  • 在 Heroku 上创建项目,登录后。可选创建数据库。

或者如果您使用 Sqlite。

heroku create $REPO
heroku addons:create heroku-postgresql:hobby-dev
echo "DATABASE_URL=$(heroku config:get DATABASE_URL)" > .env.heroku.local
# Without heroku, use sqlite (or setup MySQL)
echo "DATABASE_URL=sqlite:///%kernel.project_dir%/var/data.db" > .env.local

我们总是希望有一些安全性,因此某些路由可以受到保护。创建一个用户实体,然后创建一个 LoginFormAuthenticator。调整 AppAuthenciator 以在成功登录后返回主页。设置 MAILER_URL 为默认值。

bin/console make:user User --is-entity --identity-property-name=email --with-password -n
#sed -i "s|public function getEmail| public function getUsername() { return \$this->getEmail(); }\n\n public function getEmail|" src/Entity/User.php

sed -i "s|# MAILER_DSN|MAILER_DSN|" .env


echo "1,AppAuthenticator,SecurityController,/logout," | sed "s/,/\n/g"  | bin/console make:security
sed -i "s|// For example.*;|return new RedirectResponse(\$this->urlGenerator->generate('app_homepage'));|" src/Security/AppAuthenticator.php 
sed -i "s|throw new \\Exception\('TODO\: provide a valid redirect inside '\.__FILE__\);||" src/Security/AppAuthenticator.php 

可选的,因为 SurvosBaseBundle 已经有了,适用于移动端的格式

bin/console make:registration-form

现在安装 Survos BaseBundle

composer config minimum-stability dev
composer config prefer-stable true

composer config repositories.knp_markdown '{"type": "vcs", "url": "git@github.com:tacman/KnpMarkdownBundle.git"}'
composer req knplabs/knp-markdown-bundle:dev-symfony6

composer config repositories.survos_base_bundle '{"type": "vcs", "url": "git@github.com:survos/BaseBundle.git"}'
composer config repositories.ux-datatable '{"type": "vcs", "url": "git@github.com:tacman/ux-datatable.git"}'
composer req tacman/ux-datatable

composer require umbrella2/adminbundle
php bin/console make:admin:home

composer config repositories.cs_fixer '{"type": "vcs", "url": "git@github.com:tacman/PHP-CS-Fixer.git"}'
composer config repositories.survos_workflow '{"type": "vcs", "url": "git@github.com:survos/workflow-bundle.git"}'
composer config repositories.tabler '{"type": "vcs", "url": "git@github.com:survos/TablerBundle.git"}'
composer req survos/base-bundle:"^2.0.3"
composer req survos/tabler-bundle:dev-tac

composer require symfony/webpack-encore-bundle
yarn install
yarn add sass-loader@^11.0.0 sass --dev
yarn add https://github.com/survos/adminkit.git

#echo '@import "~bootstrap/dist/css/bootstrap.min.css";' > assets/styles/app.scss
#echo '@import "../../public/bundles/survosbase/volt-dist/css/volt.css";' >>assets/styles/app.scss
## FIRST, initialize SurvosBase, which creates app.scss.  Then fix webpack.

sed -i "s|//.enableSassLoader()|.enableSassLoader()|" webpack.config.js
sed -i "s|import './styles/app.css';|import './styles/app.scss';|" assets/js/app.js

yarn install

yarn add "@symfony/webpack-encore@^1.0.0"
yarn add "@symfony/stimulus-bridge@^2.0.0"
yarn add bootstrap@next

yarn add datatables.net-bs5 datatables.net-buttons-bs5 datatables.net-scroller datatables.net-scroller-bs5 datatables.net-select-bs5 datatables.net-searchpanes datatables.net-searchpanes-bs5 datatables.net-colreorder datatables.net-colreorder-bs5

仅限 Survos 开发

composer config repositories.survos_base_bundle '{"type": "path", "url": "../Survos/BaseBundle"}'
composer config repositories.geonames '{"type": "path", "url": "../Survos/geonames-bundle"}'
composer config repositories.phpspreadsheet '{"type": "path", "url": "../Survos/phpspreadsheet-bundle"}'

@TODO: 配方!

composer config repositories.multisearch '{"type": "vcs", "url": "git@github.com:tacman/PetkoparaMultiSearchBundle.git"}'

repositories.captcha '{"type": "vcs", "url": "git@github.com:cyrilverloop/symfony-captcha-bundle.git"}'

composer config repositories.git-survosbase '{"type": "vcs", "url": "https://github.com/survos/BaseBundle.git"}'

composer config repositories.git-geonames '{"type": "vcs", "url": "https://github.com/survos/geonames-bundle.git"}'

composer config repositories.flowdemo '{"type": "path", "url": "../Survos/../CraueFormFlowDemoBundle"}'


composer config repositories.social_post_bundle '{"type": "path", "url": "../Survos/social-post-bundle"}'

composer config repositories.social_post_bundle '{"type": "vcs", "url": "https://github.com/tacman/social-post-bundle"}'

# this is needed because it creates MAILER_DSN, which isn't created otherwise
# composer req mail
composer req knplabs/knp-menu-bundle:"^3.0@dev"

composer req survos/base-bundle:"*@dev"
phpstorm .env

或者

步骤 1:通过 Survos Init 初始化 Yarn 包

# creates survos_base.yaml (a recipe would be nicer!)    
bin/console survos:init

# edit .env and set MAILER_URL

唉,还是不行,需要基本菜单

# introspection, creates menus, looks for entities, easyadmin, etc.
bin/console survos:configure
 
# symfony run -d yarn encore dev --watch

集成 Facebook 和其他 OAuth

访问 https://github.com/knpuniversity/oauth2-client-bundle#step-1-download-the-client-library

例如:

composer require league/oauth2-facebook

创建一个应用并启用登录: https://developers.facebook.com/apps/

需要一个配置脚本,询问 ID 并将其设置在 .env.local(或 Heroku 等)中

https://developers.facebook.com/apps/558324821626788/settings/basic/

安装和配置 UserBundle(可选)

见 [docs/recommended_bundles]

如果开发 BaseBundle

composer config repositories.survosbase '{"type": "path", "url": "../Survos/BaseBundle"}'
composer req survos/base-bundle:"*@dev"

正常安装

安装包,然后通过设置过程添加和配置工具。

composer req survos/bootstrap-bundle

bin/console doctrine:schema:update --force

survos:init

首次设置,下载 jQuery、Bootstrap 等。还会 修改 一些 yaml 文件,并创建第一个菜单。

# config/packages/admin_lte.yaml

    routes:
        adminlte_welcome: app_homepage
        adminlte_login: app_login
        adminlte_profile: app_profile

@todo: 生成这个控制器和模板?

# config/routes/survos_base.yaml
survos_base: {path: /, controller: 'Survos\BootstrapBundle\Controller\BaseController::base'}
# app_homepage: {path: /, controller: 'Survos\BootstrapBundle\Controller\LandingController::base'}
app_logo: {path: /logo, controller: 'Survos\BootstrapBundle\Controller\BaseController::logo'}
app_profile: {path: /profile, controller: 'Survos\BootstrapBundle\Controller\BaseController::profile'}
# profile: {path: /profile, controller: 'Survos\BootstrapBundle\Controller\LandingController::profile'}
# logout: {path: /logout, controller: 'Survos\BootstrapBundle\Controller\LandingController::logout'}
# required if app_profile is used, since you can change the password from the profile
app_change_password: {path: /change-password, controller: 'Survos\BootstrapBundle\Controller\BaseController::changePassword'}

{% extends '@SurvosBaseBundle/layout/default-layout.html.twig' %} {% block page_content %} {{ block('body') }} {% endblock %}

{% block logo_mini %}KPA{% endblock %} {% block logo_large 'KPA Admin' %}

{% block page_title 'KPA Admin' %} {% block page_subtitle '歌曲和音乐!' %}

2021 年目标:移除 jQuery

https://tobiasahlin.com/blog/move-from-jquery-to-vanilla-javascript/

使用 vue 或 react 代替。 https://www.smashingmagazine.com/2020/07/desktop-apps-electron-vue-javascript/k

现在安装一些包!

See the details at [Recommended Bundles](docs/recommended-bundles.md)

如果您选择集成用户包,则更新模式并添加管理员

bin/console doctrine:schema:update --force

symfony server:start --no-tls

完成时,应用程序将具有一个基本的基页,包含顶部导航,可选地包括登录/注册页面。具有 ROLE_ADMIN 角色的登录用户还将(可选地)有到 easyadmin 和 api-platform 的链接。

Api Platform

@todo: 将此放入一个 survos:setup 命令中。

  • 公开 API 路由(对于 jsRoutingBundle),并
# config/routes/api_platform.yaml
api_platform:
    resource: .
    type: api_platform
    prefix: /api
    options:
        expose: true

创建 resources.yaml 文件以存储配置

# api/config/api_platform/resources.yaml
App\Entity\User: ~
App\Entity\Location:
  shortName: 'Location'                   # optional
  description: 'A place within a building where inventory item is physically located.' # optional
  attributes:                          # optional
    pagination_items_per_page: 30   # optional
    normalization_context:
      groups: ['jstree']
    denormalization_context:
      groups: ['jstree']

将 resources.yaml 目录添加到映射路径

# config/packages/api_platform.yaml
api_platform:
    mapping:
        paths:
            - '%kernel.project_dir%/src/Entity'
            - '%kernel.project_dir%/config/api_platform' # yaml or xml directory configuration]
    patch_formats:
        json: ['application/merge-patch+json']
    swagger:
        versions: [3]

配置序列化器(可能需要创建目录)

# config/serializer/serialization.yaml
App\Entity\User:
  attributes:
    id:
      groups: ['Default']
    email:
      groups: ['Default']

App\Entity\Song:
  attributes:
    title:
      groups: ['Default']

自定义包

部署到 Heroku

heroku create $projectName 
heroku buildpacks:add heroku/php
heroku buildpacks:add heroku/nodejs

echo "web:  vendor/bin/heroku-php-nginx -C heroku-nginx.conf  -F fpm_custom.conf public/" > Procfile

heroku buildpacks:add heroku/nodejs
heroku buildpacks:add --index 2 heroku/nodejs


composer config --unset repositories.survosbase && composer update
git commit -m "unset survosbase" . && git push heroku master

https://devcenter.heroku.com/articles/deploying-symfony4 bin/console survos:setup-heroku

替代方案

https://github.com/xriley/portal-theme-bs5