Yaf

Yaf (Yet Another Framework, C로 만든 PHP 웹 프레임워크)

PHP로 웹 애플리케이션을 만들되, 프레임워크 오버헤드를 최소화하고 싶을 때 쓰는 확장이에요. Yaf는 일반적인 PHP 프레임워크와 달리 C로 작성돼 확장으로 컴파일되는 프레임워크예요. 프레임워크 클래스, 오토로더, 라우터, 디스패치 루프가 모두 컴파일된 코드로 동작해서, 요청당 프레임워크 오버헤드가 밀리초가 아니라 마이크로초 단위예요.

출처: Yet Another Framework

본문

소개

Yaf(Yet Another Framework) 확장은 웹 애플리케이션을 개발하는 데 쓰는 PHP 프레임워크예요.

일반적인 PHP 프레임워크와 달리 Yaf는 C로 작성되어 확장으로 컴파일돼요. 프레임워크 클래스, 오토로더, 라우터, 디스패치 루프가 모두 컴파일된 코드에서 동작하므로, 요청당 프레임워크 오버헤드가 밀리초가 아닌 마이크로초 단위이고, 로드할 프레임워크 PHP 파일이 없어요. 부트스트랩 비용이 중요한 고트래픽 애플리케이션과, 각 요청마다 깨끗한 디스패치 사이클이 필요한 Swoole 같은 장수(long-lived) 서비스 런타임에 맞게 설계됐어요.

Yaf는 단일 진입 스크립트, 환경 섹션이 있는 설정 파일, 부트스트랩 훅, 7개의 디스패치 훅을 가진 플러그인 시스템, 6개의 내장 라우트 타입, PSR-0 스타일 오토로더(Yaf_Loader), 가벼운 PHP 템플릿 뷰(Yaf_View_Simple)를 갖춘 전형적인 MVC 아키텍처를 구현해요.

간단한 Yaf 벤치마크는 Yaf Performance에서, 빠른 시작 가이드는 Tutorials 섹션에서 볼 수 있어요.

Note: Yaf는 PHP 7.0 이상이 필요해요(소스 저장소의 master 브랜치 기준). php5 브랜치는 PHP 5.2 이상을 지원해요.

클래스 참조

Yaf_Application — The Yaf_Application class

  • Yaf_Application::app — Retrieve an Application instance
  • Yaf_Application::bootstrap — Call bootstrap
  • Yaf_Application::clearLastError — Clear the last error info
  • Yaf_Application::__construct — Yaf_Application constructor
  • Yaf_Application::environ — Retrieve the environment
  • Yaf_Application::execute — Execute a callback
  • Yaf_Application::getAppDirectory — Get the application directory
  • Yaf_Application::getConfig — Retrieve the config instance
  • Yaf_Application::getDispatcher — Get Yaf_Dispatcher instance
  • Yaf_Application::getLastErrorMsg — Get message of the last occurred error
  • Yaf_Application::getLastErrorNo — Get code of the last occurred error
  • Yaf_Application::getModules — Get defined module names
  • Yaf_Application::run — Start Yaf_Application
  • Yaf_Application::setAppDirectory — Change the application directory

Yaf_Bootstrap_Abstract — The Yaf_Bootstrap_Abstract class

Yaf_Dispatcher — The Yaf_Dispatcher class

  • Yaf_Dispatcher::autoRender — Switch on/off autorendering
  • Yaf_Dispatcher::catchException — Switch on/off exception catching
  • Yaf_Dispatcher::__construct — Yaf_Dispatcher constructor
  • Yaf_Dispatcher::disableView — Disable view rendering
  • Yaf_Dispatcher::dispatch — Dispatch a request
  • Yaf_Dispatcher::enableView — Enable view rendering
  • Yaf_Dispatcher::flushInstantly — Switch on/off the instant flushing
  • Yaf_Dispatcher::getApplication — Retrieve the application
  • Yaf_Dispatcher::getDefaultAction — Retrieve the default action name
  • Yaf_Dispatcher::getDefaultController — Retrieve the default controller name
  • Yaf_Dispatcher::getDefaultModule — Retrieve the default module name
  • Yaf_Dispatcher::getInstance — Retrieve the dispatcher instance
  • Yaf_Dispatcher::getRequest — Retrieve the request instance
  • Yaf_Dispatcher::getResponse — Get the response object
  • Yaf_Dispatcher::getRouter — Retrieve router instance
  • Yaf_Dispatcher::initView — Initialize view and return it
  • Yaf_Dispatcher::registerPlugin — Register a plugin
  • Yaf_Dispatcher::returnResponse — Switch on/off returning the response
  • Yaf_Dispatcher::setDefaultAction — Change default action name
  • Yaf_Dispatcher::setDefaultController — Change default controller name
  • Yaf_Dispatcher::setDefaultModule — Change default module name
  • Yaf_Dispatcher::setErrorHandler — Set error handler
  • Yaf_Dispatcher::setRequest — Set the request object
  • Yaf_Dispatcher::setResponse — Set the response object
  • Yaf_Dispatcher::setView — Set a custom view engine
  • Yaf_Dispatcher::throwException — Switch on/off exception throwing

