Yet Another Framework (Yaf)目次
Yaf_Application クラスはじめにYaf_Application はアプリケーションのブートストラップ機能を提供します。 再利用可能なリソース、共有できるモジュールベースのブートストラップクラス、 そして依存関係のチェックなどです。
クラス概要Yaf_Application
final
class Yaf_Application
{
/* プロパティ */
protected
$config;
protected
$dispatcher;
protected
static
$_app;
protected
$_modules;
protected
$_running;
protected
$_environ;
/* メソッド */
public __construct(mixed
$config , string $envrion = ?)public staticmixed app()
public void bootstrap(Yaf_Bootstrap_Abstract
$bootstrap = ?)public Yaf_Application clearLastError()
public void environ()
public void execute(callable
$entry , string ...$args )public Yaf_Application getAppDirectory()
public Yaf_Config_Abstract getConfig()
public Yaf_Dispatcher getDispatcher()
public string getLastErrorMsg()
public int getLastErrorNo()
public array getModules()
public void run()
public Yaf_Application setAppDirectory(string
$directory )public __destruct()
}プロパティ
Yaf_Bootstrap_Abstract クラスはじめにブートストラップとは、アプリケーションを実行する前の初期設定に使う仕組みのことです。 ユーザーが自前のブートストラップクラスを定義するには、 Yaf_Bootstrap_Abstract を継承します。 ブートストラップクラスで定義したメソッドの中で "_init" で始まるものがすべて、定義した順に Yaf_Application::bootstrap から呼ばれます。 例例1 ブートストラップの例
<?php 上の例の出力は、 たとえば以下のようになります。 string(22) "Bootstrap::_initConfig" string(22) "Bootstrap::_initPlugin" クラス概要Yaf_Bootstrap_Abstract
abstract
class Yaf_Bootstrap_Abstract
{
/* プロパティ */
/* メソッド */
}Yaf_Dispatcher クラスはじめにYaf_Dispatcher の役割は、 リクエスト環境の初期化、やってきたリクエストのルーティング、 そして見つかったアクションへのディスパッチです。 あらゆるレスポンスを取りまとめ、処理が完了した後でそれを返します。 Yaf_Dispatcher はシングルトンパターンを実装しています。 つまり、同時に複数のインスタンスは作れないということです。 そのため、このクラスをレジストリとして使い、 ディスパッチ中に他のオブジェクトから参照させることもできます。 クラス概要Yaf_Dispatcher
final
class Yaf_Dispatcher
{
/* プロパティ */
protected
$_router;
protected
$_view;
protected
$_request;
protected
$_plugins;
protected
static
$_instance;
protected
$_auto_render;
protected
$_return_response;
protected
$_instantly_flush;
protected
$_default_module;
protected
$_default_controller;
protected
$_default_action;
/* メソッド */
public __construct()
public Yaf_Dispatcher autoRender(bool
$flag = ?)public Yaf_Dispatcher catchException(bool
$flag = ?)public bool disableView()
public Yaf_Response_Abstract dispatch(Yaf_Request_Abstract
$request )public Yaf_Dispatcher enableView()
public Yaf_Dispatcher flushInstantly(bool
$flag = ?)public Yaf_Application getApplication()
public string getDefaultAction()
public string getDefaultController()
public string getDefaultModule()
public static Yaf_Dispatcher getInstance()
public Yaf_Request_Abstract getRequest()
public Yaf_Router getRouter()
public Yaf_View_Interface initView(string
$templates_dir , array $options = ?)public Yaf_Dispatcher registerPlugin(Yaf_Plugin_Abstract
$plugin )public Yaf_Dispatcher returnResponse(bool
$flag )public Yaf_Dispatcher setDefaultAction(string
$action )public Yaf_Dispatcher setDefaultController(string
$controller )public Yaf_Dispatcher setDefaultModule(string
$module )public Yaf_Dispatcher setErrorHandler(call
$callback , int $error_types )public Yaf_Dispatcher setRequest(Yaf_Request_Abstract
$request )public Yaf_Dispatcher setView(Yaf_View_Interface
$view )public Yaf_Dispatcher throwException(bool
}$flag = ?)プロパティ
Yaf_Config_Abstract クラスはじめに
クラス概要Yaf_Config_Abstract
abstract
class Yaf_Config_Abstract
{
/* プロパティ */
protected
$_config;
protected
$_readonly;
/* メソッド */
abstract public mixed get(string
$name , mixed $value )abstract public bool readonly()
abstract public Yaf_Config_Abstract set()
abstract public array toArray()
}プロパティ
Yaf_Config_Ini クラスはじめにYaf_Config_Ini を使うと、設定データをおなじみの INI 形式で保存でき、アプリケーションからもオブジェクトのプロパティとして読めるようになります。 INI フォーマットを拡張して、設定データを階層構造で扱えるようにしたり 設定セクション間での継承を設定できるようにしたりしています。 設定データの階層は、キーをピリオド(".")で区切って表します。 セクションの継承を表すには、セクション名の後にコロン(":") を続け、その後に継承元のセクション名を指定します。
クラス概要Yaf_Config_Ini
class Yaf_Config_Ini
extends
Yaf_Config_Abstract
implements
Iterator, ArrayAccess, Countable {
/* プロパティ */
/* メソッド */
public __construct(string
$config_file , string $section = ?)public void count()
public void current()
public void __get(string
$name = ?)public void __isset(string
$name )public void key()
public void next()
public void offsetExists(string
$name )public void offsetGet(string
$name )public void offsetSet(string
$name , string $value )public void offsetUnset(string
$name )public void readonly()
public void rewind()
public void __set(string
$name , mixed $value )public array toArray()
public void valid()
/* 継承したメソッド */
abstract public mixed Yaf_Config_Abstract::get(string
$name , mixed $value )abstract public bool Yaf_Config_Abstract::readonly()
abstract public Yaf_Config_Abstract Yaf_Config_Abstract::set()
abstract public array Yaf_Config_Abstract::toArray()
}プロパティ
例例1 Yaf_Config_Ini の例 この例は、Yaf_Config_Ini で INI ファイルから設定データを読む方法を示すものです。 この例では、運用環境とステージング環境の設定データを用意しています。 ステージング環境の設定は運用環境とほぼ同じなので、 staging セクションは production セクションを継承しています。 今回の場合はどちらがどちらを継承してもあまり変わらないので 逆に production セクションが staging セクションを継承するようにもできます。 しかし、もっと複雑な設定になるとそうはいかないでしょう。 次のような設定データが /path/to/config.ini に格納されているものとします。 ; Production site configuration data [production] webhost = www.example.com database.adapter = pdo_mysql database.params.host = db.example.com database.params.username = dbuser database.params.password = secret database.params.dbname = dbname ; Staging site configuration data inherits from production and ; overrides values as necessary [staging : production] database.params.host = dev.example.com database.params.username = devuser database.params.password = devsecret
<?php 上の例の出力は、 たとえば以下のようになります。 string(15) "dev.example.com" string(6) "dbname" string(7) "devuser Yaf_Config_Simple クラスはじめに
クラス概要Yaf_Config_Simple
class Yaf_Config_Simple
extends
Yaf_Config_Abstract
implements
Iterator, ArrayAccess, Countable {
/* プロパティ */
protected
$_readonly;
/* メソッド */
public __construct(array
$configs , bool $readonly = false)public void count()
public void current()
public void __get(string
$name = ?)public void __isset(string
$name )public void key()
public void next()
public void offsetExists(string
$name )public void offsetGet(string
$name )public void offsetSet(string
$name , string $value )public void offsetUnset(string
$name )public void readonly()
public void rewind()
public void __set(string
$name , string $value )public array toArray()
public void valid()
/* 継承したメソッド */
abstract public mixed Yaf_Config_Abstract::get(string
$name , mixed $value )abstract public bool Yaf_Config_Abstract::readonly()
abstract public Yaf_Config_Abstract Yaf_Config_Abstract::set()
abstract public array Yaf_Config_Abstract::toArray()
}プロパティ
Yaf_Controller_Abstract クラスはじめにYaf_Controller_Abstract は Yaf システムの中心となるクラスです。 MVC は Model-View-Controller の略で、 アプリケーションのロジックと表示のロジックを切り離すためのデザインパターンです。 すべてのカスタムコントローラは Yaf_Controller_Abstract を継承する必要があります。 カスタムコントローラでは __construct を定義できません。そのため、 Yaf_Controller_Abstract ではマジックメソッド Yaf_Controller_Abstract::init を用意しています。 カスタムコントローラで init() メソッドを定義すると、 コントローラのインスタンスを作成するときにそれが呼ばれます。 アクションには引数を持たせることができます。 リクエストが来たときに、もしリクエストのパラメータ ( Yaf_Request_Abstract::getParam を参照ください) に同名の変数があれば、Yaf はアクションのメソッド ( Yaf_Action_Abstract::execute を参照ください) にそれを渡します。
クラス概要Yaf_Controller_Abstract
abstract
class Yaf_Controller_Abstract
{
/* プロパティ */
public
$actions;
protected
$_module;
protected
$_name;
protected
$_request;
protected
$_response;
protected
$_invoke_args;
protected
$_view;
/* メソッド */
final private __construct()
protected bool display(string
$tpl , array $parameters = ?)public bool forward(string
$action , array $paramters = ?)public void getInvokeArg(string
$name )public void getInvokeArgs()
public string getModuleName()
public string getName()
public Yaf_Request_Abstract getRequest()
public Yaf_Response_Abstract getResponse()
public Yaf_View_Interface getView()
public string getViewpath()
public void init()
public void initView(array
$options = ?)public bool redirect(string
$url )protected string render(string
$tpl , array $parameters = ?)public void setViewpath(string
}$view_directory )プロパティ
Yaf_Action_Abstract クラスはじめにアクションは、Yaf の個別のファイルで定義します (Yaf_Controller_Abstract を参照ください)。 アクションメソッドには Yaf_Action_Abstract クラスも使えます。 Yaf から呼び出すためのエントリポイントが必要なので、 抽象メソッド Yaf_Action_Abstract::execute をアクションクラスで実装する必要があります。 クラス概要Yaf_Action_Abstract
class Yaf_Action_Abstract
extends
Yaf_Controller_Abstract
{
/* プロパティ */
protected
$_controller;
/* メソッド */
abstract publicmixed execute(mixed
...$args )publicYaf_Controller_Abstract getController()
public string getControllerName()
/* 継承したメソッド */
protected bool Yaf_Controller_Abstract::display(string
$tpl , array $parameters = ?)public bool Yaf_Controller_Abstract::forward(string
$action , array $paramters = ?)public void Yaf_Controller_Abstract::getInvokeArg(string
$name )public void Yaf_Controller_Abstract::getInvokeArgs()
public string Yaf_Controller_Abstract::getModuleName()
public string Yaf_Controller_Abstract::getName()
public Yaf_Request_Abstract Yaf_Controller_Abstract::getRequest()
public Yaf_Response_Abstract Yaf_Controller_Abstract::getResponse()
public Yaf_View_Interface Yaf_Controller_Abstract::getView()
public string Yaf_Controller_Abstract::getViewpath()
public void Yaf_Controller_Abstract::init()
public void Yaf_Controller_Abstract::initView(array
$options = ?)public bool Yaf_Controller_Abstract::redirect(string
$url )protected string Yaf_Controller_Abstract::render(string
$tpl , array $parameters = ?)public void Yaf_Controller_Abstract::setViewpath(string
}$view_directory )プロパティ
Yaf_View_Interface クラスはじめにYaf では、組み込みのビューエンジン Yaf_View_Simple のかわりにカスタムビューを自作できるようになっています。 その実例は、 Yaf_Dispatcher::setView を参照ください。 クラス概要Yaf_View_Interface
class Yaf_View_Interface
{
/* メソッド */
abstract public bool assign(string
$name , string $value = ?)abstract public bool display(string
$tpl , array $tpl_vars = ?)abstract public void getScriptPath()
abstract public string render(string
$tpl , array $tpl_vars = ?)abstract public void setScriptPath(string
}$template_dir )Yaf_View_Simple クラスはじめにYaf_View_Simple は Yaf の組み込みテンプレートエンジンです。 シンプルながらも高速なテンプレートエンジンで、PHP スクリプトテンプレートだけに対応しています。 クラス概要Yaf_View_Simple
class Yaf_View_Simple
implements
Yaf_View_Interface {
/* プロパティ */
protected
$_tpl_vars;
protected
$_tpl_dir;
/* メソッド */
final public __construct(string
$template_dir , array $options = ?)public bool assign(string
$name , mixed $value = ?)public bool assignRef(string
$name , mixed &$value )public bool clear(string
$name = ?)public bool display(string
$tpl , array $tpl_vars = ?)public string eval(string
$tpl_content , array $tpl_vars = ?)public void __get(string
$name = ?)public string getScriptPath()
public void __isset(string
$name )public string render(string
$tpl , array $tpl_vars = ?)public void __set(string
$name , mixed $value )public bool setScriptPath(string
}$template_dir )プロパティ
Yaf_Loader クラスはじめにYaf_Loader は、 Yaf 用に包括的なオートローディング機能を導入します。 最初に Yaf_Application のインスタンスを取得するときに、 Yaf_Loader はシングルトンのインスタンスを作って それを spl_autoload に登録します。このインスタンスを取得するには Yaf_Loader::getInstance を使います。
Yaf_Loader は、クラスのロードを一度だけ試みます。
失敗した場合の挙動は yaf.use_spl_auload
によって変わります。もしこの設定が On なら
Yaf_Loader::autoload は
デフォルトでは、Yaf_Loader はすべてのライブラリ (クラスを定義したスクリプト) が グローバル ライブラリディレクトリ に格納されているものとみなします。このディレクトリは、 php.ini (yaf.library) で指定します。 Yaf_Loader がクラス (ライブラリ) を探すときに ローカルクラスディレクトリ (application.ini で定義するもので、デフォルトは application.directory . "/library") も検索対象とさせたい場合は、クラスのプレフィックスを Yaf_Loader::registerLocalNameSpace で登録する必要があります。 いくつか例を示します (APPLICATION_PATH は application.directory であるものとします)。 例1 設定の例 // php.ini で、これを設定しているものとします yaf.library = "/global_dir" // application.ini で、これを設定しているものとします application.library = APPLICATION_PATH "/library" 例2 localnamespace の登録
<?php 例3 クラスのロード class Foo_Bar_Test => // APPLICATION_PATH/library/Foo/Bar/Test.php class GLO_Name => // /global_dir/Glo/Name.php class BarNon_Test // /global_dir/Barnon/Test.php 例4 名前空間つきのクラスのロード class \Foo\Bar\Dummy => // APPLICATION_PATH/library/Foo/Bar/Dummy.php class \FooBar\Bar\Dummy => // /global_dir/FooBar/Bar/Dummy.php すべてのフォルダの先頭が大文字になっているのが気になる場合は、php.ini で yaf.lowcase_path = On とすれば小文字にすることもできます。 Yaf_Loader は MVC クラスを読み込むようにも作られています。 次のような規約に従います。 例5 MVC クラスのロード Controller Classes => // APPLICATION_PATH/controllers/ Model Classes => // APPLICATION_PATH/models/ Plugin Classes => // APPLICATION_PATH/plugins/ 例6 MVC クラスかどうかの区別 Controller Classes => // ***Controller Model Classes => // ***Model Plugin Classes => // ***Plugin 例7 MVC のロード class IndexController // APPLICATION_PATH/controllers/Index.php class DataModel => // APPLICATION_PATH/models/Data.php class DummyPlugin => // APPLICATION_PATH/plugins/Dummy.php class A_B_TestModel => // APPLICATION_PATH/models/A/B/Test.php また、ディレクトリは yaf.lowcase_path の影響を受けます。 クラス概要Yaf_Loader
class Yaf_Loader
{
/* プロパティ */
protected
$_local_ns;
protected
$_library;
protected
$_global_library;
static
$_instance;
/* メソッド */
private __construct()
public void autoload()
public void clearLocalNamespace()
public static void getInstance()
public Yaf_Loader getLibraryPath(bool
$is_global = false )public void getLocalNamespace()
public string getNamespacePath(string
$namespaces )public array getNamespaces()
public static void import()
public void isLocalName()
public void registerLocalNamespace(mixed
$prefix )public bool registerNamespace(stringarray
$namespaces , string $path = ?)public Yaf_Loader setLibraryPath(string
}$directory , bool $is_global = false )プロパティ
Yaf_Plugin_Abstract クラスはじめにプラグインを使えば、フレームワークの拡張やカスタマイズを簡単に行えます。 プラグインは、クラスとして定義します。 実際のクラスの定義はコンポーネントによって異なります。 このインターフェイスを実装する必要があるかもしれませんが、 プラグイン自体がクラスであるという事実は変わりません。 プラグインを Yaf にロードするには Yaf_Dispatcher::registerPlugin を使います。登録を済ませれば、このインターフェイスに従って実装した すべてのメソッドが適切な場面で呼ばれます。 例例1 プラグインの例
<?php 上の例の出力は、 たとえば以下のようになります。 string(13) "routerStartup" string(14) "routerShutdown" string(19) "dispatchLoopStartup" string(11) "preDispatch" string(12) "postDispatch" string(20) "dispatchLoopShutdown" クラス概要Yaf_Plugin_Abstract
class Yaf_Plugin_Abstract
{
/* メソッド */
public void dispatchLoopShutdown(Yaf_Request_Abstract
$request , Yaf_Response_Abstract $response )public void dispatchLoopStartup(Yaf_Request_Abstract
$request , Yaf_Response_Abstract $response )public void postDispatch(Yaf_Request_Abstract
$request , Yaf_Response_Abstract $response )public void preDispatch(Yaf_Request_Abstract
$request , Yaf_Response_Abstract $response )public void preResponse(Yaf_Request_Abstract
$request , Yaf_Response_Abstract $response )public void routerShutdown(Yaf_Request_Abstract
$request , Yaf_Response_Abstract $response )public void routerStartup(Yaf_Request_Abstract
}$request , Yaf_Response_Abstract $response )Yaf_Registry クラスはじめにYaf_Registry のすべてのメソッドはstaticメソッドとして宣言されており、 どこからでもアクセスできます。これを使えば、コードのどこからでも必要に応じて 任意のデータを保存したり取得したりすることができます。 クラス概要Yaf_Registry
class Yaf_Registry
{
/* プロパティ */
static
$_instance;
protected
$_entries;
/* メソッド */
private __construct()
public static void del(string
$name )public static mixed get(string
$name )public static bool has(string
$name )public static bool set(string
}$name , string $value )プロパティ
Yaf_Request_Abstract クラスはじめに
クラス概要Yaf_Request_Abstract
class Yaf_Request_Abstract
{
/* 定数 */
const
string
Yaf_Request_Abstract::SCHEME_HTTP = http;
const
string
Yaf_Request_Abstract::SCHEME_HTTPS = https;
/* プロパティ */
public
$module;
public
$controller;
public
$action;
public
$method;
protected
$params;
protected
$language;
protected
$_exception;
protected
$_base_uri;
protected
$uri;
protected
$dispatched;
protected
$routed;
/* メソッド */
public bool clearParams()
public void getActionName()
public void getBaseUri()
public void getControllerName()
public void getEnv(string
$name , string $default = ?)public void getException()
public void getLanguage()
public string getMethod()
public void getModuleName()
public mixed getParam(string
$name , string $default = ?)public array getParams()
public void getRequestUri()
public void getServer(string
$name , string $default = ?)public bool isCli()
public bool isDispatched()
public bool isGet()
public bool isHead()
public bool isOptions()
public bool isPost()
public bool isPut()
public bool isRouted()
public bool isXmlHttpRequest()
public void setActionName(string
$action , bool $format_name = true)public bool setBaseUri(string
$uir )public void setControllerName(string
$controller , bool $format_name = true)public void setDispatched()
public void setModuleName(string
$module , bool $format_name = true)public bool setParam(string
$name , string $value = ?)public void setRequestUri(string
$uir )public void setRouted(string
}$flag = ?)プロパティ
定義済み定数
Yaf_Request_Http クラスはじめにクライアントからのあらゆるリクエストは、 Yaf_Request_Http として初期化されます。 URI のクエリ文字列や POST パラメータなどの情報は、このクラスのメソッド経由で取得できます。
クラス概要Yaf_Request_Http
class Yaf_Request_Http
extends
Yaf_Request_Abstract
{
/* プロパティ */
/* メソッド */
public __construct(string
$request_uri = ?, string $base_uri = ?)public mixed get(string
$name , string $default = ?)public mixed getCookie(string
$name , string $default = ?)public void getFiles()
public mixed getPost(string
$name , string $default = ?)public mixed getQuery(string
$name , string $default = ?)public mixed getRaw()
public void getRequest()
public bool isXmlHttpRequest()
/* 継承したメソッド */
public bool Yaf_Request_Abstract::clearParams()
public void Yaf_Request_Abstract::getActionName()
public void Yaf_Request_Abstract::getBaseUri()
public void Yaf_Request_Abstract::getControllerName()
public void Yaf_Request_Abstract::getEnv(string
$name , string $default = ?)public void Yaf_Request_Abstract::getException()
public void Yaf_Request_Abstract::getLanguage()
public string Yaf_Request_Abstract::getMethod()
public void Yaf_Request_Abstract::getModuleName()
public mixed Yaf_Request_Abstract::getParam(string
$name , string $default = ?)public array Yaf_Request_Abstract::getParams()
public void Yaf_Request_Abstract::getRequestUri()
public void Yaf_Request_Abstract::getServer(string
$name , string $default = ?)public bool Yaf_Request_Abstract::isCli()
public bool Yaf_Request_Abstract::isDispatched()
public bool Yaf_Request_Abstract::isGet()
public bool Yaf_Request_Abstract::isHead()
public bool Yaf_Request_Abstract::isOptions()
public bool Yaf_Request_Abstract::isPost()
public bool Yaf_Request_Abstract::isPut()
public bool Yaf_Request_Abstract::isRouted()
public bool Yaf_Request_Abstract::isXmlHttpRequest()
public void Yaf_Request_Abstract::setActionName(string
$action , bool $format_name = true)public bool Yaf_Request_Abstract::setBaseUri(string
$uir )public void Yaf_Request_Abstract::setControllerName(string
$controller , bool $format_name = true)public void Yaf_Request_Abstract::setDispatched()
public void Yaf_Request_Abstract::setModuleName(string
$module , bool $format_name = true)public bool Yaf_Request_Abstract::setParam(string
$name , string $value = ?)public void Yaf_Request_Abstract::setRequestUri(string
$uir )public void Yaf_Request_Abstract::setRouted(string
}$flag = ?)プロパティ
Yaf_Request_Simple クラスはじめにYaf_Request_Simple は、 テスト用に使うためのクラスです。 つまり、特定のリクエストを CLI モードでシミュレートしたりするときに使います。 クラス概要Yaf_Request_Simple
class Yaf_Request_Simple
extends
Yaf_Request_Abstract
{
/* 定数 */
const
string
Yaf_Request_Simple::SCHEME_HTTP = http;
const
string
Yaf_Request_Simple::SCHEME_HTTPS = https;
/* プロパティ */
/* メソッド */
public __construct(
string $method = ?,string $module = ?,string $controller = ?,string $action = ?,array $params = ?) public void get()
public void getCookie()
public void getFiles()
public void getPost()
public void getQuery()
public void getRequest()
public void isXmlHttpRequest()
/* 継承したメソッド */
public bool Yaf_Request_Abstract::clearParams()
public void Yaf_Request_Abstract::getActionName()
public void Yaf_Request_Abstract::getBaseUri()
public void Yaf_Request_Abstract::getControllerName()
public void Yaf_Request_Abstract::getEnv(string
$name , string $default = ?)public void Yaf_Request_Abstract::getException()
public void Yaf_Request_Abstract::getLanguage()
public string Yaf_Request_Abstract::getMethod()
public void Yaf_Request_Abstract::getModuleName()
public mixed Yaf_Request_Abstract::getParam(string
$name , string $default = ?)public array Yaf_Request_Abstract::getParams()
public void Yaf_Request_Abstract::getRequestUri()
public void Yaf_Request_Abstract::getServer(string
$name , string $default = ?)public bool Yaf_Request_Abstract::isCli()
public bool Yaf_Request_Abstract::isDispatched()
public bool Yaf_Request_Abstract::isGet()
public bool Yaf_Request_Abstract::isHead()
public bool Yaf_Request_Abstract::isOptions()
public bool Yaf_Request_Abstract::isPost()
public bool Yaf_Request_Abstract::isPut()
public bool Yaf_Request_Abstract::isRouted()
public bool Yaf_Request_Abstract::isXmlHttpRequest()
public void Yaf_Request_Abstract::setActionName(string
$action , bool $format_name = true)public bool Yaf_Request_Abstract::setBaseUri(string
$uir )public void Yaf_Request_Abstract::setControllerName(string
$controller , bool $format_name = true)public void Yaf_Request_Abstract::setDispatched()
public void Yaf_Request_Abstract::setModuleName(string
$module , bool $format_name = true)public bool Yaf_Request_Abstract::setParam(string
$name , string $value = ?)public void Yaf_Request_Abstract::setRequestUri(string
$uir )public void Yaf_Request_Abstract::setRouted(string
}$flag = ?)プロパティ
定義済み定数
Yaf_Response_Abstract クラスはじめに
クラス概要Yaf_Response_Abstract
class Yaf_Response_Abstract
{
/* 定数 */
const
string
Yaf_Response_Abstract::DEFAULT_BODY = "content";
/* プロパティ */
protected
$_header;
protected
$_body;
protected
$_sendheader;
/* メソッド */
public __construct()
public bool appendBody(string
$content , string $key = ?)public bool clearBody(string
$key = ?)public void clearHeaders()
public mixed getBody(string
$key = ?)public void getHeader()
public bool prependBody(string
$content , string $key = ?)public void response()
protected void setAllHeaders()
public bool setBody(string
$content , string $key = ?)public bool setHeader(string
$name , string $value , bool $replace = ?)public bool setRedirect(string
$url )private string __toString()
public __destruct()
}プロパティ
Yaf_Route_Interface クラスはじめにYaf_Route_Interface を使うと、開発者がカスタムルートを定義できるようになります。 クラス概要Yaf_Route_Interface
class Yaf_Route_Interface
{
/* メソッド */
abstract public string assemble(array
$info , array $query = ?)abstract public bool route(Yaf_Request_Abstract
}$request )Yaf_Route_Map クラスはじめにYaf_Route_Map は標準で組み込まれているルートです。 単純に URI エンドポイント (URI の中で、ベース URL の後に続く部分。 Yaf_Request_Abstract::setBaseUri を参照ください) をコントローラ名やアクション名に変換します (どちらになるかは Yaf_Route_Map::__construct に渡すパラメータで決まります)。 その規則は次のとおりです。 A => controller A. A/B/C => controller A_B_C. A/B/C/D/E => controller A_B_C_D_E. Yaf_Route_Map::__construct の二番目のパラメータを指定すると、 URI の中でデリミタより前の部分だけを使ってルーティングを行います。 デリミタ以降の部分は、ルーティングリクエストのパラメータとして使います ( Yaf_Route_Map::__construct のサンプルを参照ください)。 クラス概要Yaf_Route_Map
class Yaf_Route_Map
implements
Yaf_Route_Interface {
/* プロパティ */
protected
$_ctl_router;
protected
$_delimiter;
/* メソッド */
public __construct(string
$controller_prefer = false , string $delimiter = "")public string assemble(array
$info , array $query = ?)public bool route(Yaf_Request_Abstract
}$request )プロパティ
Yaf_Route_Regex クラスはじめにYaf_Route_Regex は、 Yaf の組み込みのルートのなかでも一番柔軟性の高いものです。 クラス概要Yaf_Route_Regex
class Yaf_Route_Regex
extends
Yaf_Route_Interface
implements
Yaf_Route_Interface {
/* プロパティ */
protected
$_route;
protected
$_default;
protected
$_maps;
protected
$_verify;
/* メソッド */
public __construct(
string $match ,array $route ,array $map = ?,array $verify = ?,string $reverse = ?) public stringnull assemble(array
$info , array $query = ?)public bool route(Yaf_Request_Abstract
$request )/* 継承したメソッド */
abstract public string Yaf_Route_Interface::assemble(array
$info , array $query = ?)abstract public bool Yaf_Route_Interface::route(Yaf_Request_Abstract
}$request )プロパティ
Yaf_Route_Rewrite クラスはじめに使いかたについては、 Yaf_Route_Rewrite::__construct のサンプルを参照ください。 クラス概要Yaf_Route_Rewrite
class Yaf_Route_Rewrite
extends
Yaf_Route_Interface
implements
Yaf_Route_Interface {
/* プロパティ */
protected
$_route;
protected
$_default;
protected
$_verify;
/* メソッド */
public __construct(string
$match , array $route , array $verify = ?)public string assemble(array
$info , array $query = ?)public bool route(Yaf_Request_Abstract
$request )/* 継承したメソッド */
abstract public string Yaf_Route_Interface::assemble(array
$info , array $query = ?)abstract public bool Yaf_Route_Interface::route(Yaf_Request_Abstract
}$request )プロパティ
Yaf_Router クラスはじめにYaf_Router は、フレームワークの標準のルーターです。 ルーティングとは、URI エンドポイント (URI の中で、ベース URL の後に続く部分。 Yaf_Request_Abstract::setBaseUri を参照ください) を受け取ってそこからパラメータを抽出し、 リクエストを受け取るモジュールやコントローラそしてアクションを判断する処理のことです。 モジュール、コントローラ、アクション、そしてその他のパラメータは Yaf_Request_Abstract オブジェクトにまとめられ、 そして Yaf_Dispatcher で処理します。 ルーティングが行われるのは一度だけで、リクエストを最初に受け取ってから 最初のコントローラにディスパッチする前に行われます。 Yaf_Router は、mod_rewrite 風の機能を PHP を使って実現できるような設計になっています。 Ruby on Rails のルーティング方式を参考にしており、 ウェブサーバーの URL リライト機能に関する事前知識は不要です。 Apache の場合は、次のような mod_rewrite ルールを書けば使えます。 例1 Apache 用のリライトルール RewriteEngine on RewriteRule !\.(js|ico|gif|jpg|png|css|html)$ index.php 例2 Apache 用のリライトルール RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] 例3 Lighttpd 用のリライトルール url.rewrite-once = ( ".*\?(.*)$" => "/index.php?$1", ".*\.(js|ico|gif|jpg|png|css|html)$" => "$0", "" => "/index.php" ) 例4 Nginx 用のリライトルール server { listen ****; server_name yourdomain.com; root document_root; index index.php index.html; if (!-e $request_filename) { rewrite ^/(.*) /index.php/$1 last; } } デフォルトのルートYaf_Router には設定済みのデフォルトルート Yaf_Route_Static が用意されており、これは controller/action 形式の URI にマッチします。 さらに、モジュール名を最初のパス要素として指定できます。この場合の URI は module/controller/action 形式になります。 また、追加のパラメータを URI に追記できるようになっています。つまり controller/action/var1/value1/var2/value2 といった形式です。
ルートのマッチングの例を示します。 例5 Yaf_Route_Static のデフォルトルート // このように設定しているものとします $conf = array( "application" => array( "modules" => "Index,Blog", ), ); コントローラのみ http://example/news controller == news アクションのみ (php.ini で yaf.action_prefer=1 とした場合) action == news モジュール名として無効な場合はコントローラ名とみなします http://example/foo controller == foo モジュール + コントローラ http://example/blog/archive module == blog controller == archive モジュール + コントローラ + アクション http://example/blog/archive/list module == blog controller == archive action == list モジュール + コントローラ + アクション + パラメータ http://example/blog/archive/list/sort/alpha/date/desc module == blog controller == archive action == list sort == alpha date == desc クラス概要Yaf_Router
class Yaf_Router
{
/* プロパティ */
protected
$_routes;
protected
$_current;
/* メソッド */
public __construct()
public bool addConfig(Yaf_Config_Abstract
$config )public bool addRoute(string
$name , Yaf_Route_Abstract $route )public string getCurrentRoute()
public Yaf_Route_Interface getRoute(string
$name )public mixed getRoutes()
public bool route(Yaf_Request_Abstract
}$request )プロパティ
Yaf_Route_Simple クラスはじめにYaf_Route_Simple は、クエリ文字列を見てルート情報を取得します。 Yaf_Route_Simple に対して必要な設定は、 $_GET のどのキーがモジュールでどのキーがコントローラ、 そしてどのキーがアクションなのかを指定することです。
Yaf_Route_Simple::route は常に クラス概要Yaf_Route_Simple
class Yaf_Route_Simple
implements
Yaf_Route_Interface {
/* プロパティ */
protected
$controller;
protected
$module;
protected
$action;
/* メソッド */
public __construct(string
$module_name , string $controller_name , string $action_name )public string assemble(array
$info , array $query = ?)public bool route(Yaf_Request_Abstract
}$request )プロパティ
Yaf_Route_Static クラスはじめにデフォルトでは、Yaf_Router が持っているルートは Yaf_Route_Static だけです。 Yaf_Route_Static は、 要件の 80% を満たせるように作られています。 Yaf_Route_Static のインスタンスを作る必要はありません。 また、Yaf_Router のルートスタックに追加する必要もありません。 というのもこのクラスは常に Yaf_Router のルートスタックに含まれており、最後に呼ばれるようになっているからです。 クラス概要Yaf_Route_Static
class Yaf_Route_Static
implements
Yaf_Router {
/* メソッド */
public string assemble(array
$info , array $query = ?)public void match(string
$uri )public bool route(Yaf_Request_Abstract
}$request )Yaf_Route_Supervar クラスはじめに
クラス概要Yaf_Route_Supervar
class Yaf_Route_Supervar
implements
Yaf_Route_Interface {
/* プロパティ */
protected
$_var_name;
/* メソッド */
public __construct(string
$supervar_name )public string assemble(array
$info , array $query = ?)public bool route(Yaf_Request_Abstract
}$request )プロパティ
Yaf_Session クラスはじめに
クラス概要Yaf_Session
class Yaf_Session
implements
Iterator, ArrayAccess, Countable {
/* プロパティ */
protected
static
$_instance;
protected
$_session;
protected
$_started;
/* メソッド */
private __construct()
public void count()
public void current()
public void del(string
$name )public void __get(string
$name )public static void getInstance()
public void has(string
$name )public void __isset(string
$name )public void key()
public void next()
public void offsetExists(string
$name )public void offsetGet(string
$name )public void offsetSet(string
$name , string $value )public void offsetUnset(string
$name )public void rewind()
public void __set(string
$name , string $value )public void start()
public void __unset(string
$name )public void valid()
}プロパティ
Yaf_Exception クラスはじめに
クラス概要Yaf_Exception
class Yaf_Exception
extends
Exception
{
/* 継承したプロパティ */
protected
string
$message = "";
private
string
$string = "";
protected
int
$code;
protected
string
$file = "";
protected
int
$line;
private
array
$trace = [];
private
Throwablenull
$previous = null;
/* メソッド */
public __construct()
public void getPrevious()
/* 継承したメソッド */
final public string Exception::getMessage()
final public Throwablenull Exception::getPrevious()
final public int Exception::getCode()
final public string Exception::getFile()
final public int Exception::getLine()
final public array Exception::getTrace()
final public string Exception::getTraceAsString()
public string Exception::__toString()
private void Exception::__clone()
}Yaf_Exception_TypeError クラスはじめに
クラス概要Yaf_Exception_TypeError
class Yaf_Exception_TypeError
extends
Yaf_Exception
{
/* プロパティ */
/* メソッド */
/* 継承したメソッド */
public void Yaf_Exception::getPrevious()
}Yaf_Exception_StartupError クラスはじめに
クラス概要Yaf_Exception_StartupError
class Yaf_Exception_StartupError
extends
Yaf_Exception
{
/* プロパティ */
/* メソッド */
/* 継承したメソッド */
public void Yaf_Exception::getPrevious()
}Yaf_Exception_DispatchFailed クラスはじめに
クラス概要Yaf_Exception_DispatchFailed
class Yaf_Exception_DispatchFailed
extends
Yaf_Exception
{
/* プロパティ */
/* メソッド */
/* 継承したメソッド */
public void Yaf_Exception::getPrevious()
}Yaf_Exception_RouterFailed クラスはじめに
クラス概要Yaf_Exception_RouterFailed
class Yaf_Exception_RouterFailed
extends
Yaf_Exception
{
/* プロパティ */
/* メソッド */
/* 継承したメソッド */
public void Yaf_Exception::getPrevious()
}Yaf_Exception_LoadFailed クラスはじめに
クラス概要Yaf_Exception_LoadFailed
class Yaf_Exception_LoadFailed
extends
Yaf_Exception
{
/* プロパティ */
/* メソッド */
/* 継承したメソッド */
public void Yaf_Exception::getPrevious()
}Yaf_Exception_LoadFailed_Module クラスはじめに
クラス概要Yaf_Exception_LoadFailed_Module
class Yaf_Exception_LoadFailed_Module
extends
Yaf_Exception_LoadFailed
{
/* プロパティ */
/* メソッド */
/* 継承したメソッド */
public void Yaf_Exception::getPrevious()
}Yaf_Exception_LoadFailed_Controller クラスはじめに
クラス概要Yaf_Exception_LoadFailed_Controller
class Yaf_Exception_LoadFailed_Controller
extends
Yaf_Exception_LoadFailed
{
/* プロパティ */
/* メソッド */
/* 継承したメソッド */
public void Yaf_Exception::getPrevious()
}Yaf_Exception_LoadFailed_Action クラスはじめに
クラス概要Yaf_Exception_LoadFailed_Action
class Yaf_Exception_LoadFailed_Action
extends
Yaf_Exception_LoadFailed
{
/* プロパティ */
/* メソッド */
/* 継承したメソッド */
public void Yaf_Exception::getPrevious()
}Yaf_Exception_LoadFailed_View クラスはじめに
クラス概要Yaf_Exception_LoadFailed_View
class Yaf_Exception_LoadFailed_View
extends
Yaf_Exception_LoadFailed
{
/* プロパティ */
/* メソッド */
/* 継承したメソッド */
public void Yaf_Exception::getPrevious()
} |