ekino / drupal-bundle
集成Symfony2与Drupal
Requires
- php: >=5.5.9
- doctrine/common: ^2.6
- doctrine/orm: ^2.5
- friendsofsymfony/user-bundle: ^2.1
- psr/log: ^1.1
- symfony/config: ^3.4
- symfony/dependency-injection: ^3.4
- symfony/event-dispatcher: ^3.4
- symfony/http-foundation: ^3.4
- symfony/http-kernel: ^3.4
- symfony/security-core: ^3.4
- twig/twig: ^1.42
Requires (Dev)
- phpunit/phpunit: ^4.8
- symfony/phpunit-bridge: ^4.3
This package is auto-updated.
Last update: 2024-09-07 01:43:15 UTC
README
要求至少Drush 5.0以与Symfony控制台兼容。
此捆绑包尝试深度集成Symfony2与Drupal,以及Drupal与Symfony2。当然,这是在不修改Drupal核心的情况下完成的。
当此捆绑包被激活时,Symfony2控制台将自动加载Drupal库。因此,它使得从您的Symfony2命令中使用Drupal库成为可能。
安装
下载symfony2沙盒和Drupal代码
安装文件以获得以下结构
Symfony Sandbox Root
- app
- vendor
- src
- web (Drupal source code)
目录web
必须是文档根目录,并包含Drupal源代码。
更新index.php
文件
此文件与Drupal“共享”容器,因此可以在Drupal中使用Symfony2的服务。初始化过程始终由Symfony2处理。
<?php require_once __DIR__.'/../app/bootstrap.php.cache'; require_once __DIR__.'/../app/AppKernel.php'; //require_once __DIR__.'/../app/bootstrap_cache.php.cache'; //require_once __DIR__.'/../app/AppCache.php'; use Symfony\Component\HttpFoundation\Request; $kernel = new AppKernel('dev', true); // $kernel->loadClassCache(); $kernel->boot(); // make the Symfony container available from Drupal file global $container; $container = $kernel->getContainer(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response);
安装相关Drupal模块
可以从以下url下载该模块:https://github.com/ekino/ekino_drupal_symfony2
配置
编辑Symfony config.yml
文件并添加以下行
parameters:
session.flashbag.class: Ekino\Bundle\DrupalBundle\Port\DrupalFlashBag
session.attribute_bag.class: Ekino\Bundle\DrupalBundle\Port\DrupalAttributeBag
framework:
# ... configuration options
session:
# ... configuration options
storage_id: ekino.drupal.session.storage
ekino_drupal:
root: %kernel.root_dir%/../web
logger: ekino.drupal.logger.watchdog
strategy_id: ekino.drupal.delivery_strategy.symfony
# attach a security token to the following provider keys
provider_keys: [main, admin]
# not required
entity_repositories:
# 3 equivalent examples of configuration:
- { bundle: page }
- { type: node, bundle: page }
- { type: node, bundle: page, class: Ekino\Bundle\DrupalBundle\Entity\EntityRepository }
# you can also define an entity repository:
- { type: node, class: Application\Ekino\Bundle\DrupalBundle\Entity\Node\NodeRepository }
# switch to true if you want to prefix the name of Symfony tables
table_prefix:
enabled: false
prefix: symfony__
exclude: [users]
# optional
session:
refresh_cookie_lifetime: true # default value: false
# declare 2 required mapping definition used by Drupal
doctrine:
dbal:
driver: %database_driver%
dbname: %database_name%
user: %database_user%
host: %database_host%
port: %database_port%
password: %database_password%
charset: UTF8
mapping_types:
longblob: object
blob: object
# Tips: this allows Doctrine to consider only tables starting with
# "symfony__" during a migration generation.
# Think to add Doctrine migrations table here or configure it in
# the doctrine_migrations section (table_name)
schema_filter: ~^(symfony__|migration_versions)~
该捆绑包附带3种交付策略
- ekino.drupal.delivery_strategy.background: Drupal从不返回响应,Symfony返回
- ekino.drupal.delivery_strategy.drupal: Drupal始终返回响应,即使页面是404
- ekino.drupal.delivery_strategy.symfony: Drupal只有在页面不是404时才返回响应
(可选)部分 entity_repositories
允许您轻松与Drupal API交互以检索内容,并在Symfony代码中处理。配置提供默认值
- 默认实体类型是
node
- 默认存储库类是
Ekino\Bundle\DrupalBundle\Entity\EntityRepository
,请随意配置您的
更新查询
UPDATE users SET `emailCanonical` = `mail`, `usernameCanonical` = `name`, `roles` = 'b:0;';
用法
Symfony组件可以在Drupal中使用
<?php function drupal_foo_function() { $result = symfony_service('reusage_service')->foo(); // do some stuff with $result }
安全
您可以使用Drupal权限来保护Symfony路由,前缀为PERMISSION_DRUPAL_。例如
security: role_hierarchy: # ... firewalls: # ... access_control: - { path: ^/symfony/admin, role: PERMISSION_DRUPAL_ACCESS_ADMINISTRATION_PAGES }
PERMISSION_DRUPAL_ACCESS_ADMINISTRATION_PAGES翻译为“访问管理页面”并与user_access和全局Drupal用户一起使用。
如果您想使用“个人访问”权限,例如,使用role PERMISSION_DRUPAL_PERSONAL_ACCESS。
限制
- 无法使用Symfony原生类来管理会话,因为Drupal初始化了它自己的会话处理器,并且无法更改此设置。
- 请求必须通过index.php提供,因为这是.htaccess文件中的默认值,并且无法更改Drupal中的默认脚本。
预览
如果安装成功完成,欢迎页面看起来像
您可以在底部看到Symfony Web Debug Toolbar ;-)。