Yaf_Config_Abstract — The Yaf_Config_Abstract class

  • Yaf_Config_Abstract::get — Retrieve a configuration value
  • Yaf_Config_Abstract::readonly — Check if configuration is read-only
  • Yaf_Config_Abstract::set — Set a configuration value
  • Yaf_Config_Abstract::toArray — Export configuration as array

Yaf_Config_Ini — The Yaf_Config_Ini class

  • Yaf_Config_Ini::__construct — Constructor of Yaf_Config_Ini
  • Yaf_Config_Ini::count — Count configuration entries
  • Yaf_Config_Ini::current — Get current entry value
  • Yaf_Config_Ini::get — Retrieve a configuration value
  • Yaf_Config_Ini::__isset — Check if a key exists
  • Yaf_Config_Ini::key — Get current entry key
  • Yaf_Config_Ini::next — Advance to next entry
  • Yaf_Config_Ini::offsetExists — Check if a key exists (ArrayAccess)
  • Yaf_Config_Ini::offsetGet — Get a value (ArrayAccess)
  • Yaf_Config_Ini::offsetSet — Set a configuration value (ArrayAccess)
  • Yaf_Config_Ini::offsetUnset — Remove a key (ArrayAccess)
  • Yaf_Config_Ini::readonly — Check if configuration is read-only
  • Yaf_Config_Ini::rewind — Reset iterator to first entry
  • Yaf_Config_Ini::set — Set a configuration value
  • Yaf_Config_Ini::toArray — Export configuration as array
  • Yaf_Config_Ini::valid — Check if current position is valid

Yaf_Config_Simple — The Yaf_Config_Simple class

  • Yaf_Config_Simple::__construct — Constructor of Yaf_Config_Simple
  • Yaf_Config_Simple::count — Count configuration entries
  • Yaf_Config_Simple::current — Get current entry value
  • Yaf_Config_Simple::get — Retrieve a configuration value
  • Yaf_Config_Simple::__isset — Check if a key exists
  • Yaf_Config_Simple::key — Get current entry key
  • Yaf_Config_Simple::next — Advance to next entry
  • Yaf_Config_Simple::offsetExists — Check if a key exists (ArrayAccess)
  • Yaf_Config_Simple::offsetGet — Get a value (ArrayAccess)
  • Yaf_Config_Simple::offsetSet — Set a configuration value (ArrayAccess)
  • Yaf_Config_Simple::offsetUnset — Remove a key (ArrayAccess)
  • Yaf_Config_Simple::readonly — Check if configuration is read-only
  • Yaf_Config_Simple::rewind — Reset iterator to first entry
  • Yaf_Config_Simple::set — Set a configuration value
  • Yaf_Config_Simple::toArray — Export configuration as array
  • Yaf_Config_Simple::valid — Check if current position is valid

Yaf_Controller_Abstract — The Yaf_Controller_Abstract class

  • Yaf_Controller_Abstract::__construct — Constructor of Yaf_Controller_Abstract
  • Yaf_Controller_Abstract::display — Render and display a view
  • Yaf_Controller_Abstract::forward — Forward the current request to another action
  • Yaf_Controller_Abstract::getInvokeArg — Retrieve one action invocation argument
  • Yaf_Controller_Abstract::getInvokeArgs — Retrieve all action invocation arguments
  • Yaf_Controller_Abstract::getModuleName — Get module name
  • Yaf_Controller_Abstract::getName — Get controller name
  • Yaf_Controller_Abstract::getRequest — Retrieve current request object
  • Yaf_Controller_Abstract::getResponse — Retrieve current response object
  • Yaf_Controller_Abstract::getView — Retrieve the view engine
  • Yaf_Controller_Abstract::getViewpath — Get the view path
  • Yaf_Controller_Abstract::init — Controller initializer
  • Yaf_Controller_Abstract::initView — Initialize the view and return it
  • Yaf_Controller_Abstract::redirect — Redirect to a URL
  • Yaf_Controller_Abstract::render — Render view template
  • Yaf_Controller_Abstract::setViewpath — Set the view path

