From 93e2e696218c79837a8cffc5fea589756a7ede5f Mon Sep 17 00:00:00 2001 From: Nobuo Kihara Date: Mon, 27 Oct 2014 23:22:45 +0900 Subject: [PATCH 1/5] docs/guide-ja/structure-applications.md - catchAll Conflicts: docs/guide-ja/structure-applications.md --- docs/guide-ja/structure-applications.md | 601 ++++++++++++++++++++++++ 1 file changed, 601 insertions(+) create mode 100644 docs/guide-ja/structure-applications.md diff --git a/docs/guide-ja/structure-applications.md b/docs/guide-ja/structure-applications.md new file mode 100644 index 0000000000..de51e7232e --- /dev/null +++ b/docs/guide-ja/structure-applications.md @@ -0,0 +1,601 @@ +アプリケーション +================ + +アプリケーションは Yii アプリケーションシステム全体の構造とライフサイクルを統制するオブジェクトです。 +全ての Yii アプリケーションシステムは、それぞれ、[エントリスクリプト](structure-entry-scripts.md) において作成され、`\Yii::$app` という式でグローバルにアクセス可能な、単一のアプリケーションオブジェクトを持ちます。 + +> Info|情報: ガイドの中で「アプリケーション」という言葉は、文脈に応じて、 +アプリケーションオブジェクトを意味したり、アプリケーションシステムを意味したりします。 + +二種類のアプリケーションがあります: すなわち、[[yii\web\Application|ウェブアプリケーション]] と [[yii\console\Application|コンソールアプリケーション]] です。 +名前が示すように、前者は主にウェブのリクエストを処理し、後者はコンソールコマンドのリクエストを処理します。 + + +## アプリケーションの設定 + +[エントリスクリプト](structure-entry-scripts.md) は、アプリケーションを作成するときに、 +下記のように、[設定](concept-configurations.md) を読み込んで、それをアプリケーションに適用します: + +```php +require(__DIR__ . '/../vendor/autoload.php'); +require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); + +// アプリケーションの設定を読み込む +$config = require(__DIR__ . '/../config/web.php'); + +// アプリケーションのインスタンスを作成し、設定を適用する +(new yii\web\Application($config))->run(); +``` + +通常の [設定](concept-configurations.md) と同じように、アプリケーションの設定は、アプリケーションオブジェクトのプロパティをどのように初期化するかを規定するものです。 +アプリケーションの設定は、たいていは非常に複雑なものですから、通常は、上記の例の `web.php` ファイルのように、[設定ファイル](concept-configurations.md#configuration-files) に保管されます。 + + +## アプリケーションのプロパティ + +アプリケーションの設定で構成すべき重要なアプリケーションのプロパティは数多くあります。 +それらのプロパティの典型的なものは、アプリケーションが走る環境を記述するものです。 +例えば、アプリケーションは、どのようにして [コントローラ](structure-controllers.md) をロードするか、また、どこにテンポラリファイルを保存するかなどを知らなければなりません。 +以下において、それらのプロパティを要約します。 + + +### 必須のプロパティ + +どのアプリケーションでも、最低二つのプロパティは構成しなければなりません: +すなわち、[[yii\base\Application::id|id]] と [[yii\base\Application::basePath|basePath]] です。 + + +#### [[yii\base\Application::id|id]] + +[[yii\base\Application::id|id]] プロパティは、アプリケーションを他のアプリケーションから区別するユニークな ID を規定します。 +このプロパティは主としてプログラム的に使われます。 +必須ではありませんが、最良の相互運用性を確保するために、アプリケーション ID を規定するときに英数字だけを使うことが推奨されます。 + + +#### [[yii\base\Application::basePath|basePath]] + +[[yii\base\Application::basePath|basePath]] プロパティは、アプリケーションのルートディレクトリを規定します。 +これは、アプリケーションシステムの全ての保護されたソースコードを収容するディレクトリです。 +通常、このディレクトリの下に、MVC パターンに対応するソースコードを収容した `models`、`views`、`controllers` などのサブディレクトリがあります。 + +[[yii\base\Application::basePath|basePath]] プロパティの構成には、ディレクトリパスを使っても、[パスエイリアス](concept-aliases.md) を使っても構いません。 +どちらの形式においても、対応するディレクトリが存在しなければなりません。 +さもなくば、例外が投げられます。 +パスは `realpath()` 関数を呼び出して正規化されます。 + +[[yii\base\Application::basePath|basePath]] プロパティは、しばしば、他の重要なパス (例えば、runtime のパス) を派生させるために使われます。 +このため、`basePath` を示す `@app` というパスエイリアスが、あらかじめ定義されています。 +その結果、派生的なパスはこのエイリアスを使って形成することが出来ます +(例えば、runtime ディレクトリを示す `@app/runtime` など)。 + + +### 重要なプロパティ + +この項で説明するプロパティは、アプリケーションが異なるごとに異なってくるものであるため、たいてい、構成する必要が生じます。 + + +#### [[yii\base\Application::aliases|aliases]] + +このプロパティを使って、配列形式で一連の [エイリアス](concept-aliases.md) を定義することが出来ます。 +配列のキーがエイリアスの名前であり、配列の値が対応するパスの定義です。 +例えば、 + +```php +[ + 'aliases' => [ + '@name1' => 'path/to/path1', + '@name2' => 'path/to/path2', + ], +] +``` + +このプロパティが提供されているのは、[[Yii::setAlias()]] メソッドを呼び出す代りに、アプリケーション設定を使ってエイリアスを定義することが出来るようにするためです。 + + +#### [[yii\base\Application::bootstrap|bootstrap]] + +これは非常に有用なプロパティです。 +これによって、アプリケーションの [[yii\base\Application::bootstrap()|ブートストラップの過程]] において走らせるべきコンポーネントを配列として規定することが出来ます。 +例えば、ある [モジュール](structure-modules.md) に [URL 規則](runtime-url-handling.md) をカスタマイズさせたいときに、モジュールの ID をこのプロパティの要素として挙げることが出来ます。 + +このプロパティに挙げるコンポーネントは、それぞれ、以下の形式のいずれかによって規定することが出来ます: + +- [components](#components) によって規定されるアプリケーションコンポーネントの ID。 +- [modules](#modules) によって規定されるモジュールの ID。 +- クラス名。 +- 設定配列。 +- コンポーネントを作成して返す無名関数。 + +例えば、 + +```php +[ + 'bootstrap' => [ + // アプリケーションコンポーネント ID、または、モジュール ID + 'demo', + + // クラス名 + 'app\components\Profiler', + + // 設定配列 + [ + 'class' => 'app\components\Profiler', + 'level' => 3, + ], + + // 無名関数 + function () { + return new app\components\Profiler(); + } + ], +] +``` + +> Info|情報: モジュール ID と同じ ID のアプリケーションコンポーネントがある場合は、ブートストラップの過程ではアプリケーションコンポーネントが使われます。 + 代りにモジュールを使いたいときは、次のように、無名関数を使って指定することが出来ます: +>```php +[ + function () { + return Yii::$app->getModule('user'); + }, +] +``` + +ブートストラップの過程で、各コンポーネントのインスタンスが作成されます。 +そして、コンポーネントクラスが [[yii\base\BootstrapInterface]] を実装している場合は、その [[yii\base\BootstrapInterface::bootstrap()|bootstrap()]] メソッドも呼び出されます。 + +もう一つの実用的な例が [ベーシックアプリケーションテンプレート](start-installation.md) のアプリケーション設定の中にあります。 +そこでは、アプリケーションが開発環境で走るときには `debug` モジュールと `gii` モジュールがブートストラップコンポーネントとして構成されています。 + +```php +if (YII_ENV_DEV) { + // 'dev' 環境のための設定の調整 + $config['bootstrap'][] = 'debug'; + $config['modules']['debug'] = 'yii\debug\Module'; + + $config['bootstrap'][] = 'gii'; + $config['modules']['gii'] = 'yii\gii\Module'; +} +``` + +> Note|注意: あまり多くのコンポーネントを `bootstrap` に置くと、アプリケーションのパフォーマンスを劣化させます。 + なぜなら、リクエストごとに同じ一連のコンポーネントを走らせなければならないからです。 + ですから、ブートストラップコンポーネントは賢く使ってください。 + + +#### [[yii\web\Application::catchAll|catchAll]] + +このプロパティは [[yii\web\Application|ウェブアプリケーション]] においてのみサポートされます。 +これは、全てのユーザリクエストを処理すべき [コントローラアクション](structure-controllers.md) を規定します。 +これは主としてアプリケーションがメンテナンスモードにあって、入ってくる全てのリクエストを単一のアクションで処理する必要があるときに使われます。 + +構成は配列の形を取り、最初の要素はアクションのルートを指定します。 +そして、配列の残りの要素 (キー・値のペア) は、アクションに渡されるパラメータを指定します。 +例えば、 + +```php +[ + 'catchAll' => [ + 'offline/notice', + 'param1' => 'value1', + 'param2' => 'value2', + ], +] +``` + + +#### [[yii\base\Application::components|components]] + +This is the single most important property. It allows you to register a list of named components +called [application components](structure-application-components.md) that you can use in other places. For example, + +```php +[ + 'components' => [ + 'cache' => [ + 'class' => 'yii\caching\FileCache', + ], + 'user' => [ + 'identityClass' => 'app\models\User', + 'enableAutoLogin' => true, + ], + ], +] +``` + +Each application component is specified as a key-value pair in the array. The key represents the component ID, +while the value represents the component class name or [configuration](concept-configurations.md). + +You can register any component with an application, and the component can later be accessed globally +using the expression `\Yii::$app->ComponentID`. + +Please read the [Application Components](structure-application-components.md) section for details. + + +#### [[yii\base\Application::controllerMap|controllerMap]] + +This property allows you to map a controller ID to an arbitrary controller class. By default, Yii maps +controller IDs to controller classes based on a [convention](#controllerNamespace) (e.g. the ID `post` would be mapped +to `app\controllers\PostController`). By configuring this property, you can break the convention for +specific controllers. In the following example, `account` will be mapped to +`app\controllers\UserController`, while `article` will be mapped to `app\controllers\PostController`. + +```php +[ + 'controllerMap' => [ + [ + 'account' => 'app\controllers\UserController', + 'article' => [ + 'class' => 'app\controllers\PostController', + 'enableCsrfValidation' => false, + ], + ], + ], +] +``` + +The array keys of this property represent the controller IDs, while the array values represent the corresponding +controller class names or [configurations](concept-configurations.md). + + +#### [[yii\base\Application::controllerNamespace|controllerNamespace]] + +This property specifies the default namespace under which controller classes should be located. It defaults to +`app\controllers`. If a controller ID is `post`, by convention the corresponding controller class name (without +namespace) would be `PostController`, and the fully qualified class name would be `app\controllers\PostController`. + +Controller classes may also be located under sub-directories of the directory corresponding to this namespace. +For example, given a controller ID `admin/post`, the corresponding fully qualified controller class would +be `app\controllers\admin\PostController`. + +It is important that the fully qualified controller classes should be [autoloadable](concept-autoloading.md) +and the actual namespace of your controller classes match the value of this property. Otherwise, +you will receive "Page Not Found" error when accessing the application. + +In case you want to break the convention as described above, you may configure the [controllerMap](#controllerMap) +property. + + +#### [[yii\base\Application::language|language]] + +This property specifies the language in which the application should display content to end users. +The default value of this property is `en`, meaning English. You should configure this property +if your application needs to support multiple languages. + +The value of this property determines various [internationalization](tutorial-i18n.md) aspects, +including message translation, date formatting, number formatting, etc. For example, the [[yii\jui\DatePicker]] widget +will use this property value by default to determine in which language the calendar should be displayed and how +should the date be formatted. + +It is recommended that you specify a language in terms of an [IETF language tag](http://en.wikipedia.org/wiki/IETF_language_tag). +For example, `en` stands for English, while `en-US` stands for English (United States). + +More details about this property can be found in the [Internationalization](tutorial-i18n.md) section. + + +#### [[yii\base\Application::modules|modules]] + +This property specifies the [modules](structure-modules.md) that the application contains. + +The property takes an array of module classes or [configurations](concept-configurations.md) with the array keys +being the module IDs. For example, + +```php +[ + 'modules' => [ + // a "booking" module specified with the module class + 'booking' => 'app\modules\booking\BookingModule', + + // a "comment" module specified with a configuration array + 'comment' => [ + 'class' => 'app\modules\comment\CommentModule', + 'db' => 'db', + ], + ], +] +``` + +Please refer to the [Modules](structure-modules.md) section for more details. + + +#### [[yii\base\Application::name|name]] + +This property specifies the application name that may be displayed to end users. Unlike the +[[yii\base\Application::id|id]] property which should take a unique value, the value of this property is mainly for +display purpose and does not need to be unique. + +You do not always need to configure this property if none of your code is using it. + + +#### [[yii\base\Application::params|params]] + +This property specifies an array of globally accessible application parameters. Instead of using hardcoded +numbers and strings everywhere in your code, it is a good practice to define them as application parameters +in a single place and use the parameters in places where needed. For example, you may define the thumbnail +image size as a parameter like the following: + +```php +[ + 'params' => [ + 'thumbnail.size' => [128, 128], + ], +] +``` + +Then in your code where you need to use the size value, you can simply use the code like the following: + +```php +$size = \Yii::$app->params['thumbnail.size']; +$width = \Yii::$app->params['thumbnail.size'][0]; +``` + +Later if you decide to change the thumbnail size, you only need to modify it in the application configuration +without touching any dependent code. + + +#### [[yii\base\Application::sourceLanguage|sourceLanguage]] + +This property specifies the language that the application code is written in. The default value is `'en-US'`, +meaning English (United States). You should configure this property if the text content in your code is not in English. + +Like the [language](#language) property, you should configure this property in terms of +an [IETF language tag](http://en.wikipedia.org/wiki/IETF_language_tag). For example, `en` stands for English, +while `en-US` stands for English (United States). + +More details about this property can be found in the [Internationalization](tutorial-i18n.md) section. + + +#### [[yii\base\Application::timeZone|timeZone]] + +This property is provided as an alternative way of setting the default time zone of PHP runtime. +By configuring this property, you are essentially calling the PHP function +[date_default_timezone_set()](http://php.net/manual/en/function.date-default-timezone-set.php). For example, + +```php +[ + 'timeZone' => 'America/Los_Angeles', +] +``` + + +#### [[yii\base\Application::version|version]] + +This property specifies the version of the application. It defaults to `'1.0'`. You do not always need to configure +this property if none of your code is using it. + + +### Useful Properties + +The properties described in this subsection are not commonly configured because their default values +stipulate common conventions. However, you may still configure them in case you want to break the conventions. + + +#### [[yii\base\Application::charset|charset]] + +This property specifies the charset that the application uses. The default value is `'UTF-8'` which should +be kept as is for most applications unless you are working with some legacy systems that use a lot of non-unicode data. + + +#### [[yii\base\Application::defaultRoute|defaultRoute]] + +This property specifies the [route](runtime-routing.md) that an application should use when a request +does not specify one. The route may consist of child module ID, controller ID, and/or action ID. +For example, `help`, `post/create`, `admin/post/create`. If action ID is not given, it will take the default +value as specified in [[yii\base\Controller::defaultAction]]. + +For [[yii\web\Application|Web applications]], the default value of this property is `'site'`, which means +the `SiteController` controller and its default action should be used. As a result, if you access +the application without specifying a route, it will show the result of `app\controllers\SiteController::actionIndex()`. + +For [[yii\console\Application|console applications]], the default value is `'help'`, which means the core command +[[yii\console\controllers\HelpController::actionIndex()]] should be used. As a result, if you run the command `yii` +without providing any arguments, it will display the help information. + + +#### [[yii\base\Application::extensions|extensions]] + +This property specifies the list of [extensions](structure-extensions.md) that are installed and used by the application. +By default, it will take the array returned by the file `@vendor/yiisoft/extensions.php`. The `extensions.php` file +is generated and maintained automatically when you use [Composer](http://getcomposer.org) to install extensions. +So in most cases, you do not need to configure this property. + +In the special case when you want to maintain extensions manually, you may configure this property like the following: + +```php +[ + 'extensions' => [ + [ + 'name' => 'extension name', + 'version' => 'version number', + 'bootstrap' => 'BootstrapClassName', // optional, may also be a configuration array + 'alias' => [ // optional + '@alias1' => 'to/path1', + '@alias2' => 'to/path2', + ], + ], + + // ... more extensions like the above ... + + ], +] +``` + +As you can see, the property takes an array of extension specifications. Each extension is specified with an array +consisting of `name` and `version` elements. If an extension needs to run during the [bootstrap](runtime-bootstrapping.md) +process, a `bootstrap` element may be specified with a bootstrapping class name or a [configuration](concept-configurations.md) +array. An extension may also define a few [aliases](concept-aliases.md). + + +#### [[yii\base\Application::layout|layout]] + +This property specifies the name of the default layout that should be used when rendering a [view](structure-views.md). +The default value is `'main'`, meaning the layout file `main.php` under the [layout path](#layoutPath) should be used. +If both of the [layout path](#layoutPath) and the [view path](#viewPath) are taking the default values, +the default layout file can be represented as the path alias `@app/views/layouts/main.php`. + +You may configure this property to be `false` if you want to disable layout by default, although this is very rare. + + +#### [[yii\base\Application::layoutPath|layoutPath]] + +This property specifies the path where layout files should be looked for. The default value is +the `layouts` sub-directory under the [view path](#viewPath). If the [view path](#viewPath) is taking +its default value, the default layout path can be represented as the path alias `@app/views/layouts`. + +You may configure it as a directory or a path [alias](concept-aliases.md). + + +#### [[yii\base\Application::runtimePath|runtimePath]] + +This property specifies the path where temporary files, such as log files, cache files, can be generated. +The default value is the directory represented by the alias `@app/runtime`. + +You may configure it as a directory or a path [alias](concept-aliases.md). Note that the runtime path must +be writable by the process running the application. And the path should be protected from being accessed +by end users because the temporary files under it may contain sensitive information. + +To simplify accessing to this path, Yii has predefined a path alias named `@runtime` for it. + + +#### [[yii\base\Application::viewPath|viewPath]] + +This property specifies the root directory where view files are located. The default value is the directory +represented by the alias `@app/views`. You may configure it as a directory or a path [alias](concept-aliases.md). + + +#### [[yii\base\Application::vendorPath|vendorPath]] + +This property specifies the vendor directory managed by [Composer](http://getcomposer.org). It contains +all third party libraries used by your application, including the Yii framework. The default value is +the directory represented by the alias `@app/vendor`. + +You may configure this property as a directory or a path [alias](concept-aliases.md). When you modify +this property, make sure you also adjust the Composer configuration accordingly. + +To simplify accessing to this path, Yii has predefined a path alias named `@vendor` for it. + + +#### [[yii\console\Application::enableCoreCommands|enableCoreCommands]] + +This property is supported by [[yii\console\Application|console applications]] only. It specifies +whether the core commands included in the Yii release should be enabled. The default value is `true`. + + +## Application Events + +An application triggers several events during the lifecycle of handling an request. You may attach event +handlers to these events in application configurations like the following, + +```php +[ + 'on beforeRequest' => function ($event) { + // ... + }, +] +``` + +The use of the `on eventName` syntax is described in the [Configurations](concept-configurations.md#configuration-format) +section. + +Alternatively, you may attach event handlers during the [bootstrapping process](runtime-bootstrapping.md) process +after the application instance is created. For example, + +```php +\Yii::$app->on(\yii\base\Application::EVENT_BEFORE_REQUEST, function ($event) { + // ... +}); +``` + +### [[yii\base\Application::EVENT_BEFORE_REQUEST|EVENT_BEFORE_REQUEST]] + +This event is triggered *before* an application handles a request. The actual event name is `beforeRequest`. + +When this event is triggered, the application instance has been configured and initialized. So it is a good place +to insert your custom code via the event mechanism to intercept the request handling process. For example, +in the event handler, you may dynamically set the [[yii\base\Application::language]] property based on some parameters. + + +### [[yii\base\Application::EVENT_AFTER_REQUEST|EVENT_AFTER_REQUEST]] + +This event is triggered *after* an application finishes handling a request but *before* sending the response. +The actual event name is `afterRequest`. + +When this event is triggered, the request handling is completed and you may take this chance to do some postprocessing +of the request or customize the response. + +Note that the [[yii\web\Response|response]] component also triggers some events while it is sending out +response content to end users. Those events are triggered *after* this event. + + +### [[yii\base\Application::EVENT_BEFORE_ACTION|EVENT_BEFORE_ACTION]] + +This event is triggered *before* running every [controller action](structure-controllers.md). +The actual event name is `beforeAction`. + +The event parameter is an instance of [[yii\base\ActionEvent]]. An event handler may set +the [[yii\base\ActionEvent::isValid]] property to be `false` to stop running the action. +For example, + +```php +[ + 'on beforeAction' => function ($event) { + if (some condition) { + $event->isValid = false; + } else { + } + }, +] +``` + +Note that the same `beforeAction` event is also triggered by [modules](structure-modules.md) +and [controllers](structure-controllers.md). Application objects are the first ones +triggering this event, followed by modules (if any), and finally controllers. If an event handler +sets [[yii\base\ActionEvent::isValid]] to be `false`, all the following events will NOT be triggered. + + +### [[yii\base\Application::EVENT_AFTER_ACTION|EVENT_AFTER_ACTION]] + +This event is triggered *after* running every [controller action](structure-controllers.md). +The actual event name is `afterAction`. + +The event parameter is an instance of [[yii\base\ActionEvent]]. Through +the [[yii\base\ActionEvent::result]] property, an event handler may access or modify the action result. +For example, + +```php +[ + 'on afterAction' => function ($event) { + if (some condition) { + // modify $event->result + } else { + } + }, +] +``` + +Note that the same `afterAction` event is also triggered by [modules](structure-modules.md) +and [controllers](structure-controllers.md). These objects trigger this event in the reverse order +as for that of `beforeAction`. That is, controllers are the first objects triggering this event, +followed by modules (if any), and finally applications. + + +## Application Lifecycle + +When an [entry script](structure-entry-scripts.md) is being executed to handle a request, +an application will undergo the following lifecycle: + +1. The entry script loads the application configuration as an array. +2. The entry script creates a new instance of the application: + * [[yii\base\Application::preInit()|preInit()]] is called, which configures some high priority + application properties, such as [[yii\base\Application::basePath|basePath]]. + * Register the [[yii\base\Application::errorHandler|error handler]]. + * Configure application properties. + * [[yii\base\Application::init()|init()]] is called which further calls + [[yii\base\Application::bootstrap()|bootstrap()]] to run bootstrapping components. +3. The entry script calls [[yii\base\Application::run()]] to run the application: + * Trigger the [[yii\base\Application::EVENT_BEFORE_REQUEST|EVENT_BEFORE_REQUEST]] event. + * Handle the request: resolve the request into a [route](runtime-routing.md) and the associated parameters; + create the module, controller and action objects as specified by the route; and run the action. + * Trigger the [[yii\base\Application::EVENT_AFTER_REQUEST|EVENT_AFTER_REQUEST]] event. + * Send response to the end user. +4. The entry script receives the exit status from the application and completes the request processing. From 753e4185248cadfd305a152a05dcc2e76289673b Mon Sep 17 00:00:00 2001 From: Nobuo Kihara Date: Tue, 28 Oct 2014 20:46:06 +0900 Subject: [PATCH 2/5] better word for "configuration" --- docs/guide-ja/README.md | 8 +++--- docs/guide-ja/intro-upgrade-from-v1.md | 35 +++++++++++++------------ docs/guide-ja/start-databases.md | 16 +++++------ docs/guide-ja/start-gii.md | 10 +++---- docs/guide-ja/start-installation.md | 10 +++---- docs/guide-ja/start-workflow.md | 10 +++---- docs/guide-ja/structure-applications.md | 26 +++++++++--------- 7 files changed, 58 insertions(+), 57 deletions(-) diff --git a/docs/guide-ja/README.md b/docs/guide-ja/README.md index 5ccae2cb76..2f6db51ee8 100644 --- a/docs/guide-ja/README.md +++ b/docs/guide-ja/README.md @@ -32,14 +32,14 @@ All Rights Reserved. ---------------------- * [概要](structure-overview.md) -* [エントリースクリプト](structure-entry-scripts.md) +* [エントリスクリプト](structure-entry-scripts.md) * [アプリケーション](structure-applications.md) * [アプリケーションコンポーネント](structure-application-components.md) * [コントローラ](structure-controllers.md) * [モデル](structure-models.md) * [ビュー](structure-views.md) * [モジュール](structure-modules.md) -* [フィルター](structure-filters.md) +* [フィルタ](structure-filters.md) * [ウィジェット](structure-widgets.md) * [アセット](structure-assets.md) * [エクステンション](structure-extensions.md) @@ -49,7 +49,7 @@ All Rights Reserved. ---------------- * [概要](runtime-overview.md) -* [ブートストラッピング](runtime-bootstrapping.md) +* [ブートストラップ](runtime-bootstrapping.md) * [ルーティング](runtime-routing.md) * [リクエスト](runtime-requests.md) * [レスポンス](runtime-responses.md) @@ -66,7 +66,7 @@ All Rights Reserved. * [プロパティ](concept-properties.md) * [イベント](concept-events.md) * [ビヘイビア](concept-behaviors.md) -* [設定](concept-configurations.md) +* [コンフィギュレーション](concept-configurations.md) * [エイリアス](concept-aliases.md) * [クラスのオートロード](concept-autoloading.md) * [サービスロケータ](concept-service-locator.md) diff --git a/docs/guide-ja/intro-upgrade-from-v1.md b/docs/guide-ja/intro-upgrade-from-v1.md index 283c88fed0..176d36c82e 100644 --- a/docs/guide-ja/intro-upgrade-from-v1.md +++ b/docs/guide-ja/intro-upgrade-from-v1.md @@ -63,18 +63,18 @@ Yii 2.0 は、1.1 の `CComponent` クラスを二つのクラスに分割しま 通常、基本的なデータ構造を表すクラスに対しては、このことが当てはまります。 -オブジェクトの設定 ------------------- +オブジェクトのコンフィギュレーション +------------------------------------ -[[yii\base\Object|Object]] クラスはオブジェクトを設定するための統一された方法を導入しています。 -[[yii\base\Object|Object]] の全ての派生クラスは、正しく設定されるように、コンストラクタを(それが必要な場合には)以下の方法で宣言すべきです: +[[yii\base\Object|Object]] クラスはオブジェクトのコンフィギュレーションのための統一された方法を導入しています。 +[[yii\base\Object|Object]] の全ての派生クラスは、適切にコンフィギュレーションを適用されるように、コンストラクタを(それが必要な場合には)以下の方法で宣言すべきです: ```php class MyClass extends \yii\base\Object { public function __construct($param1, $param2, $config = []) { - // ... 設定が適用される前の初期化処理 + // ... コンフィギュレーションが適用される前の初期化処理 parent::__construct($config); } @@ -83,16 +83,16 @@ class MyClass extends \yii\base\Object { parent::init(); - // ... 設定が適用された後の初期化処理 + // ... コンフィギュレーションが適用された後の初期化処理 } } ``` -上記において、コンストラクタは最後のパラメータとして設定配列を取らなければなりません。 -設定配列は「名前-値」のペアを含むものであり、コンストラクタの最後でプロパティを初期化するためのものです。 -[[yii\base\Object::init()|init()]] メソッドをオーバーライドして、設定が適用された後に行うべき初期化処理を行うことが出来ます。 +上記において、コンストラクタは最後のパラメータとしてコンフィギュレーション配列を取らなければなりません。 +コンフィギュレーション配列は「名前-値」のペアを含むものであり、コンストラクタの最後でプロパティを初期化するためのものです。 +[[yii\base\Object::init()|init()]] メソッドをオーバーライドして、コンフィギュレーションが適用された後に行うべき初期化処理を行うことが出来ます。 -この規約に従うことによって、設定配列を使って新しいオブジェクトを生成して設定することが出来るようになります: +この規約に従うことによって、コンフィギュレーション配列を使って新しいオブジェクトを生成して設定することが出来るようになります: ```php $object = Yii::createObject([ @@ -102,7 +102,7 @@ $object = Yii::createObject([ ], [$param1, $param2]); ``` -設定に関する更なる詳細は、[オブジェクトの設定](concept-configurations.md) の節で見ることが出来ます。 +コンフィギュレーションに関する更なる詳細は、[オブジェクトのコンフィギュレーション](concept-configurations.md) の節で見ることが出来ます。 イベント @@ -138,7 +138,8 @@ Yii 2.0 は、パスエイリアスの使用を、ファイル/ディレクト 例えば [[yii\caching\FileCache::cachePath]] はパスエイリアスと通常のディレクトリパスの両方を受け取ることが出来ます。 パスエイリアスは、また、クラスの名前空間とも密接に関係しています。 -ルートの名前空間のそれぞれに対してパスエイリアスを定義することが推奨されています。そうすることによって、よけいな設定をしなくても、Yii のクラスオートローダを使うことが出来るようになります。 +ルートの名前空間のそれぞれに対してパスエイリアスを定義することが推奨されています。 +そうすることによって、よけいなコンフィギュレーションをしなくても、Yii のクラスオートローダを使うことが出来るようになります。 例えば、`@yii` は Yii のインストールディレクトリを指しているので、`yii\web\Request` というようなクラスをオートロードすることが出来ます。 サードパーティのライブラリ、例えば Zend フレームワークなどを使う場合には、そのフレームワークのインストールディレクトリを指す `@Zend` というパスエイリアスを定義することが出来ます。 一旦そうしてしまえば、その Zend フレームワークのライブラリ中のどんなクラスでも、同じようにオートロードすることが出来るようになります。 @@ -164,7 +165,7 @@ echo $this->render('_item', ['item' => $item]); PHP を主たるテンプレート言語として使うのに加えて、Yii 2.0 は人気のある二つのテンプレートエンジン、Smarty と Twig に対する正式なサポートを備えています。 Prado テンプレートエンジンはもうサポートされません。 -これらのテンプレートエンジンを使うためには、[[yii\base\View::$renderers|View::$renderers]] プロパティをセットして、`view` アプリケーションコンポーネントを設定する必要があります。 +これらのテンプレートエンジンを使うためには、[[yii\base\View::$renderers|View::$renderers]] プロパティをセットして、`view` アプリケーションコンポーネントを構成する必要があります。 詳細は [テンプレートエンジン](tutorial-template-engines.md) の節を参照してください。 @@ -264,7 +265,7 @@ ActiveForm::end(); コントローラやウィジェットのコンテキストの外で表示されるビューに対してすら、適用できます。 また、`CThemeManager` コンポーネントはもうありません。 -その代りに、`theme` は `view` アプリケーションコンポーネントの設定可能なプロパティになりました。 +その代りに、`theme` は `view` アプリケーションコンポーネントのコンフィギュレーション可能なプロパティになりました。 更なる詳細については [テーマ](output-theming.md) の節を参照してください。 @@ -296,8 +297,8 @@ Yii 2.0 は [PECL intl PHP モジュール](http://pecl.php.net/package/intl) 更なる詳細については [国際化](tutorial-i18n.md) の節を参照してください。 -アクションフィルター --------------------- +アクションフィルタ +------------------ 新しいアクションフィルターはビヘイビアによって実装されています。 新しいカスタムフィルターを定義するためには、[[yii\base\ActionFilter]] を拡張します。 @@ -318,7 +319,7 @@ public function behaviors() } ``` -更なる詳細については [フィルター](structure-filters.md) の節を参照してください。 +更なる詳細については [フィルタ](structure-filters.md) の節を参照してください。 アセット diff --git a/docs/guide-ja/start-databases.md b/docs/guide-ja/start-databases.md index 5e955cc3ee..aec826899a 100644 --- a/docs/guide-ja/start-databases.md +++ b/docs/guide-ja/start-databases.md @@ -2,12 +2,12 @@ ================== この節では、`country` という名前のデータベーステーブルから読み出した国データを表示する新しいページの作り方を説明します。 -この目的を達するために、データベース接続を設定し、[アクティブレコード](db-active-record.md) クラスを作成し、 +この目的を達するために、データベース接続を構成し、[アクティブレコード](db-active-record.md) クラスを作成し、 [アクション](structure-controllers.md) を定義し、そして [ビュー](structure-views.md) を作成します。 このチュートリアルを通じて、次のことをする方法を学びます: -* DB 接続を設定する +* DB 接続を構成する * アクティブレコードのクラスを定義する * アクティブレコードのクラスを使ってデータを検索する * 改ページを伴う方法でビューにデータを表示する @@ -51,7 +51,7 @@ INSERT INTO `country` VALUES ('US','United States',278357000); そして、`country` テーブルは、10 行のデータを持っています。 -DB 接続を設定する +DB 接続を構成する ----------------- 先に進む前に、[PDO](http://www.php.net/manual/en/book.pdo.php) PHP 拡張および使用しているデータベースの PDO ドライバ @@ -73,15 +73,15 @@ return [ ]; ``` -この `config/db.php` というファイルは典型的なファイルベースの [設定](concept-configurations.md) ツールです。 -この設定ファイルが [[yii\db\Connection]] インスタンスの作成と初期化に必要なパラメータを規定します。そして、 +この `config/db.php` というファイルは典型的なファイルベースの [コンフィギュレーション](concept-configurations.md) ツールです。 +このコンフィギュレーションファイルが [[yii\db\Connection]] インスタンスの作成と初期化に必要なパラメータを規定します。そして、 [[yii\db\Connection]] インスタンスを通じて、背後のデータベースに対して SQL クエリを実行することが出来るようになります。 -上記のようにして設定された DB 接続は、アプリケーションコードの中で `Yii::$app->db` という式でアクセスすることが出来ます。 +上記のようにして構成された DB 接続は、アプリケーションコードの中で `Yii::$app->db` という式でアクセスすることが出来ます。 -> Info|情報: `config/db.php` は、メインのアプリケーション設定ファイルである `config/web.php` にインクルードされます。 +> Info|情報: `config/db.php` は、メインのアプリケーションコンフィギュレーションファイルである `config/web.php` にインクルードされます。 この `config/web.php` が [アプリケーション](structure-applications.md) インスタンスが初期化される仕方を規定します。 - 更なる情報については、[設定](concept-configurations.md) の節を参照してください。 + 更なる情報については、[コンフィギュレーション](concept-configurations.md) の節を参照してください。 アクティブレコードを作成する diff --git a/docs/guide-ja/start-gii.md b/docs/guide-ja/start-gii.md index 498f7fcefc..600ce54d08 100644 --- a/docs/guide-ja/start-gii.md +++ b/docs/guide-ja/start-gii.md @@ -17,8 +17,8 @@ Gii を開始する -------------- [Gii](tool-gii.md) は Yii の [モジュール](structure-modules.md) として提供されます。 -Gii は、アプリケーションの [[yii\base\Application::modules|modules]] プロパティの中で設定することで有効にすることが出来ます。 -アプリケーションを生成した仕方にもよりますが、`config/web.php` の設定ファイルの中に、多分、下記のコードが既に提供されているでしょう: +Gii は、アプリケーションの [[yii\base\Application::modules|modules]] プロパティの中で構成することで有効にすることが出来ます。 +アプリケーションを生成した仕方にもよりますが、`config/web.php` のコンフィギュレーションファイルの中に、多分、下記のコードが既に提供されているでしょう: ```php $config = [ ... ]; @@ -29,7 +29,7 @@ if (YII_ENV_DEV) { } ``` -上記の設定は、[開発環境](concept-configurations.md#environment-constants) において、アプリケーションは +上記のコンフィギュレーションは、[開発環境](concept-configurations.md#environment-constants) において、アプリケーションは `gii` という名前のモジュールをインクルードすべきこと、そして `gii` は [[yii\gii\Module]] というクラスのものであることを記述しています。 アプリケーションの [エントリスクリプト](structure-entry-scripts.md) である `web/index.php` をチェックすると、次の行があることに気付くでしょう。 @@ -39,7 +39,7 @@ if (YII_ENV_DEV) { defined('YII_ENV') or define('YII_ENV', 'dev'); ``` -この行のおかげで、アプリケーションは開発モードになり、上記の設定によって、Gii が有効になります。 +この行のおかげで、アプリケーションは開発モードになり、上記のコンフィギュレーションによって、Gii が有効になります。 これで、下記の URL によって Gii にアクセスすることが出来ます: ``` @@ -47,7 +47,7 @@ http://hostname/index.php?r=gii ``` > Note|注意: ローカルホスト以外のマシンから GII にアクセスしようとすると、既定ではセキュリティ上の -> 目的からアクセスが拒否されます。下記のように Gii を設定して、許可される IP アドレスを追加することが出来ます。 +> 目的からアクセスが拒否されます。下記のように Gii を構成して、許可される IP アドレスを追加することが出来ます。 > ```php 'gii' => [ diff --git a/docs/guide-ja/start-installation.md b/docs/guide-ja/start-installation.md index dfae5440e4..8cc7142efe 100644 --- a/docs/guide-ja/start-installation.md +++ b/docs/guide-ja/start-installation.md @@ -54,7 +54,7 @@ Composer がインストールされたら、ウェブからアクセスでき 1. [yiiframework.com](http://www.yiiframework.com/download/) からアーカイブファイルをダウンロードする。 2. ダウンロードしたファイルをウェブからアクセスできるフォルダーに展開する。 -3. `config/web.php` ファイルを編集して、`cookieValidationKey` 設定アイテムに秘密キーを入力する +3. `config/web.php` ファイルを編集して、`cookieValidationKey` というコンフィギュレーション項目に秘密キーを入力する (Composer を使って Yii をインストールするときは、これは自動的に実行されます): ```php @@ -109,7 +109,7 @@ Yii の最低必要条件を満たすように PHP のインストールを構 また、アプリケーションがデータベースを必要とする場合は、[PDO PHP 拡張](http://www.php.net/manual/ja/pdo.installation.php) および対応するデータベースドライバ (MySQL データベースのための `pdo_mysql` など) をインストールしなければなりません。 -ウェブサーバを設定する +ウェブサーバを構成する ---------------------- > Info|情報: もし Yii の試運転をしているだけで、実運用のサーバに配置する意図がないのであれば、当面、この項は飛ばしても構いません。 @@ -131,7 +131,7 @@ Yii 2.0 は、また、facebook の [HHVM](http://hhvm.com/) とも互換性が 更なる詳細については、[共有ホスティング環境](tutorial-shared-hosting.md) の節を参照してください。 -### 推奨される Apache の設定 +### 推奨される Apache の構成 下記の設定を Apache の `httpd.conf` ファイルまたはバーチャルホスト設定の中で使います。 `path/to/basic/web` の部分を `basic/web` の実際のパスに置き換えなければならないことに注意してください。 @@ -154,7 +154,7 @@ DocumentRoot "path/to/basic/web" ``` -### 推奨される Nginx の設定 +### 推奨される Nginx の構成 [Nginx](http://wiki.nginx.org/) を使うためには、PHP を [FPM SAPI](http://jp1.php.net/install.fpm) としてインストールしていなければなりません。 下記の設定を使い、`path/to/basic/web` の部分を `basic/web` の実際のパスに置き換え、`mysite.local` を実際のサーバのホスト名に置き換えてください。 @@ -199,7 +199,7 @@ server { } ``` -この設定を使う場合は、同時に `php.ini` ファイルで `cgi.fix_pathinfo=0` も設定して、 +この構成を使う場合は、同時に `php.ini` ファイルで `cgi.fix_pathinfo=0` も設定して、 多数の不要な `stat()` の呼び出しを避けるべきです。 また、HTTPS サーバを走らせている場合には、安全な接続であることを Yii が正しく検知できるように、 diff --git a/docs/guide-ja/start-workflow.md b/docs/guide-ja/start-workflow.md index 3397e8cd8a..d01d7008ca 100644 --- a/docs/guide-ja/start-workflow.md +++ b/docs/guide-ja/start-workflow.md @@ -2,7 +2,7 @@ ========================== Yii のインストールが終ると、実際に動く Yii のアプリケーションにアクセスすることが出来るようになります。 -その URL は、`http://hostname/basic/web/index.php` あるいは `http://hostname/index.php` など、設定によつて異なります。 +その URL は、`http://hostname/basic/web/index.php` あるいは `http://hostname/index.php` など、設定によって異なります。 この節では、アプリケーションに組み込み済みの機能を紹介し、コードがどのように組織されているか、 そして、一般にアプリケーションがリクエストをどのように処理するかを説明します。 @@ -41,9 +41,9 @@ Yii のインストールが終ると、実際に動く Yii のアプリケー ``` basic/ アプリケーションのベースパス composer.json Composer によって使用される。パッケージ情報を記述 - config/ アプリケーションその他の設定を格納 - console.php コンソールアプリケーションの設定 - web.php ウェブアプリケーションの設定 + config/ アプリケーションその他のコンフィギュレーションを格納 + console.php コンソールアプリケーションのコンフィギュレーション + web.php ウェブアプリケーションのコンフィギュレーション commands/ コンソールコマンドのクラスを格納 controllers/ コントローラのクラスを格納 models/ モデルのクラスを格納 @@ -81,7 +81,7 @@ Yii は [モデル・ビュー・コントローラ (MVC)](http://wikipedia.org/ ![リクエストのライフサイクル](images/application-lifecycle.png) 1. ユーザが [エントリスクリプト](structure-entry-scripts.md) `web/index.php` に対してリクエストを出します。 -2. エントリスクリプトはアプリケーションの [設定](concept-configurations.md) を読み出して、 +2. エントリスクリプトはアプリケーションの [コンフィギュレーション](concept-configurations.md) を読み出して、 リクエストを処理する [アプリケーション](structure-applications.md) のインスタンスを作成します。 3. アプリケーションは、[リクエスト](runtime-requests.md) アプリケーションコンポーネントの助力を得て、 リクエストされた [ルート](runtime-routing.md) を解決します。 diff --git a/docs/guide-ja/structure-applications.md b/docs/guide-ja/structure-applications.md index de51e7232e..f296a8fb9a 100644 --- a/docs/guide-ja/structure-applications.md +++ b/docs/guide-ja/structure-applications.md @@ -11,29 +11,29 @@ 名前が示すように、前者は主にウェブのリクエストを処理し、後者はコンソールコマンドのリクエストを処理します。 -## アプリケーションの設定 +## アプリケーションのコンフィギュレーション [エントリスクリプト](structure-entry-scripts.md) は、アプリケーションを作成するときに、 -下記のように、[設定](concept-configurations.md) を読み込んで、それをアプリケーションに適用します: +下記のように、[コンフィギュレーション](concept-configurations.md) を読み込んで、それをアプリケーションに適用します: ```php require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); -// アプリケーションの設定を読み込む +// アプリケーションのコンフィギュレーションを読み込む $config = require(__DIR__ . '/../config/web.php'); -// アプリケーションのインスタンスを作成し、設定を適用する +// アプリケーションのインスタンスを作成し、コンフィギュレーションを適用する (new yii\web\Application($config))->run(); ``` -通常の [設定](concept-configurations.md) と同じように、アプリケーションの設定は、アプリケーションオブジェクトのプロパティをどのように初期化するかを規定するものです。 -アプリケーションの設定は、たいていは非常に複雑なものですから、通常は、上記の例の `web.php` ファイルのように、[設定ファイル](concept-configurations.md#configuration-files) に保管されます。 +通常の [コンフィギュレーション](concept-configurations.md) と同じように、アプリケーションのコンフィギュレーションは、アプリケーションオブジェクトのプロパティをどのように初期化するかを規定するものです。 +アプリケーションのコンフィギュレーションは、たいていは非常に複雑なものですから、通常は、上記の例の `web.php` ファイルのように、[コンフィギュレーションファイル](concept-configurations.md#configuration-files) に保管されます。 ## アプリケーションのプロパティ -アプリケーションの設定で構成すべき重要なアプリケーションのプロパティは数多くあります。 +アプリケーションのコンフィギュレーションで構成すべき重要なアプリケーションのプロパティは数多くあります。 それらのプロパティの典型的なものは、アプリケーションが走る環境を記述するものです。 例えば、アプリケーションは、どのようにして [コントローラ](structure-controllers.md) をロードするか、また、どこにテンポラリファイルを保存するかなどを知らなければなりません。 以下において、それらのプロパティを要約します。 @@ -89,7 +89,7 @@ $config = require(__DIR__ . '/../config/web.php'); ] ``` -このプロパティが提供されているのは、[[Yii::setAlias()]] メソッドを呼び出す代りに、アプリケーション設定を使ってエイリアスを定義することが出来るようにするためです。 +このプロパティが提供されているのは、[[Yii::setAlias()]] メソッドを呼び出す代りに、アプリケーションのコンフィギュレーションを使ってエイリアスを定義することが出来るようにするためです。 #### [[yii\base\Application::bootstrap|bootstrap]] @@ -103,7 +103,7 @@ $config = require(__DIR__ . '/../config/web.php'); - [components](#components) によって規定されるアプリケーションコンポーネントの ID。 - [modules](#modules) によって規定されるモジュールの ID。 - クラス名。 -- 設定配列。 +- コンフィギュレーション配列。 - コンポーネントを作成して返す無名関数。 例えば、 @@ -117,7 +117,7 @@ $config = require(__DIR__ . '/../config/web.php'); // クラス名 'app\components\Profiler', - // 設定配列 + // コンフィギュレーション配列 [ 'class' => 'app\components\Profiler', 'level' => 3, @@ -144,12 +144,12 @@ $config = require(__DIR__ . '/../config/web.php'); ブートストラップの過程で、各コンポーネントのインスタンスが作成されます。 そして、コンポーネントクラスが [[yii\base\BootstrapInterface]] を実装している場合は、その [[yii\base\BootstrapInterface::bootstrap()|bootstrap()]] メソッドも呼び出されます。 -もう一つの実用的な例が [ベーシックアプリケーションテンプレート](start-installation.md) のアプリケーション設定の中にあります。 +もう一つの実用的な例が [ベーシックアプリケーションテンプレート](start-installation.md) のアプリケーションのコンフィギュレーションの中にあります。 そこでは、アプリケーションが開発環境で走るときには `debug` モジュールと `gii` モジュールがブートストラップコンポーネントとして構成されています。 ```php if (YII_ENV_DEV) { - // 'dev' 環境のための設定の調整 + // 'dev' 環境のためのコンフィギュレーションの調整 $config['bootstrap'][] = 'debug'; $config['modules']['debug'] = 'yii\debug\Module'; @@ -169,7 +169,7 @@ if (YII_ENV_DEV) { これは、全てのユーザリクエストを処理すべき [コントローラアクション](structure-controllers.md) を規定します。 これは主としてアプリケーションがメンテナンスモードにあって、入ってくる全てのリクエストを単一のアクションで処理する必要があるときに使われます。 -構成は配列の形を取り、最初の要素はアクションのルートを指定します。 +コンフィギュレーションは配列の形を取り、最初の要素はアクションのルートを指定します。 そして、配列の残りの要素 (キー・値のペア) は、アクションに渡されるパラメータを指定します。 例えば、 From 4f2d46a448e0509a1d67b372d93fa00e898b9f94 Mon Sep 17 00:00:00 2001 From: Nobuo Kihara Date: Tue, 28 Oct 2014 23:02:15 +0900 Subject: [PATCH 3/5] docs/guide-ja/structure-applications.md - language --- docs/guide-ja/structure-applications.md | 68 ++++++++++++------------ docs/guide-ja/structure-entry-scripts.md | 8 +-- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/docs/guide-ja/structure-applications.md b/docs/guide-ja/structure-applications.md index f296a8fb9a..971f8441db 100644 --- a/docs/guide-ja/structure-applications.md +++ b/docs/guide-ja/structure-applications.md @@ -186,8 +186,8 @@ if (YII_ENV_DEV) { #### [[yii\base\Application::components|components]] -This is the single most important property. It allows you to register a list of named components -called [application components](structure-application-components.md) that you can use in other places. For example, +これが唯一最重要なプロパティです。これによって、[アプリケーションコンポーネント](structure-application-components.md) と呼ばれる一連の名前付きのコンポーネントを登録して、それらを他の場所で使うことが出来るようになります。 +例えば、 ```php [ @@ -203,22 +203,23 @@ called [application components](structure-application-components.md) that you ca ] ``` -Each application component is specified as a key-value pair in the array. The key represents the component ID, -while the value represents the component class name or [configuration](concept-configurations.md). +全てのアプリケーションコンポーネントは、それぞれ、配列の中で「キー・値」のペアとして規定されます。 +キーはコンポーネントの ID を示し、値はコンポーネントのクラス名または [コンフィギュレーション](concept-configurations.md) を示します。 -You can register any component with an application, and the component can later be accessed globally -using the expression `\Yii::$app->ComponentID`. +どのようなコンポーネントでもアプリケーションとともに登録することが出来ます。 +そして登録されたコンポーネントは、後で、`\Yii::$app->ComponentID` という式を使ってグローバルにアクセスすることが出来ます。 -Please read the [Application Components](structure-application-components.md) section for details. +詳細は [アプリケーションコンポーネント](structure-application-components.md) の節を呼んでください。 #### [[yii\base\Application::controllerMap|controllerMap]] -This property allows you to map a controller ID to an arbitrary controller class. By default, Yii maps -controller IDs to controller classes based on a [convention](#controllerNamespace) (e.g. the ID `post` would be mapped -to `app\controllers\PostController`). By configuring this property, you can break the convention for -specific controllers. In the following example, `account` will be mapped to -`app\controllers\UserController`, while `article` will be mapped to `app\controllers\PostController`. +このプロパティは、コントローラ ID を任意のコントローラクラスに割り付けることを可能にするものです。 +既定では、Yii は [規約](#controllerNamespace) に基いてコントローラ ID をコントローラクラスに割り付けます +(例えば、`post` という ID は `app\controllers\PostController` に割り付けられます)。 +このプロパティを構成することによって、特定のコントローラに対する規約を破ることが出来ます。 +下記の例では、`account` は `app\controllers\UserController` に割り付けられ、 +`article` は `app\controllers\PostController` に割り付けられることになります。 ```php [ @@ -234,43 +235,40 @@ specific controllers. In the following example, `account` will be mapped to ] ``` -The array keys of this property represent the controller IDs, while the array values represent the corresponding -controller class names or [configurations](concept-configurations.md). +このプロパティの配列のキーはコントローラ ID を表し、配列の値は対応するコントローラクラスの名前または [コンフィギュレーション](concept-configurations.md) を表します。 #### [[yii\base\Application::controllerNamespace|controllerNamespace]] -This property specifies the default namespace under which controller classes should be located. It defaults to -`app\controllers`. If a controller ID is `post`, by convention the corresponding controller class name (without -namespace) would be `PostController`, and the fully qualified class name would be `app\controllers\PostController`. +このプロパティは、コントローラクラスが配置されるべき既定の名前空間を指定するものです。 +デフォルト値は `app\controllers` です。 +コントローラ ID が `post` である場合、規約によって対応するコントローラの (名前空間を略した) クラス名は `PostController` となり、 +完全修飾クラス名は `app\controllers\PostController` となります。 -Controller classes may also be located under sub-directories of the directory corresponding to this namespace. -For example, given a controller ID `admin/post`, the corresponding fully qualified controller class would -be `app\controllers\admin\PostController`. +コントローラクラスは、この名前空間に対応するディレクトリのサブディレクトリに配置されても構いません。 +例えば、コントローラ ID として `admin/post` を仮定すると、対応するコントローラの完全修飾クラス名は `app\controllers\admin\PostController` となります。 -It is important that the fully qualified controller classes should be [autoloadable](concept-autoloading.md) -and the actual namespace of your controller classes match the value of this property. Otherwise, -you will receive "Page Not Found" error when accessing the application. +完全修飾のコントローラクラスが [オートロード可能](concept-autoloading.md) でなければならず、 +コントローラクラスの実際の名前空間がこのプロパティと合致していなければならない、 +ということは非常に重要なことです。 +そうでないと、アプリケーションにアクセスしたときに "ページがみつかりません" というエラーを受け取ることになります。 -In case you want to break the convention as described above, you may configure the [controllerMap](#controllerMap) -property. +上述の規約を破りたい場合は、[controllerMap](#controllerMap) プロパティを構成することが出来ます。 #### [[yii\base\Application::language|language]] -This property specifies the language in which the application should display content to end users. -The default value of this property is `en`, meaning English. You should configure this property -if your application needs to support multiple languages. +このプロパティは、アプリケーションがコンテンツをエンドユーザに表示するときに使うべき言語を規定します。 +このプロパティのデフォルト値は `en` であり、英語を意味します。 +アプリケーションが多言語をサポートする必要があるときは、このプロパティを構成すべきです。 -The value of this property determines various [internationalization](tutorial-i18n.md) aspects, -including message translation, date formatting, number formatting, etc. For example, the [[yii\jui\DatePicker]] widget -will use this property value by default to determine in which language the calendar should be displayed and how -should the date be formatted. +このプロパティの値が、メッセージの翻訳、日付の書式、数字の書式などを含めて、[国際化](tutorial-i18n.md) のさまざまな側面を決定します。 +例えば、[[yii\jui\DatePicker]] ウィジェットは、どの言語でカレンダーを表示すべきか、そして日付をどのように書式設定すべきかを、既定では、このプロパティを使用して決定します。 -It is recommended that you specify a language in terms of an [IETF language tag](http://en.wikipedia.org/wiki/IETF_language_tag). -For example, `en` stands for English, while `en-US` stands for English (United States). +言語を指定するのには、[IETF 言語タグ](http://ja.wikipedia.org/wiki/IETF%E8%A8%80%E8%AA%9E%E3%82%BF%E3%82%B0) に従うことが推奨されます。 +例えば、`en` は英語を意味し、`en-US` はアメリカ合衆国の英語を意味します。 -More details about this property can be found in the [Internationalization](tutorial-i18n.md) section. +このプロパティに関する更なる詳細は [国際化](tutorial-i18n.md) の節で読むことが出来ます。 #### [[yii\base\Application::modules|modules]] diff --git a/docs/guide-ja/structure-entry-scripts.md b/docs/guide-ja/structure-entry-scripts.md index 21afbe2347..eadf96167f 100644 --- a/docs/guide-ja/structure-entry-scripts.md +++ b/docs/guide-ja/structure-entry-scripts.md @@ -19,7 +19,7 @@ * グローバルな定数を定義する; * [Composer のオートローダ](http://getcomposer.org/doc/01-basic-usage.md#autoloading) を登録する; * [[Yii]] クラスファイルをインクルードする; -* アプリケーション設定を読み出す; +* アプリケーションのコンフィギュレーションを読み出す; * [アプリケーション](structure-applications.md) のインスタンスを生成して構成する; * [[yii\base\Application::run()]] を呼んで、受け取ったリクエストを処理する。 @@ -40,7 +40,7 @@ require(__DIR__ . '/../vendor/autoload.php'); // Yii クラスファイルをインクルード require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); -// アプリケーション設定を読み出す +// アプリケーションのコンフィギュレーションを読み出す $config = require(__DIR__ . '/../config/web.php'); // アプリケーションを作成し、構成して、走らせる @@ -75,7 +75,7 @@ require(__DIR__ . '/vendor/autoload.php'); // Yii クラスファイルをインクルード require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); -// アプリケーション設定を読み出す +// アプリケーションのコンフィギュレーションを読み出す $config = require(__DIR__ . '/config/console.php'); $application = new yii\console\Application($config); @@ -95,7 +95,7 @@ Yii は下記の三つの定数をサポートしています: この理由により、デバッグモードは主として開発時に使用されるべきものとなります。 `YII_DEBUG` の既定値は false です。 * `YII_ENV`: どういう環境でアプリケーションが走るかを規定します。 - 詳細については、[設定](concept-configurations.md#environment-constants) の節で説明されます。 + 詳細については、[コンフィギュレーション](concept-configurations.md#environment-constants) の節で説明されます。 `YII_ENV` の既定値は `'prod'` です。これはアプリケーションが実運用環境で走ることを意味します。 * `YII_ENABLE_ERROR_HANDLER`: Yii によって提供されるエラーハンドラを有効にするかどうかを規定します。 この定数の既定値は true です。 From 0ab0eb495feae06ce6fe411a305d099e4a896630 Mon Sep 17 00:00:00 2001 From: Nobuo Kihara Date: Wed, 29 Oct 2014 08:01:55 +0900 Subject: [PATCH 4/5] docs/guide-ja/structure-applications.md - charset [ci skip] --- docs/guide-ja/structure-applications.md | 68 ++++++++++++------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/docs/guide-ja/structure-applications.md b/docs/guide-ja/structure-applications.md index 971f8441db..555545cebc 100644 --- a/docs/guide-ja/structure-applications.md +++ b/docs/guide-ja/structure-applications.md @@ -273,18 +273,18 @@ if (YII_ENV_DEV) { #### [[yii\base\Application::modules|modules]] -This property specifies the [modules](structure-modules.md) that the application contains. +このプロパティはアプリケーションが含む [モジュール](structure-modules.md) を規定します。 -The property takes an array of module classes or [configurations](concept-configurations.md) with the array keys -being the module IDs. For example, +このプロパティは、モジュールのクラスまたは [コンフィギュレーション](concept-configurations.md) の配列であり、 +その配列のキーはモジュールの ID です。例えば、 ```php [ 'modules' => [ - // a "booking" module specified with the module class + // モジュールクラスで規定された "booking" モジュール 'booking' => 'app\modules\booking\BookingModule', - // a "comment" module specified with a configuration array + // コンフィギュレーション配列で規定された "comment" モジュール 'comment' => [ 'class' => 'app\modules\comment\CommentModule', 'db' => 'db', @@ -293,24 +293,24 @@ being the module IDs. For example, ] ``` -Please refer to the [Modules](structure-modules.md) section for more details. +詳細は [モジュール](structure-modules.md) の節を参照してください。 #### [[yii\base\Application::name|name]] -This property specifies the application name that may be displayed to end users. Unlike the -[[yii\base\Application::id|id]] property which should take a unique value, the value of this property is mainly for -display purpose and does not need to be unique. +このプロパティはアプリケーション名を規定します。これは、エンドユーザに対して表示されるかも知れません。 +[[yii\base\Application::id|id]] プロパティがユニークな値でなければならないのとは違って、このプロパティの値は +主として表示目的であり、ユニークである必要はありません。 -You do not always need to configure this property if none of your code is using it. +コードで使わないのであれば、このプロパティを構成する必要はありません。 #### [[yii\base\Application::params|params]] -This property specifies an array of globally accessible application parameters. Instead of using hardcoded -numbers and strings everywhere in your code, it is a good practice to define them as application parameters -in a single place and use the parameters in places where needed. For example, you may define the thumbnail -image size as a parameter like the following: +このプロパティは、グローバルにアクセス可能なアプリケーションパラメータの配列を規定します。 +コードの中のいたる処でハードコードされた数値や文字列を使う代りに、それらをアプリケーションパラメータとして +一ヶ所で定義し、必要な場所ではそのパラメータを使うというのが良い慣行です。 +例えば、次のように、サムネール画像のサイズをパラメータとして定義することが出来ます: ```php [ @@ -320,58 +320,58 @@ image size as a parameter like the following: ] ``` -Then in your code where you need to use the size value, you can simply use the code like the following: +そして、このサイズの値を使う必要があるコードにおいては、ただ単に下記のようなコードを使うことが出来ます: ```php $size = \Yii::$app->params['thumbnail.size']; $width = \Yii::$app->params['thumbnail.size'][0]; ``` -Later if you decide to change the thumbnail size, you only need to modify it in the application configuration -without touching any dependent code. +後でサムネールのサイズを変更すると決めたときは、アプリケーションのコンフィギュレーションにおいてのみサイズを修正すればよく、 +これに依存するコードには少しも触れる必要がありません。 #### [[yii\base\Application::sourceLanguage|sourceLanguage]] -This property specifies the language that the application code is written in. The default value is `'en-US'`, -meaning English (United States). You should configure this property if the text content in your code is not in English. +このプロパティはアプリケーションコードが書かれている言語を規定します。デフォルト値は`'en-US'`、アメリカ合衆国の英語です。 +あなたのコードのテキスト内容が英語以外で書かれているときは、このプロパティを構成すべきです。 -Like the [language](#language) property, you should configure this property in terms of -an [IETF language tag](http://en.wikipedia.org/wiki/IETF_language_tag). For example, `en` stands for English, -while `en-US` stands for English (United States). +[language](#language) プロパティと同様に、このプロパティは [IETF 言語タグ](http://ja.wikipedia.org/wiki/IETF%E8%A8%80%E8%AA%9E%E3%82%BF%E3%82%B0) に従って構成すべきです。 +例えば、`en` は英語を意味し、`en-US` はアメリカ合衆国の英語を意味します。 -More details about this property can be found in the [Internationalization](tutorial-i18n.md) section. +このプロパティに関する更なる詳細は [国際化](tutorial-i18n.md) の節で読むことが出来ます。 #### [[yii\base\Application::timeZone|timeZone]] -This property is provided as an alternative way of setting the default time zone of PHP runtime. -By configuring this property, you are essentially calling the PHP function -[date_default_timezone_set()](http://php.net/manual/en/function.date-default-timezone-set.php). For example, +このプロパティは、PHP ランタイムのデフォルトタイムゾーンを設定する代替手段として提供されています。 +このプロパティを構成すると、本質的には PHP 関数 [date_default_timezone_set()](http://php.net/manual/ja/function.date-default-timezone-set.php) を呼ぶことになります。 +例えば、 ```php [ - 'timeZone' => 'America/Los_Angeles', + 'timeZone' => 'Asia/Tokyo', ] ``` #### [[yii\base\Application::version|version]] -This property specifies the version of the application. It defaults to `'1.0'`. You do not always need to configure -this property if none of your code is using it. +このプロパティはアプリケーションのバージョンを規定します。デフォルト値は `'1.0'` です。 +コードの中で使わないのであれば、必ずしも構成する必要はありません。 -### Useful Properties +### 有用なプロパティ -The properties described in this subsection are not commonly configured because their default values -stipulate common conventions. However, you may still configure them in case you want to break the conventions. +この項で説明されるプロパティは通常は構成されません。というのは、そのデフォルト値が通常の規約を規定するものだからです。 +しかしながら、規約を破る必要がある場合には、これらのプロパティを構成することが出来ます。 #### [[yii\base\Application::charset|charset]] -This property specifies the charset that the application uses. The default value is `'UTF-8'` which should -be kept as is for most applications unless you are working with some legacy systems that use a lot of non-unicode data. +このプロパティはアプリケーションが使う文字セットを規定します。デフォルト値は `'UTF-8'` であり、 +あなたのアプリケーションが多数の非ユニコードデータを使うレガシーシステムと連携するのでなければ、 +そのままにしておくべきです。 #### [[yii\base\Application::defaultRoute|defaultRoute]] From c1c61dfcde6ae25d5eeae8d9d424b190c99c3473 Mon Sep 17 00:00:00 2001 From: Nobuo Kihara Date: Wed, 29 Oct 2014 21:47:14 +0900 Subject: [PATCH 5/5] docs/guide-ja/structure-applications.md translation completed [ci skip] --- docs/guide-ja/structure-applications.md | 196 ++++++++++++------------ 1 file changed, 100 insertions(+), 96 deletions(-) diff --git a/docs/guide-ja/structure-applications.md b/docs/guide-ja/structure-applications.md index 555545cebc..f15dd7345d 100644 --- a/docs/guide-ja/structure-applications.md +++ b/docs/guide-ja/structure-applications.md @@ -376,28 +376,27 @@ $width = \Yii::$app->params['thumbnail.size'][0]; #### [[yii\base\Application::defaultRoute|defaultRoute]] -This property specifies the [route](runtime-routing.md) that an application should use when a request -does not specify one. The route may consist of child module ID, controller ID, and/or action ID. -For example, `help`, `post/create`, `admin/post/create`. If action ID is not given, it will take the default -value as specified in [[yii\base\Controller::defaultAction]]. +このプロパティは、リクエストがルートを指定していないときにアプリケーションが使用すべき [route](runtime-routing.md) を規定します。 +ルートは、チャイルドモジュール ID、コントローラ ID、および/または アクション ID を構成要素とすることが出来ます。 +例えば、`help`、`post/create`、`admin/post/create` などです。 +アクション ID が与えられていない場合は、[[yii\base\Controller::defaultAction]] で規定されるデフォルト値を取ります。 -For [[yii\web\Application|Web applications]], the default value of this property is `'site'`, which means -the `SiteController` controller and its default action should be used. As a result, if you access -the application without specifying a route, it will show the result of `app\controllers\SiteController::actionIndex()`. +[[yii\web\Application|ウェブアプリケーション]] では、このプロパティのデフォルト値は `'site'` であり、 +その意味するところは、`SiteController` コントローラとそのデフォルトアクションが使用されるべきである、ということです。 +結果として、ルートを指定せずにアプリケーションにアクセスすると、`app\controllers\SiteController::actionIndex()` の結果が表示されます。 -For [[yii\console\Application|console applications]], the default value is `'help'`, which means the core command -[[yii\console\controllers\HelpController::actionIndex()]] should be used. As a result, if you run the command `yii` -without providing any arguments, it will display the help information. +[[yii\console\Application|コンソールアプリケーション]] では、デフォルト値は `'help'` であり、コアコマンドの [[yii\console\controllers\HelpController::actionIndex()]] が使用されるべきであるという意味です。 +結果として、引数を与えずに `yii` というコマンドを走らせると、ヘルプ情報が表示されることになります。 #### [[yii\base\Application::extensions|extensions]] -This property specifies the list of [extensions](structure-extensions.md) that are installed and used by the application. -By default, it will take the array returned by the file `@vendor/yiisoft/extensions.php`. The `extensions.php` file -is generated and maintained automatically when you use [Composer](http://getcomposer.org) to install extensions. -So in most cases, you do not need to configure this property. +このプロパティは、アプリケーションにインストールされて使われる [エクステンション](structure-extensions.md) を規定するリストです。 +デフォルトでは、`@vendor/yiisoft/extensions.php` というファイルによって返される配列を取ります。 +`extensions.php` は、[Composer](http://getcomposer.org) を使ってエクステンションをインストールすると、自動的に生成され保守されます。 +ですから、たいていの場合、このプロパティをあなたが構成する必要はありません。 -In the special case when you want to maintain extensions manually, you may configure this property like the following: +エクステンションを手作業で保守したいという特殊なケースにおいては、次のようにしてこのプロパティを構成することが出来ます: ```php [ @@ -405,82 +404,88 @@ In the special case when you want to maintain extensions manually, you may confi [ 'name' => 'extension name', 'version' => 'version number', - 'bootstrap' => 'BootstrapClassName', // optional, may also be a configuration array + 'bootstrap' => 'BootstrapClassName', // オプション、コンフィギュレーション配列でもよい 'alias' => [ // optional '@alias1' => 'to/path1', '@alias2' => 'to/path2', ], ], - // ... more extensions like the above ... + // ... 上記と同じように、更にエクステンションを構成 ... ], ] ``` -As you can see, the property takes an array of extension specifications. Each extension is specified with an array -consisting of `name` and `version` elements. If an extension needs to run during the [bootstrap](runtime-bootstrapping.md) -process, a `bootstrap` element may be specified with a bootstrapping class name or a [configuration](concept-configurations.md) -array. An extension may also define a few [aliases](concept-aliases.md). +見て分かるように、このプロパティはエクステンションの仕様を示す配列を取ります。 +それぞれのエクステンションは、`name` と `version` の要素を含む配列によって規定されます。 +エクステンションが [ブートストラップ](runtime-bootstrapping.md) の過程で走る必要がある場合には、 +`bootstrap` 要素をブートストラップのクラス名または [コンフィギュレーション](concept-configurations.md) 配列によって規定することが出来ます。 +また、エクステンションはいくつかの [エイリアス](concept-aliases.md) を定義することも出来ます。 #### [[yii\base\Application::layout|layout]] -This property specifies the name of the default layout that should be used when rendering a [view](structure-views.md). -The default value is `'main'`, meaning the layout file `main.php` under the [layout path](#layoutPath) should be used. -If both of the [layout path](#layoutPath) and the [view path](#viewPath) are taking the default values, -the default layout file can be represented as the path alias `@app/views/layouts/main.php`. +このプロパティは、[ビュー](structure-views.md) を描画するときに使われるべきデフォルトのレイアウトを規定します。 +デフォルト値は `'main'` であり、[レイアウトパス](#layoutPath) の下にある `main.php` というファイルが使われるべき事を意味します。 +[レイアウトパス](#layoutPath) と [ビューパス](#viewPath) の両方がデフォルト値を取る場合、 +デフォルトのレイアウトファイルは `@app/views/layouts/main.php` というパスエイリアスとして表すことが出来ます。 -You may configure this property to be `false` if you want to disable layout by default, although this is very rare. +滅多には無いことですが、レイアウトをデフォルトで無効にしたい場合は、このプロパティを `false` として構成することが出来ます。 #### [[yii\base\Application::layoutPath|layoutPath]] -This property specifies the path where layout files should be looked for. The default value is -the `layouts` sub-directory under the [view path](#viewPath). If the [view path](#viewPath) is taking -its default value, the default layout path can be represented as the path alias `@app/views/layouts`. +このプロパティは、レイアウトファイルが捜されるべきパスを規定します。 +デフォルト値は、[ビューパス](#viewPath) の下の `layouts` サブディレクトリです。 +[ビューパス](#viewPath) がデフォルト値を取る場合、デフォルトのレイアウトパスは `@app/views/layouts` というパスエイリアスとして表すことが出来ます。 -You may configure it as a directory or a path [alias](concept-aliases.md). +このプロパティはディレクトリまたはパス [エイリアス](concept-aliases.md) として構成することが出来ます。 #### [[yii\base\Application::runtimePath|runtimePath]] -This property specifies the path where temporary files, such as log files, cache files, can be generated. -The default value is the directory represented by the alias `@app/runtime`. +このプロパティは、ログファイルやキャッシュファイルなどの一時的ファイルを生成することが出来るパスを規定します。 +デフォルト値は、`@app/runtime` というエイリアスで表現されるディレクトリです。 -You may configure it as a directory or a path [alias](concept-aliases.md). Note that the runtime path must -be writable by the process running the application. And the path should be protected from being accessed -by end users because the temporary files under it may contain sensitive information. +このプロパティはディレクトリまたはパス [エイリアス](concept-aliases.md) として構成することが出来ます。 +ランタイムパスは、アプリケーションを走らせているプロセスによって書き込みが可能なものでなければならないことに注意してください。 +そして、この下にある一時的ファイルは秘匿を要する情報を含みうるものですので、ランタイムパスはエンドユーザによるアクセスから保護されるべきです。 -To simplify accessing to this path, Yii has predefined a path alias named `@runtime` for it. +このパスに簡単にアクセスできるように、Yii は `@runtime` というパスエイリアスを事前に定義しています。 #### [[yii\base\Application::viewPath|viewPath]] -This property specifies the root directory where view files are located. The default value is the directory -represented by the alias `@app/views`. You may configure it as a directory or a path [alias](concept-aliases.md). +このプロパティはビューファイルが配置されるルートディレクトリを規定します。 +デフォルト値は、`@app/views` というエイリアスで表現されるディレクトリです。 +このプロパティはディレクトリまたはパス [エイリアス](concept-aliases.md) として構成することが出来ます。 #### [[yii\base\Application::vendorPath|vendorPath]] -This property specifies the vendor directory managed by [Composer](http://getcomposer.org). It contains -all third party libraries used by your application, including the Yii framework. The default value is -the directory represented by the alias `@app/vendor`. +このプロパティは、[Composer](http://getcomposer.org) によって管理される vendor ディレクトリを規定します。 +Yii フレームワークを含めて、あなたのアプリケーションによって使われる全てのサードパーティライブラリを格納するディレクトリです。 +デフォルト値は、`@app/vendor` というエイリアスで表現されるディレクトリです。 +このプロパティはディレクトリまたはパス [エイリアス](concept-aliases.md) として構成することが出来ます。 +このプロパティを修正するときは、必ず、Composer の構成もそれに合せて調整してください。 You may configure this property as a directory or a path [alias](concept-aliases.md). When you modify this property, make sure you also adjust the Composer configuration accordingly. -To simplify accessing to this path, Yii has predefined a path alias named `@vendor` for it. +このパスに簡単にアクセスできるように、Yii は `@vendor` というパスエイリアスを事前に定義しています。 #### [[yii\console\Application::enableCoreCommands|enableCoreCommands]] -This property is supported by [[yii\console\Application|console applications]] only. It specifies -whether the core commands included in the Yii release should be enabled. The default value is `true`. +このプロパティは [[yii\console\Application|コンソールアプリケーション]] においてのみサポートされています。 +Yii リリースに含まれているコアコマンドを有効にすべきか否かを規定します。デフォルト値は `true` です。 -## Application Events +## アプリケーションのイベント +アプリケーションはリクエストを処理するライフサイクルの中でいくつかのイベントを発生させます。 +これらのイベントに対して、下記のようにして、アプリケーションのコンフィギュレーションの中でイベントハンドラを付けることが出来ます。 An application triggers several events during the lifecycle of handling an request. You may attach event handlers to these events in application configurations like the following, @@ -492,11 +497,10 @@ handlers to these events in application configurations like the following, ] ``` -The use of the `on eventName` syntax is described in the [Configurations](concept-configurations.md#configuration-format) -section. +`on eventName` という構文の使い方については、[コンフィギュレーション](concept-configurations.md#configuration-format) の節で説明されています。 -Alternatively, you may attach event handlers during the [bootstrapping process](runtime-bootstrapping.md) process -after the application instance is created. For example, +別の方法として、アプリケーションのインスタンスが生成された後、[ブートストラップの過程](runtime-bootstrapping.md) の中でイベントハンドラを付けることも出来ます。 +例えば、 ```php \Yii::$app->on(\yii\base\Application::EVENT_BEFORE_REQUEST, function ($event) { @@ -506,33 +510,33 @@ after the application instance is created. For example, ### [[yii\base\Application::EVENT_BEFORE_REQUEST|EVENT_BEFORE_REQUEST]] -This event is triggered *before* an application handles a request. The actual event name is `beforeRequest`. +このイベントは、アプリケーションがリクエストを処理する *前* に発生します。 +実際のイベント名は `beforeRequest` です。 -When this event is triggered, the application instance has been configured and initialized. So it is a good place -to insert your custom code via the event mechanism to intercept the request handling process. For example, -in the event handler, you may dynamically set the [[yii\base\Application::language]] property based on some parameters. +このイベントが発生するときには、アプリケーションのインスタンスは既に構成されて初期化されています。 +ですから、イベントメカニズムを使って、リクエスト処理のプロセスに横槍を入れるカスタムコードを挿入するのには、ちょうど良い場所です。 +例えば、このイベントハンドラの中で、何らかのパラメータに基いて [[yii\base\Application::language]] プロパティを動的にセットすることが出来ます。 ### [[yii\base\Application::EVENT_AFTER_REQUEST|EVENT_AFTER_REQUEST]] -This event is triggered *after* an application finishes handling a request but *before* sending the response. -The actual event name is `afterRequest`. +このイベントは、アプリケーションがリクエストの処理を完了した *後*、レスポンスを送信する *前* に発生します。 +実際のイベント名は `afterRequest` です。 -When this event is triggered, the request handling is completed and you may take this chance to do some postprocessing -of the request or customize the response. +このイベントが発生するときにはリクエストの処理は完了していますので、この機をとらえて、リクエストに対する何らかの後処理をしたり、レスポンスをカスタマイズしたりすることが出来ます。 -Note that the [[yii\web\Response|response]] component also triggers some events while it is sending out -response content to end users. Those events are triggered *after* this event. +[[yii\web\Response|response]] コンポーネントも、エンドユーザにレスポンスのコンテンツを送出する間にいくつかのイベントを発生させることに注意してください。 +それらのイベントは、このイベントの *後* に発生します。 ### [[yii\base\Application::EVENT_BEFORE_ACTION|EVENT_BEFORE_ACTION]] -This event is triggered *before* running every [controller action](structure-controllers.md). -The actual event name is `beforeAction`. +このイベントは、[コントローラアクション](structure-controllers.md) を走らせる *前* に毎回発生します。 +実際のイベント名は `beforeAction` です。 -The event parameter is an instance of [[yii\base\ActionEvent]]. An event handler may set -the [[yii\base\ActionEvent::isValid]] property to be `false` to stop running the action. -For example, +イベントのパラメータは [[yii\base\ActionEvent]] のインスタンスです。 +イベントハンドラは、[[yii\base\ActionEvent::isValid]] プロパティを `false` にセットして、アクションが走るのを止めることが出来ます。 +例えば、 ```php [ @@ -545,55 +549,55 @@ For example, ] ``` -Note that the same `beforeAction` event is also triggered by [modules](structure-modules.md) -and [controllers](structure-controllers.md). Application objects are the first ones -triggering this event, followed by modules (if any), and finally controllers. If an event handler -sets [[yii\base\ActionEvent::isValid]] to be `false`, all the following events will NOT be triggered. +同じ `beforeAction` イベントが、[モジュール](structure-modules.md) と [コントローラ](structure-controllers.md) +からも発生することに注意してください。 +アプリケーションオブジェクトが最初にこのイベントを発生させ、次に (もし有れば) モジュールが、そして最後にコントローラがこのイベントを発生させます。 +イベントハンドラが [[yii\base\ActionEvent::isValid]] を `false` にセットすると、後続のイベントは発生しません。 ### [[yii\base\Application::EVENT_AFTER_ACTION|EVENT_AFTER_ACTION]] -This event is triggered *after* running every [controller action](structure-controllers.md). -The actual event name is `afterAction`. +このイベントは、[コントローラアクション](structure-controllers.md) が走った *後* に毎回発生します。 +実際のイベント名は `afterAction` です。 -The event parameter is an instance of [[yii\base\ActionEvent]]. Through -the [[yii\base\ActionEvent::result]] property, an event handler may access or modify the action result. -For example, +イベントのパラメータは [[yii\base\ActionEvent]] のインスタンスです。 +[[yii\base\ActionEvent::result]] プロパティを通じて、イベントハンドラはアクションの結果にアクセスしたり、またはアクションの結果を修正したり出来ます。 +例えば、 ```php [ 'on afterAction' => function ($event) { if (some condition) { - // modify $event->result + // $event->result を修正する } else { } }, ] ``` -Note that the same `afterAction` event is also triggered by [modules](structure-modules.md) -and [controllers](structure-controllers.md). These objects trigger this event in the reverse order -as for that of `beforeAction`. That is, controllers are the first objects triggering this event, -followed by modules (if any), and finally applications. +同じ `afterAction` イベントが、[モジュール](structure-modules.md) と [コントローラ](structure-controllers.md) +からも発生することに注意してください。 +これらのオブジェクトは、`beforeAction` の場合とは逆の順でイベントを発生させます。 +すなわち、コントローラオブジェクトが最初にこのイベントを発生させ、次に (もし有れば) モジュールが、そして最後にアプリケーションがこのイベントを発生させます。 -## Application Lifecycle +## アプリケーションのライフサイクル -When an [entry script](structure-entry-scripts.md) is being executed to handle a request, -an application will undergo the following lifecycle: +[エントリスクリプト](structure-entry-scripts.md) が実行されて、リクエストが処理されるとき、 +アプリケーションは次のようなライフサイクルを経ます: -1. The entry script loads the application configuration as an array. -2. The entry script creates a new instance of the application: - * [[yii\base\Application::preInit()|preInit()]] is called, which configures some high priority - application properties, such as [[yii\base\Application::basePath|basePath]]. - * Register the [[yii\base\Application::errorHandler|error handler]]. - * Configure application properties. - * [[yii\base\Application::init()|init()]] is called which further calls - [[yii\base\Application::bootstrap()|bootstrap()]] to run bootstrapping components. -3. The entry script calls [[yii\base\Application::run()]] to run the application: - * Trigger the [[yii\base\Application::EVENT_BEFORE_REQUEST|EVENT_BEFORE_REQUEST]] event. - * Handle the request: resolve the request into a [route](runtime-routing.md) and the associated parameters; - create the module, controller and action objects as specified by the route; and run the action. - * Trigger the [[yii\base\Application::EVENT_AFTER_REQUEST|EVENT_AFTER_REQUEST]] event. - * Send response to the end user. -4. The entry script receives the exit status from the application and completes the request processing. +1. エントリスクリプトがアプリケーションのコンフィギュレーションを配列として読み出す。 +2. エントリスクリプトがアプリケーションの新しいインスタンスを作成する: + * [[yii\base\Application::preInit()|preInit()]] が呼び出されて、[[yii\base\Application::basePath|basePath]] + のような、優先度の高いアプリケーションプロパティを構成する。 + * [[yii\base\Application::errorHandler|エラーハンドラ]] を登録する。 + * アプリケーションのプロパティを構成する。 + * [[yii\base\Application::init()|init()]] が呼ばれ、そこから更に、ブートストラップコンポーネントを + 走らせるために、[[yii\base\Application::bootstrap()|bootstrap()]] が呼ばれる。 +3. エントリスクリプトが [[yii\base\Application::run()]] を呼んで、アプリケーションを走らせる: + * [[yii\base\Application::EVENT_BEFORE_REQUEST|EVENT_BEFORE_REQUEST]] イベントを発生させる。 + * リクエストを処理する: リクエストを [ルート](runtime-routing.md) とそれに結び付くパラメータとして解決する; + ルートによって指定されたモジュール、コントローラ、および、アクションを作成する; そしてアクションを走らせる。 + * [[yii\base\Application::EVENT_AFTER_REQUEST|EVENT_AFTER_REQUEST]] イベントを発生させる。 + * エンドユーザにレスポンスを送信する。 +4. エントリスクリプトがアプリケーションから終了ステータスを受け取り、リクエストの処理を完了する。