LoginSignup
0
0

More than 5 years have passed since last update.

eZ Pubilsh レガシーコードの利用方法

Last updated at Posted at 2016-12-25

レガシーモード

eZ Publish 5.x の管理画面はレガシーコードのままなので、レガシーモードで実行されています。

  • Symfonyカーネルを通して実行されるため、Symfony サービスはレガシースタックからアクセス可能。
  • デフォルトのルーターを無効にします(標準のSymfonyルートはこのモードでは動作しません)
  • UrlAliasRouterを無効にします。したがって、ViewControllerはバイパスされます。
  • レガシーモードは HttpCache 機構を使用しないのでパフォーマンスが低下します。

Symfonyのルートを有効にする

ez_publish_legacy:
    # Routes that are allowed when legacy_mode is true.
    # Must be routes identifiers (e.g. "my_route_name").
    # Can be a prefix, so that all routes beginning with given prefix will be taken into account.
    legacy_aware_routes: ["my_route_name", "my_route_prefix_"]

レガシーテンプレートのインクルード

古いテンプレート(.tpl)を新しいテンプレートにインクルードすることが可能です。

{# Twig template #}
{# Following code will include my/old_template.tpl, exposing $someVar variable in it #}
{% include "design:my/old_template.tpl" with {"someVar": "someValue"} %}

または、ezpublish_legacyフォルダに相対的なパスでレガシーテンプレートを含める場合は、次のようにします。

{# Following code will include ezpublish_legacyextension/my_legacy_extension/design/standard/templates/my_old_template.tpl, exposing $someVar variable in it #}
{% include "file:extension/my_legacy_extension/design/standard/templates/my_old_template.tpl" with {"someVar": "someValue"} %}

レガシーコードの実行

<?php
// Declare use statements for the classes you may need
use eZINI;

// Inside a controller extending eZ\Bundle\EzPublishCoreBundle\Controller
$settingName = 'MySetting';
$test = array( 'oneValue', 'anotherValue' );
$myLegacySetting = $this->getLegacyKernel()->runCallback(
    function () use ( $settingName, $test )
    {
        // Here you can reuse $settingName and $test variables inside the legacy context
        $ini = eZINI::instance( 'someconfig.ini' );
        return $ini->variable( 'SomeSection', $settingName );
    }
);

レガシーモジュール

フォールバックとサブリクエストのルーティング

{{ render( url( 'ez_legacy', {'module_uri': '/content/view/sitemap/2'} ) ) }}

レガシーでのeZ Publish 5とSymfonyの機能の使用

// From a legacy module or any PHP code running in legacy context.
$container = ezpKernel::instance()->getServiceContainer();

/** @var $repository \eZ\Publish\API\Repository\Repository */
$repository = $container->get( 'ezpublish.api.repository' );
/** @var $logger \Symfony\Component\HttpKernel\Log\LoggerInterface|\Psr\Log\LoggerInterface */
// PSR LoggerInterface is used in eZ Publish 5.1 / Symfony 2.2
$logger = $container->get( 'logger' );
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0