Yaf_Action_Abstract — The Yaf_Action_Abstract class

  • Yaf_Action_Abstract::execute — Action entry point
  • Yaf_Action_Abstract::getController — Retrieve controller object
  • Yaf_Action_Abstract::getControllerName — Get controller name

Yaf_View_Interface — The Yaf_View_Interface class

  • Yaf_View_Interface::assign — Assign a variable to the view
  • Yaf_View_Interface::display — Render and emit a template
  • Yaf_View_Interface::getScriptPath — Get the template directory
  • Yaf_View_Interface::render — Render a template
  • Yaf_View_Interface::setScriptPath — Set the template directory

Yaf_View_Simple — The Yaf_View_Simple class

  • Yaf_View_Simple::assign — Assign a variable to the view
  • Yaf_View_Simple::assignRef — Alias of Yaf_View_Simple::assign
  • Yaf_View_Simple::clear — Remove an assigned variable
  • Yaf_View_Simple::__construct — Constructor of Yaf_View_Simple
  • Yaf_View_Simple::display — Render and store a template in the response
  • Yaf_View_Simple::eval — Render a template string
  • Yaf_View_Simple::get — Get an assigned variable
  • Yaf_View_Simple::getScriptPath — Get the template directory
  • Yaf_View_Simple::__isset — Check whether a variable is assigned
  • Yaf_View_Simple::render — Render a template
  • Yaf_View_Simple::__set — Assign a variable via property write
  • Yaf_View_Simple::setScriptPath — Set the template directory

Yaf_Loader — The Yaf_Loader class

  • Yaf_Loader::autoload — Autoload a class
  • Yaf_Loader::clearLocalNamespace — Clear registered namespaces
  • Yaf_Loader::__construct — The constructor is private
  • Yaf_Loader::getInstance — Retrieve the Yaf_Loader instance
  • Yaf_Loader::getLibraryPath — Retrieve the library path
  • Yaf_Loader::getLocalNamespace — Retrieve registered namespaces
  • Yaf_Loader::getNamespacePath — Retrieve the library path of a class
  • Yaf_Loader::getNamespaces — Alias of getLocalNamespace
  • Yaf_Loader::import — Load a PHP script
  • Yaf_Loader::isLocalName — Whether a class is local
  • Yaf_Loader::registerLocalNamespace — Register local namespace
  • Yaf_Loader::registerNamespace — Alias of registerLocalNamespace
  • Yaf_Loader::setLibraryPath — Change the library path

Yaf_Plugin_Abstract — The Yaf_Plugin_Abstract class

  • Yaf_Plugin_Abstract::dispatchLoopShutdown — Hook after dispatch loop
  • Yaf_Plugin_Abstract::dispatchLoopStartup — Hook before dispatch loop
  • Yaf_Plugin_Abstract::postDispatch — Hook after each dispatch
  • Yaf_Plugin_Abstract::preDispatch — Hook before each dispatch
  • Yaf_Plugin_Abstract::preResponse — Hook before the response is sent
  • Yaf_Plugin_Abstract::routerShutdown — Hook after routing
  • Yaf_Plugin_Abstract::routerStartup — Hook before routing

Yaf_Registry — The Yaf_Registry class

  • Yaf_Registry::__construct — Constructor of Yaf_Registry
  • Yaf_Registry::del — Remove an item from registry
  • Yaf_Registry::get — Retrieve an item from registry
  • Yaf_Registry::has — Check whether an item exists
  • Yaf_Registry::set — Add an item into registry

