From c2a6cbdb114f5ecee8d639fadaac3931720f261f Mon Sep 17 00:00:00 2001 From: kseta Date: Sun, 16 Nov 2014 19:56:23 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[cookbook][profiler]=20=E7=BF=BB=E8=A8=B3?= =?UTF-8?q?=E6=BA=96=E5=82=99=E3=81=AE=E3=81=9F=E3=82=81=E5=8E=9F=E6=96=87?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cookbook/profiler/index.rst | 9 ++ cookbook/profiler/matchers.rst | 167 +++++++++++++++++++++++++++++++++ cookbook/profiler/storage.rst | 69 ++++++++++++++ 3 files changed, 245 insertions(+) create mode 100644 cookbook/profiler/index.rst create mode 100644 cookbook/profiler/matchers.rst create mode 100644 cookbook/profiler/storage.rst diff --git a/cookbook/profiler/index.rst b/cookbook/profiler/index.rst new file mode 100644 index 0000000..7ff3abe --- /dev/null +++ b/cookbook/profiler/index.rst @@ -0,0 +1,9 @@ +Profiler +======== + +.. toctree:: + :maxdepth: 2 + + data_collector + matchers + storage diff --git a/cookbook/profiler/matchers.rst b/cookbook/profiler/matchers.rst new file mode 100644 index 0000000..b23af0d --- /dev/null +++ b/cookbook/profiler/matchers.rst @@ -0,0 +1,167 @@ +.. index:: + single: Profiling; Matchers + +How to Use Matchers to Enable the Profiler Conditionally +======================================================== + +By default, the profiler is only activated in the development environment. But +it's imaginable that a developer may want to see the profiler even in +production. Another situation may be that you want to show the profiler only +when an admin has logged in. You can enable the profiler in these situations +by using matchers. + +Using the built-in Matcher +-------------------------- + +Symfony provides a +:class:`built-in matcher ` +which can match paths and IPs. For example, if you want to only show the +profiler when accessing the page with the ``168.0.0.1`` IP, then you can +use this configuration: + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + framework: + # ... + profiler: + matcher: + ip: 168.0.0.1 + + .. code-block:: xml + + + + + + + .. code-block:: php + + // app/config/config.php + $container->loadFromExtension('framework', array( + 'profiler' => array( + 'ip' => '168.0.0.1', + ), + )); + +You can also set a ``path`` option to define the path on which the profiler +should be enabled. For instance, setting it to ``^/admin/`` will enable the +profiler only for the ``/admin/`` URLs. + +Creating a custom Matcher +------------------------- + +You can also create a custom matcher. This is a service that checks whether +the profiler should be enabled or not. To create that service, create a class +which implements +:class:`Symfony\\Component\\HttpFoundation\\RequestMatcherInterface`. This +interface requires one method: +:method:`Symfony\\Component\\HttpFoundation\\RequestMatcherInterface::matches`. +This method returns false to disable the profiler and true to enable the +profiler. + +To enable the profiler when a ``ROLE_SUPER_ADMIN`` is logged in, you can use +something like:: + + // src/Acme/DemoBundle/Profiler/SuperAdminMatcher.php + namespace Acme\DemoBundle\Profiler; + + use Symfony\Component\Security\Core\SecurityContext; + use Symfony\Component\HttpFoundation\Request; + use Symfony\Component\HttpFoundation\RequestMatcherInterface; + + class SuperAdminMatcher implements RequestMatcherInterface + { + protected $securityContext; + + public function __construct(SecurityContext $securityContext) + { + $this->securityContext = $securityContext; + } + + public function matches(Request $request) + { + return $this->securityContext->isGranted('ROLE_SUPER_ADMIN'); + } + } + +Then, you need to configure the service: + +.. configuration-block:: + + .. code-block:: yaml + + parameters: + acme_demo.profiler.matcher.super_admin.class: Acme\DemoBundle\Profiler\SuperAdminMatcher + + services: + acme_demo.profiler.matcher.super_admin: + class: "%acme_demo.profiler.matcher.super_admin.class%" + arguments: ["@security.context"] + + .. code-block:: xml + + + Acme\DemoBundle\Profiler\SuperAdminMatcher + + + + + + + + .. code-block:: php + + use Symfony\Component\DependencyInjection\Definition; + use Symfony\Component\DependencyInjection\Reference; + + $container->setParameter( + 'acme_demo.profiler.matcher.super_admin.class', + 'Acme\DemoBundle\Profiler\SuperAdminMatcher' + ); + + $container->setDefinition('acme_demo.profiler.matcher.super_admin', new Definition( + '%acme_demo.profiler.matcher.super_admin.class%', + array(new Reference('security.context')) + ); + +Now the service is registered, the only thing left to do is configure the +profiler to use this service as the matcher: + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + framework: + # ... + profiler: + matcher: + service: acme_demo.profiler.matcher.super_admin + + .. code-block:: xml + + + + + + + + .. code-block:: php + + // app/config/config.php + $container->loadFromExtension('framework', array( + // ... + 'profiler' => array( + 'service' => 'acme_demo.profiler.matcher.super_admin', + ), + )); diff --git a/cookbook/profiler/storage.rst b/cookbook/profiler/storage.rst new file mode 100644 index 0000000..ca3c5b4 --- /dev/null +++ b/cookbook/profiler/storage.rst @@ -0,0 +1,69 @@ +.. index:: + single: Profiling; Storage Configuration + +Switching the Profiler Storage +============================== + +By default the profile stores the collected data in files in the cache directory. +You can control the storage being used through the ``dsn``, ``username``, +``password`` and ``lifetime`` options. For example, the following configuration +uses MySQL as the storage for the profiler with a lifetime of one hour: + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + framework: + profiler: + dsn: "mysql:host=localhost;dbname=%database_name%" + username: "%database_user%" + password: "%database_password%" + lifetime: 3600 + + .. code-block:: xml + + + + + + + + + + .. code-block:: php + + // app/config/config.php + + // ... + $container->loadFromExtension('framework', array( + 'profiler' => array( + 'dsn' => 'mysql:host=localhost;dbname=%database_name%', + 'username' => '%database_user', + 'password' => '%database_password%', + 'lifetime' => 3600, + ), + )); + +The :doc:`HttpKernel component ` currently +supports the following profiler storage implementations: + +* :class:`Symfony\\Component\\HttpKernel\\Profiler\\FileProfilerStorage` +* :class:`Symfony\\Component\\HttpKernel\\Profiler\\MemcachedProfilerStorage` +* :class:`Symfony\\Component\\HttpKernel\\Profiler\\MemcacheProfilerStorage` +* :class:`Symfony\\Component\\HttpKernel\\Profiler\\MongoDbProfilerStorage` +* :class:`Symfony\\Component\\HttpKernel\\Profiler\\MysqlProfilerStorage` +* :class:`Symfony\\Component\\HttpKernel\\Profiler\\RedisProfilerStorage` +* :class:`Symfony\\Component\\HttpKernel\\Profiler\\SqliteProfilerStorage` From 5b9d8541a37037f9df7a3cf23d029cb9229d3a66 Mon Sep 17 00:00:00 2001 From: kseta Date: Mon, 1 Dec 2014 21:08:58 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[cookbook][profiler]=20matchers.rst=20?= =?UTF-8?q?=E3=82=92=E7=BF=BB=E8=A8=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cookbook/profiler/matchers.rst | 56 ++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/cookbook/profiler/matchers.rst b/cookbook/profiler/matchers.rst index b23af0d..2f02854 100644 --- a/cookbook/profiler/matchers.rst +++ b/cookbook/profiler/matchers.rst @@ -1,23 +1,27 @@ +.. note:: + + * 対象バージョン:2.6 + * 翻訳更新日:2014/12/01 + .. index:: single: Profiling; Matchers -How to Use Matchers to Enable the Profiler Conditionally +プロファイラーを条件に応じて有効化する Matchers の使い方 ======================================================== -By default, the profiler is only activated in the development environment. But -it's imaginable that a developer may want to see the profiler even in -production. Another situation may be that you want to show the profiler only -when an admin has logged in. You can enable the profiler in these situations -by using matchers. +デフォルトでは Profiler は開発環境でしか有効になっていません。 +しかし、開発者が本番環境でも Profiler を見たいということは想像できます。 +管理者としてログインした場合のみ Profiler を表示させたいという状況もあるでしょう。 +Matchers を使うことで状況に応じて Profiler を有効にすることが可能です。 -Using the built-in Matcher +built-in Matcher を使う -------------------------- -Symfony provides a +Symfony は Path と IPアドレスにマッチすることができる :class:`built-in matcher ` -which can match paths and IPs. For example, if you want to only show the -profiler when accessing the page with the ``168.0.0.1`` IP, then you can -use this configuration: +を提供しています。 +例えば、もし ``168.0.0.1`` という IP アドレスでアクセスした場合のみ Profiler を表示させたい場合には +このような設定を使います。 .. configuration-block:: @@ -48,24 +52,22 @@ use this configuration: ), )); -You can also set a ``path`` option to define the path on which the profiler -should be enabled. For instance, setting it to ``^/admin/`` will enable the -profiler only for the ``/admin/`` URLs. +Profiler が有効であるべきパスを ``path`` オプションに定義することも可能です。 +例えば、 ``^/admin/`` に設定することで ``/admin/`` という URL のみ Profiler を有効にできます。 -Creating a custom Matcher +カスタマイズした Matcher を使う ------------------------- -You can also create a custom matcher. This is a service that checks whether -the profiler should be enabled or not. To create that service, create a class -which implements -:class:`Symfony\\Component\\HttpFoundation\\RequestMatcherInterface`. This -interface requires one method: +カスタマイズした Matcher を作ることも可能です。 +これは Profiler を有効にするべきか否かをチェックするサービスです。 +:class:`Symfony\\Component\\HttpFoundation\\RequestMatcherInterface` +を実装したクラスでサービスを作ります。 +このインターフェースには :method:`Symfony\\Component\\HttpFoundation\\RequestMatcherInterface::matches`. -This method returns false to disable the profiler and true to enable the -profiler. +というメソッドの実装が必要です。 +このメソッドは、 Profiler が無効の場合は False を、有効な場合は True を返します。 -To enable the profiler when a ``ROLE_SUPER_ADMIN`` is logged in, you can use -something like:: +``ROLE_SUPER_ADMIN`` がログインした場合に Profiler を有効にするときはこのように実装します:: // src/Acme/DemoBundle/Profiler/SuperAdminMatcher.php namespace Acme\DemoBundle\Profiler; @@ -89,7 +91,7 @@ something like:: } } -Then, you need to configure the service: +そしてサービスを設定します: .. configuration-block:: @@ -132,8 +134,8 @@ Then, you need to configure the service: array(new Reference('security.context')) ); -Now the service is registered, the only thing left to do is configure the -profiler to use this service as the matcher: +これでサービスが登録されました。最後の仕上げにこのサービスを Matcher として利用し +Profiler を設定しましょう: .. configuration-block:: From a06eb4e669cde392995434c695898dc3e855df0d Mon Sep 17 00:00:00 2001 From: kseta Date: Mon, 1 Dec 2014 21:17:09 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[cookbook][profiler]=20storage.rst=20?= =?UTF-8?q?=E3=82=92=E7=BF=BB=E8=A8=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cookbook/profiler/storage.rst | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cookbook/profiler/storage.rst b/cookbook/profiler/storage.rst index ca3c5b4..c0c1e51 100644 --- a/cookbook/profiler/storage.rst +++ b/cookbook/profiler/storage.rst @@ -1,13 +1,17 @@ +.. note:: + + * 対象バージョン:2.6 + * 翻訳更新日:2014/12/01 + .. index:: single: Profiling; Storage Configuration -Switching the Profiler Storage +Profiler のストレージを変更する ============================== -By default the profile stores the collected data in files in the cache directory. -You can control the storage being used through the ``dsn``, ``username``, -``password`` and ``lifetime`` options. For example, the following configuration -uses MySQL as the storage for the profiler with a lifetime of one hour: +デフォルトでは Profiler はキャッシュディレクトリ内のファイルに集積されたデータ蓄積します。 +このストレージは ``dsn``, ``username``, ``password``, ``lifetime`` を介して調整が可能です。 +例えば、lifetime が1時間として MySQL を Profiler のストレージとして仕様する設定は以下の通りです: .. configuration-block:: @@ -57,8 +61,8 @@ uses MySQL as the storage for the profiler with a lifetime of one hour: ), )); -The :doc:`HttpKernel component ` currently -supports the following profiler storage implementations: +:doc:`HttpKernel component ` +は現在、以下の Profiler 用のストレージをサポートしています。 * :class:`Symfony\\Component\\HttpKernel\\Profiler\\FileProfilerStorage` * :class:`Symfony\\Component\\HttpKernel\\Profiler\\MemcachedProfilerStorage`