Yaf
Yaf (Yet Another Framework, C로 만든 PHP 웹 프레임워크)
PHP로 웹 애플리케이션을 만들되, 프레임워크 오버헤드를 최소화하고 싶을 때 쓰는 확장이에요. Yaf는 일반적인 PHP 프레임워크와 달리 C로 작성돼 확장으로 컴파일되는 프레임워크예요. 프레임워크 클래스, 오토로더, 라우터, 디스패치 루프가 모두 컴파일된 코드로 동작해서, 요청당 프레임워크 오버헤드가 밀리초가 아니라 마이크로초 단위예요.
본문
소개
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 instanceYaf_Application::bootstrap— Call bootstrapYaf_Application::clearLastError— Clear the last error infoYaf_Application::__construct— Yaf_Application constructorYaf_Application::environ— Retrieve the environmentYaf_Application::execute— Execute a callbackYaf_Application::getAppDirectory— Get the application directoryYaf_Application::getConfig— Retrieve the config instanceYaf_Application::getDispatcher— Get Yaf_Dispatcher instanceYaf_Application::getLastErrorMsg— Get message of the last occurred errorYaf_Application::getLastErrorNo— Get code of the last occurred errorYaf_Application::getModules— Get defined module namesYaf_Application::run— Start Yaf_ApplicationYaf_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 autorenderingYaf_Dispatcher::catchException— Switch on/off exception catchingYaf_Dispatcher::__construct— Yaf_Dispatcher constructorYaf_Dispatcher::disableView— Disable view renderingYaf_Dispatcher::dispatch— Dispatch a requestYaf_Dispatcher::enableView— Enable view renderingYaf_Dispatcher::flushInstantly— Switch on/off the instant flushingYaf_Dispatcher::getApplication— Retrieve the applicationYaf_Dispatcher::getDefaultAction— Retrieve the default action nameYaf_Dispatcher::getDefaultController— Retrieve the default controller nameYaf_Dispatcher::getDefaultModule— Retrieve the default module nameYaf_Dispatcher::getInstance— Retrieve the dispatcher instanceYaf_Dispatcher::getRequest— Retrieve the request instanceYaf_Dispatcher::getResponse— Get the response objectYaf_Dispatcher::getRouter— Retrieve router instanceYaf_Dispatcher::initView— Initialize view and return itYaf_Dispatcher::registerPlugin— Register a pluginYaf_Dispatcher::returnResponse— Switch on/off returning the responseYaf_Dispatcher::setDefaultAction— Change default action nameYaf_Dispatcher::setDefaultController— Change default controller nameYaf_Dispatcher::setDefaultModule— Change default module nameYaf_Dispatcher::setErrorHandler— Set error handlerYaf_Dispatcher::setRequest— Set the request objectYaf_Dispatcher::setResponse— Set the response objectYaf_Dispatcher::setView— Set a custom view engineYaf_Dispatcher::throwException— Switch on/off exception throwing
Yaf_Config_Abstract — The Yaf_Config_Abstract class
Yaf_Config_Abstract::get— Retrieve a configuration valueYaf_Config_Abstract::readonly— Check if configuration is read-onlyYaf_Config_Abstract::set— Set a configuration valueYaf_Config_Abstract::toArray— Export configuration as array
Yaf_Config_Ini — The Yaf_Config_Ini class
Yaf_Config_Ini::__construct— Constructor of Yaf_Config_IniYaf_Config_Ini::count— Count configuration entriesYaf_Config_Ini::current— Get current entry valueYaf_Config_Ini::get— Retrieve a configuration valueYaf_Config_Ini::__isset— Check if a key existsYaf_Config_Ini::key— Get current entry keyYaf_Config_Ini::next— Advance to next entryYaf_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-onlyYaf_Config_Ini::rewind— Reset iterator to first entryYaf_Config_Ini::set— Set a configuration valueYaf_Config_Ini::toArray— Export configuration as arrayYaf_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_SimpleYaf_Config_Simple::count— Count configuration entriesYaf_Config_Simple::current— Get current entry valueYaf_Config_Simple::get— Retrieve a configuration valueYaf_Config_Simple::__isset— Check if a key existsYaf_Config_Simple::key— Get current entry keyYaf_Config_Simple::next— Advance to next entryYaf_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-onlyYaf_Config_Simple::rewind— Reset iterator to first entryYaf_Config_Simple::set— Set a configuration valueYaf_Config_Simple::toArray— Export configuration as arrayYaf_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_AbstractYaf_Controller_Abstract::display— Render and display a viewYaf_Controller_Abstract::forward— Forward the current request to another actionYaf_Controller_Abstract::getInvokeArg— Retrieve one action invocation argumentYaf_Controller_Abstract::getInvokeArgs— Retrieve all action invocation argumentsYaf_Controller_Abstract::getModuleName— Get module nameYaf_Controller_Abstract::getName— Get controller nameYaf_Controller_Abstract::getRequest— Retrieve current request objectYaf_Controller_Abstract::getResponse— Retrieve current response objectYaf_Controller_Abstract::getView— Retrieve the view engineYaf_Controller_Abstract::getViewpath— Get the view pathYaf_Controller_Abstract::init— Controller initializerYaf_Controller_Abstract::initView— Initialize the view and return itYaf_Controller_Abstract::redirect— Redirect to a URLYaf_Controller_Abstract::render— Render view templateYaf_Controller_Abstract::setViewpath— Set the view path
Yaf_Action_Abstract — The Yaf_Action_Abstract class
Yaf_Action_Abstract::execute— Action entry pointYaf_Action_Abstract::getController— Retrieve controller objectYaf_Action_Abstract::getControllerName— Get controller name
Yaf_View_Interface — The Yaf_View_Interface class
Yaf_View_Interface::assign— Assign a variable to the viewYaf_View_Interface::display— Render and emit a templateYaf_View_Interface::getScriptPath— Get the template directoryYaf_View_Interface::render— Render a templateYaf_View_Interface::setScriptPath— Set the template directory
Yaf_View_Simple — The Yaf_View_Simple class
Yaf_View_Simple::assign— Assign a variable to the viewYaf_View_Simple::assignRef— Alias of Yaf_View_Simple::assignYaf_View_Simple::clear— Remove an assigned variableYaf_View_Simple::__construct— Constructor of Yaf_View_SimpleYaf_View_Simple::display— Render and store a template in the responseYaf_View_Simple::eval— Render a template stringYaf_View_Simple::get— Get an assigned variableYaf_View_Simple::getScriptPath— Get the template directoryYaf_View_Simple::__isset— Check whether a variable is assignedYaf_View_Simple::render— Render a templateYaf_View_Simple::__set— Assign a variable via property writeYaf_View_Simple::setScriptPath— Set the template directory
Yaf_Loader — The Yaf_Loader class
Yaf_Loader::autoload— Autoload a classYaf_Loader::clearLocalNamespace— Clear registered namespacesYaf_Loader::__construct— The constructor is privateYaf_Loader::getInstance— Retrieve the Yaf_Loader instanceYaf_Loader::getLibraryPath— Retrieve the library pathYaf_Loader::getLocalNamespace— Retrieve registered namespacesYaf_Loader::getNamespacePath— Retrieve the library path of a classYaf_Loader::getNamespaces— Alias of getLocalNamespaceYaf_Loader::import— Load a PHP scriptYaf_Loader::isLocalName— Whether a class is localYaf_Loader::registerLocalNamespace— Register local namespaceYaf_Loader::registerNamespace— Alias of registerLocalNamespaceYaf_Loader::setLibraryPath— Change the library path
Yaf_Plugin_Abstract — The Yaf_Plugin_Abstract class
Yaf_Plugin_Abstract::dispatchLoopShutdown— Hook after dispatch loopYaf_Plugin_Abstract::dispatchLoopStartup— Hook before dispatch loopYaf_Plugin_Abstract::postDispatch— Hook after each dispatchYaf_Plugin_Abstract::preDispatch— Hook before each dispatchYaf_Plugin_Abstract::preResponse— Hook before the response is sentYaf_Plugin_Abstract::routerShutdown— Hook after routingYaf_Plugin_Abstract::routerStartup— Hook before routing
Yaf_Registry — The Yaf_Registry class
Yaf_Registry::__construct— Constructor of Yaf_RegistryYaf_Registry::del— Remove an item from registryYaf_Registry::get— Retrieve an item from registryYaf_Registry::has— Check whether an item existsYaf_Registry::set— Add an item into registry
Yaf_Request_Abstract — The Yaf_Request_Abstract class
Yaf_Request_Abstract::clearParams— Remove all parametersYaf_Request_Abstract::get— Retrieve a variable from the requestYaf_Request_Abstract::getActionName— Retrieve the action nameYaf_Request_Abstract::getBaseUri— Retrieve the base URIYaf_Request_Abstract::getControllerName— Retrieve the controller nameYaf_Request_Abstract::getCookie— Fetch a COOKIE variableYaf_Request_Abstract::getEnv— Retrieve an ENV variableYaf_Request_Abstract::getException— Retrieve the exceptionYaf_Request_Abstract::getFiles— Fetch uploaded filesYaf_Request_Abstract::getLanguage— Retrieve the client's preferred languageYaf_Request_Abstract::getMethod— Retrieve the request methodYaf_Request_Abstract::getModuleName— Retrieve the module nameYaf_Request_Abstract::getParam— Retrieve a parameterYaf_Request_Abstract::getParams— Retrieve all parametersYaf_Request_Abstract::getPost— Fetch a POST parameterYaf_Request_Abstract::getQuery— Fetch a query parameterYaf_Request_Abstract::getRaw— Retrieve the raw request bodyYaf_Request_Abstract::getRequest— Fetch a REQUEST variableYaf_Request_Abstract::getRequestUri— Retrieve the request URIYaf_Request_Abstract::getServer— Retrieve a SERVER variableYaf_Request_Abstract::isCli— Determine if the request is a CLI requestYaf_Request_Abstract::isDelete— Determine if the request is a DELETE requestYaf_Request_Abstract::isDispatched— Determine if the request is dispatchedYaf_Request_Abstract::isGet— Determine if the request is a GET requestYaf_Request_Abstract::isHead— Determine if the request is a HEAD requestYaf_Request_Abstract::isOptions— Determine if the request is a OPTIONS requestYaf_Request_Abstract::isPatch— Determine if the request is a PATCH requestYaf_Request_Abstract::isPost— Determine if the request is a POST requestYaf_Request_Abstract::isPut— Determine if the request is a PUT requestYaf_Request_Abstract::isRouted— Determine if the request has been routedYaf_Request_Abstract::isXmlHttpRequest— Determine if the request is an Ajax requestYaf_Request_Abstract::setActionName— Set action nameYaf_Request_Abstract::setBaseUri— Set base URIYaf_Request_Abstract::setControllerName— Set controller nameYaf_Request_Abstract::setDispatched— Mark the request as dispatchedYaf_Request_Abstract::setModuleName— Set module nameYaf_Request_Abstract::setParam— Set a parameter to the requestYaf_Request_Abstract::setRequestUri— Set the request URIYaf_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 bodyYaf_Response_Abstract::clearBody— Discard all existing response bodiesYaf_Response_Abstract::clearHeaders— Remove all response headersYaf_Response_Abstract::__construct— Construct a responseYaf_Response_Abstract::getBody— Retrieve a response body blockYaf_Response_Abstract::getHeader— Retrieve an HTTP response headerYaf_Response_Abstract::prependBody— Prepend to the response bodyYaf_Response_Abstract::response— Send the responseYaf_Response_Abstract::setAllHeaders— Set all HTTP response headersYaf_Response_Abstract::setBody— Set content to the responseYaf_Response_Abstract::setHeader— Set an HTTP response headerYaf_Response_Abstract::setRedirect— Redirect to another URLYaf_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 requestYaf_Route_Interface::route— Route a request
Yaf_Route_Map — The Yaf_Route_Map class
Yaf_Route_Map::assemble— Assemble a urlYaf_Route_Map::__construct— Construct a map routeYaf_Route_Map::route— Route a request
Yaf_Route_Regex — The Yaf_Route_Regex class
Yaf_Route_Regex::assemble— Assemble a urlYaf_Route_Regex::__construct— Yaf_Route_Regex constructorYaf_Route_Regex::route— Route a request
Yaf_Route_Rewrite — The Yaf_Route_Rewrite class
Yaf_Route_Rewrite::assemble— Assemble a urlYaf_Route_Rewrite::__construct— Yaf_Route_Rewrite constructorYaf_Route_Rewrite::route— Route a request
Yaf_Router — The Yaf_Router class
Yaf_Router::addConfig— Add config-defined routes into RouterYaf_Router::addRoute— Add new Route into RouterYaf_Router::__construct— Yaf_Router constructorYaf_Router::getCurrentRoute— Get the effective route nameYaf_Router::getRoute— Retrieve a route by nameYaf_Router::getRoutes— Retrieve registered routesYaf_Router::route— Route a request
Yaf_Route_Simple — The Yaf_Route_Simple class
Yaf_Route_Simple::assemble— Assemble a urlYaf_Route_Simple::__construct— Construct a simple routeYaf_Route_Simple::route— Route a request
Yaf_Route_Static — The Yaf_Route_Static class
Yaf_Route_Static::assemble— Assemble a urlYaf_Route_Static::match— Whether the route matches a URIYaf_Route_Static::route— Route a request
Yaf_Route_Supervar — The Yaf_Route_Supervar class
Yaf_Route_Supervar::assemble— Assemble a urlYaf_Route_Supervar::__construct— Construct a supervar routeYaf_Route_Supervar::route— Route a request
Yaf_Session — The Yaf_Session class
Yaf_Session::__construct— Constructor of Yaf_SessionYaf_Session::count— Count session entriesYaf_Session::current— Get current session entry valueYaf_Session::del— Remove a session keyYaf_Session::get— Get a session valueYaf_Session::getInstance— Get the session singletonYaf_Session::has— Check if a session key existsYaf_Session::__isset— Check if a session key existsYaf_Session::key— Get current session entry keyYaf_Session::next— Advance to next session entryYaf_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 entryYaf_Session::set— Set a session valueYaf_Session::start— Start the sessionYaf_Session::__unset— Remove a session keyYaf_Session::valid— Check if current session position is valid
예외 클래스
Yaf_Exception— The Yaf_Exception classYaf_Exception::__construct— Construct a Yaf exceptionYaf_Exception::getPrevious— Retrieve the previous exceptionYaf_Exception_TypeError— The Yaf_Exception_TypeError classYaf_Exception_StartupError— The Yaf_Exception_StartupError classYaf_Exception_DispatchFailed— The Yaf_Exception_DispatchFailed classYaf_Exception_RouterFailed— The Yaf_Exception_RouterFailed classYaf_Exception_LoadFailed— The Yaf_Exception_LoadFailed classYaf_Exception_LoadFailed_Module— The Yaf_Exception_LoadFailed_Module classYaf_Exception_LoadFailed_Controller— The Yaf_Exception_LoadFailed_Controller classYaf_Exception_LoadFailed_Action— The Yaf_Exception_LoadFailed_Action classYaf_Exception_LoadFailed_View— The Yaf_Exception_LoadFailed_View class
더 알아보기
- Yaf의 핵심 장점은 요청당 오버헤드가 극히 작다는 거예요. 고트래픽이나 Swoole 같은 장수 런타임과 함께 쓸 때 부트스트랩 비용을 줄일 수 있어요.
- 라우트 타입이 여러 개(
Yaf_Route_Static,Yaf_Route_Regex,Yaf_Route_Rewrite등)라서 URL 구조를 유연하게 설계할 수 있어요. 플러그인 훅 7개를 활용하면 요청 생애주기 각 단계에 개입할 수 있어요.