Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #329 from kseta/translate-cookbook-profiler
[cookbook] Profiler の翻訳
- Loading branch information
Showing
3 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Profiler | ||
======== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
data_collector | ||
matchers | ||
storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
.. note:: | ||
|
||
* 対象バージョン:2.6 | ||
* 翻訳更新日:2014/12/01 | ||
|
||
.. index:: | ||
single: Profiling; Matchers | ||
|
||
プロファイラーを条件に応じて有効化する Matchers の使い方 | ||
======================================================== | ||
|
||
デフォルトでは Profiler は開発環境でしか有効になっていません。 | ||
しかし、開発者が本番環境でも Profiler を見たいということは想像できます。 | ||
管理者としてログインした場合のみ Profiler を表示させたいという状況もあるでしょう。 | ||
Matchers を使うことで状況に応じて Profiler を有効にすることが可能です。 | ||
|
||
built-in Matcher を使う | ||
-------------------------- | ||
|
||
Symfony は Path と IPアドレスにマッチすることができる | ||
:class:`built-in matcher <Symfony\\Component\\HttpFoundation\\RequestMatcher>` | ||
を提供しています。 | ||
例えば、もし ``168.0.0.1`` という IP アドレスでアクセスした場合のみ Profiler を表示させたい場合には | ||
このような設定を使います。 | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
# app/config/config.yml | ||
framework: | ||
# ... | ||
profiler: | ||
matcher: | ||
ip: 168.0.0.1 | ||
.. code-block:: xml | ||
<!-- app/config/config.xml --> | ||
<framework:config> | ||
<framework:profiler | ||
ip="168.0.0.1" | ||
/> | ||
</framework:config> | ||
.. code-block:: php | ||
// app/config/config.php | ||
$container->loadFromExtension('framework', array( | ||
'profiler' => array( | ||
'ip' => '168.0.0.1', | ||
), | ||
)); | ||
Profiler が有効であるべきパスを ``path`` オプションに定義することも可能です。 | ||
例えば、 ``^/admin/`` に設定することで ``/admin/`` という URL のみ Profiler を有効にできます。 | ||
|
||
カスタマイズした Matcher を使う | ||
------------------------- | ||
|
||
カスタマイズした Matcher を作ることも可能です。 | ||
これは Profiler を有効にするべきか否かをチェックするサービスです。 | ||
:class:`Symfony\\Component\\HttpFoundation\\RequestMatcherInterface` | ||
を実装したクラスでサービスを作ります。 | ||
このインターフェースには | ||
:method:`Symfony\\Component\\HttpFoundation\\RequestMatcherInterface::matches`. | ||
というメソッドの実装が必要です。 | ||
このメソッドは、 Profiler が無効の場合は False を、有効な場合は True を返します。 | ||
|
||
``ROLE_SUPER_ADMIN`` がログインした場合に Profiler を有効にするときはこのように実装します:: | ||
|
||
// 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'); | ||
} | ||
} | ||
|
||
そしてサービスを設定します: | ||
|
||
.. 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 | ||
<parameters> | ||
<parameter | ||
key="acme_demo.profiler.matcher.super_admin.class" | ||
>Acme\DemoBundle\Profiler\SuperAdminMatcher</parameter> | ||
</parameters> | ||
<services> | ||
<service id="acme_demo.profiler.matcher.super_admin" | ||
class="%acme_demo.profiler.matcher.super_admin.class%"> | ||
<argument type="service" id="security.context" /> | ||
</services> | ||
.. 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')) | ||
); | ||
これでサービスが登録されました。最後の仕上げにこのサービスを Matcher として利用し | ||
Profiler を設定しましょう: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
# app/config/config.yml | ||
framework: | ||
# ... | ||
profiler: | ||
matcher: | ||
service: acme_demo.profiler.matcher.super_admin | ||
.. code-block:: xml | ||
<!-- app/config/config.xml --> | ||
<framework:config> | ||
<!-- ... --> | ||
<framework:profiler | ||
service="acme_demo.profiler.matcher.super_admin" | ||
/> | ||
</framework:config> | ||
.. code-block:: php | ||
// app/config/config.php | ||
$container->loadFromExtension('framework', array( | ||
// ... | ||
'profiler' => array( | ||
'service' => 'acme_demo.profiler.matcher.super_admin', | ||
), | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
.. note:: | ||
|
||
* 対象バージョン:2.6 | ||
* 翻訳更新日:2014/12/01 | ||
|
||
.. index:: | ||
single: Profiling; Storage Configuration | ||
|
||
Profiler のストレージを変更する | ||
============================== | ||
|
||
デフォルトでは Profiler はキャッシュディレクトリ内のファイルに集積されたデータ蓄積します。 | ||
このストレージは ``dsn``, ``username``, ``password``, ``lifetime`` を介して調整が可能です。 | ||
例えば、lifetime が1時間として MySQL を Profiler のストレージとして仕様する設定は以下の通りです: | ||
|
||
.. 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 | ||
<!-- app/config/config.xml --> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:framework="http://symfony.com/schema/dic/symfony" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
http://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/symfony | ||
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" | ||
> | ||
<framework:config> | ||
<framework:profiler | ||
dsn="mysql:host=localhost;dbname=%database_name%" | ||
username="%database_user%" | ||
password="%database_password%" | ||
lifetime="3600" | ||
/> | ||
</framework:config> | ||
</container> | ||
.. 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, | ||
), | ||
)); | ||
:doc:`HttpKernel component </components/http_kernel/introduction>` | ||
は現在、以下の Profiler 用のストレージをサポートしています。 | ||
|
||
* :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` |