Yaf_Request_Abstract — The Yaf_Request_Abstract class

  • Yaf_Request_Abstract::clearParams — Remove all parameters
  • Yaf_Request_Abstract::get — Retrieve a variable from the request
  • Yaf_Request_Abstract::getActionName — Retrieve the action name
  • Yaf_Request_Abstract::getBaseUri — Retrieve the base URI
  • Yaf_Request_Abstract::getControllerName — Retrieve the controller name
  • Yaf_Request_Abstract::getCookie — Fetch a COOKIE variable
  • Yaf_Request_Abstract::getEnv — Retrieve an ENV variable
  • Yaf_Request_Abstract::getException — Retrieve the exception
  • Yaf_Request_Abstract::getFiles — Fetch uploaded files
  • Yaf_Request_Abstract::getLanguage — Retrieve the client's preferred language
  • Yaf_Request_Abstract::getMethod — Retrieve the request method
  • Yaf_Request_Abstract::getModuleName — Retrieve the module name
  • Yaf_Request_Abstract::getParam — Retrieve a parameter
  • Yaf_Request_Abstract::getParams — Retrieve all parameters
  • Yaf_Request_Abstract::getPost — Fetch a POST parameter
  • Yaf_Request_Abstract::getQuery — Fetch a query parameter
  • Yaf_Request_Abstract::getRaw — Retrieve the raw request body
  • Yaf_Request_Abstract::getRequest — Fetch a REQUEST variable
  • Yaf_Request_Abstract::getRequestUri — Retrieve the request URI
  • Yaf_Request_Abstract::getServer — Retrieve a SERVER variable
  • Yaf_Request_Abstract::isCli — Determine if the request is a CLI request
  • Yaf_Request_Abstract::isDelete — Determine if the request is a DELETE request
  • Yaf_Request_Abstract::isDispatched — Determine if the request is dispatched
  • Yaf_Request_Abstract::isGet — Determine if the request is a GET request
  • Yaf_Request_Abstract::isHead — Determine if the request is a HEAD request
  • Yaf_Request_Abstract::isOptions — Determine if the request is a OPTIONS request
  • Yaf_Request_Abstract::isPatch — Determine if the request is a PATCH request
  • Yaf_Request_Abstract::isPost — Determine if the request is a POST request
  • Yaf_Request_Abstract::isPut — Determine if the request is a PUT request
  • Yaf_Request_Abstract::isRouted — Determine if the request has been routed
  • Yaf_Request_Abstract::isXmlHttpRequest — Determine if the request is an Ajax request
  • Yaf_Request_Abstract::setActionName — Set action name
  • Yaf_Request_Abstract::setBaseUri — Set base URI
  • Yaf_Request_Abstract::setControllerName — Set controller name
  • Yaf_Request_Abstract::setDispatched — Mark the request as dispatched
  • Yaf_Request_Abstract::setModuleName — Set module name
  • Yaf_Request_Abstract::setParam — Set a parameter to the request
  • Yaf_Request_Abstract::setRequestUri — Set the request URI
  • Yaf_Request_Abstract::setRouted — Mark the request as routed

Yaf_Request_Http — The Yaf_Request_Http class

  • Yaf_Request_Http::__construct — Constructor of Yaf_Request_Http

Yaf_Request_Simple — The Yaf_Request_Simple class

  • Yaf_Request_Simple::__construct — Constructor of Yaf_Request_Simple

Yaf_Response_Abstract — The Yaf_Response_Abstract class

  • Yaf_Response_Abstract::appendBody — Append to the response body
  • Yaf_Response_Abstract::clearBody — Discard all existing response bodies
  • Yaf_Response_Abstract::clearHeaders — Remove all response headers
  • Yaf_Response_Abstract::__construct — Construct a response
  • Yaf_Response_Abstract::getBody — Retrieve a response body block
  • Yaf_Response_Abstract::getHeader — Retrieve an HTTP response header
  • Yaf_Response_Abstract::prependBody — Prepend to the response body
  • Yaf_Response_Abstract::response — Send the response
  • Yaf_Response_Abstract::setAllHeaders — Set all HTTP response headers
  • Yaf_Response_Abstract::setBody — Set content to the response
  • Yaf_Response_Abstract::setHeader — Set an HTTP response header
  • Yaf_Response_Abstract::setRedirect — Redirect to another URL
  • Yaf_Response_Abstract::__toString — Retrieve all bodys as string

Yaf_Response_Cli — The Yaf_Response_Cli class

Yaf_Response_Http — The Yaf_Response_Http class

Yaf_Route_Interface — The Yaf_Route_Interface class

  • Yaf_Route_Interface::assemble — Assemble a request
  • Yaf_Route_Interface::route — Route a request

Yaf_Route_Map — The Yaf_Route_Map class

  • Yaf_Route_Map::assemble — Assemble a url
  • Yaf_Route_Map::__construct — Construct a map route
  • Yaf_Route_Map::route — Route a request

Yaf_Route_Regex — The Yaf_Route_Regex class

  • Yaf_Route_Regex::assemble — Assemble a url
  • Yaf_Route_Regex::__construct — Yaf_Route_Regex constructor
  • Yaf_Route_Regex::route — Route a request

Yaf_Route_Rewrite — The Yaf_Route_Rewrite class

  • Yaf_Route_Rewrite::assemble — Assemble a url
  • Yaf_Route_Rewrite::__construct — Yaf_Route_Rewrite constructor
  • Yaf_Route_Rewrite::route — Route a request

Yaf_Router — The Yaf_Router class

  • Yaf_Router::addConfig — Add config-defined routes into Router
  • Yaf_Router::addRoute — Add new Route into Router
  • Yaf_Router::__construct — Yaf_Router constructor
  • Yaf_Router::getCurrentRoute — Get the effective route name
  • Yaf_Router::getRoute — Retrieve a route by name
  • Yaf_Router::getRoutes — Retrieve registered routes
  • Yaf_Router::route — Route a request

Yaf_Route_Simple — The Yaf_Route_Simple class

  • Yaf_Route_Simple::assemble — Assemble a url
  • Yaf_Route_Simple::__construct — Construct a simple route
  • Yaf_Route_Simple::route — Route a request

Yaf_Route_Static — The Yaf_Route_Static class

  • Yaf_Route_Static::assemble — Assemble a url
  • Yaf_Route_Static::match — Whether the route matches a URI
  • Yaf_Route_Static::route — Route a request

Yaf_Route_Supervar — The Yaf_Route_Supervar class

  • Yaf_Route_Supervar::assemble — Assemble a url
  • Yaf_Route_Supervar::__construct — Construct a supervar route
  • Yaf_Route_Supervar::route — Route a request

Yaf_Session — The Yaf_Session class

  • Yaf_Session::__construct — Constructor of Yaf_Session
  • Yaf_Session::count — Count session entries
  • Yaf_Session::current — Get current session entry value
  • Yaf_Session::del — Remove a session key
  • Yaf_Session::get — Get a session value
  • Yaf_Session::getInstance — Get the session singleton
  • Yaf_Session::has — Check if a session key exists
  • Yaf_Session::__isset — Check if a session key exists
  • Yaf_Session::key — Get current session entry key
  • Yaf_Session::next — Advance to next session entry
  • Yaf_Session::offsetExists — Check if a session key exists (ArrayAccess)
  • Yaf_Session::offsetGet — Get a session value (ArrayAccess)
  • Yaf_Session::offsetSet — Set a session value (ArrayAccess)
  • Yaf_Session::offsetUnset — Remove a session key (ArrayAccess)
  • Yaf_Session::rewind — Reset session iterator to first entry
  • Yaf_Session::set — Set a session value
  • Yaf_Session::start — Start the session
  • Yaf_Session::__unset — Remove a session key
  • Yaf_Session::valid — Check if current session position is valid

예외 클래스

  • Yaf_Exception — The Yaf_Exception class
  • Yaf_Exception::__construct — Construct a Yaf exception
  • Yaf_Exception::getPrevious — Retrieve the previous exception
  • Yaf_Exception_TypeError — The Yaf_Exception_TypeError class
  • Yaf_Exception_StartupError — The Yaf_Exception_StartupError class
  • Yaf_Exception_DispatchFailed — The Yaf_Exception_DispatchFailed class
  • Yaf_Exception_RouterFailed — The Yaf_Exception_RouterFailed class
  • Yaf_Exception_LoadFailed — The Yaf_Exception_LoadFailed class
  • Yaf_Exception_LoadFailed_Module — The Yaf_Exception_LoadFailed_Module class
  • Yaf_Exception_LoadFailed_Controller — The Yaf_Exception_LoadFailed_Controller class
  • Yaf_Exception_LoadFailed_Action — The Yaf_Exception_LoadFailed_Action class
  • Yaf_Exception_LoadFailed_View — The Yaf_Exception_LoadFailed_View class

더 알아보기

  • Yaf의 핵심 장점은 요청당 오버헤드가 극히 작다는 거예요. 고트래픽이나 Swoole 같은 장수 런타임과 함께 쓸 때 부트스트랩 비용을 줄일 수 있어요.
  • 라우트 타입이 여러 개(Yaf_Route_Static, Yaf_Route_Regex, Yaf_Route_Rewrite 등)라서 URL 구조를 유연하게 설계할 수 있어요. 플러그인 훅 7개를 활용하면 요청 생애주기 각 단계에 개입할 수 있어요.