A fast php framework written in c, built in php-ext
C PHP Other
Latest commit ff534f6 Aug 18, 2016 @laruence back to dev
Failed to load latest commit information.
configs Attempt to fix #226 (segfault on windows 7 64bits) Dec 28, 2015
requests simplify, constant are inherited from Yaf_Request_Abstract Jun 24, 2016
responses Fixed issue #190 Sep 6, 2015
routes avoiding strdup Jul 4, 2016
tests Added test script for issue #303 Aug 18, 2016
tools added some TODOs.. fixed typos and a possible bug fix Sep 15, 2013
travis Fix typo Dec 8, 2013
views Added test script for issue #303 Aug 18, 2016
.gitattributes attributes Sep 5, 2012
.travis.yml Disable travis for 5.* Feb 12, 2015
CREDITS 1. Fixed issues #4 Aug 17, 2012
EXPERIMENTAL initial commit Dec 13, 2011
LICENSE Add LICENSE file Oct 8, 2012
README.md remove Jul 6, 2016
check-package.sh Missing files, fix #82 Jan 8, 2014
config.m4 Fixed issue #189 Error in pecl upgrade to get the newest stable yaf Sep 8, 2015
config.w32 try to fix windws build Jan 9, 2014
package.xml releasing 3.0.4 Aug 18, 2016
php_yaf.h back to dev Aug 18, 2016
yaf.c Attempt to fix issue #194 Sep 10, 2015
yaf.dsp Add working folder to include path Jan 18, 2013
yaf.php initial commit Dec 13, 2011
yaf_action.c porting Feb 9, 2015
yaf_action.h porting Feb 9, 2015
yaf_application.c Minor opt Aug 12, 2016
yaf_application.h porting Feb 9, 2015
yaf_bootstrap.c Clean up Feb 11, 2015
yaf_bootstrap.h Clean up Feb 11, 2015
yaf_config.c Remove useless yaf.cache_config Jun 17, 2015
yaf_config.h Clean up Feb 11, 2015
yaf_controller.c Merge branch 'master' into php7 Nov 15, 2015
yaf_controller.h porting Feb 9, 2015
yaf_dispatcher.c Minor opt Aug 12, 2016
yaf_dispatcher.h clean up Jun 1, 2015
yaf_exception.c Clean up Feb 11, 2015
yaf_exception.h add exception filter in EXCEPTION_HANDLER in case yaf 'eat' Error Aug 5, 2015
yaf_loader.c Minor opt Aug 12, 2016
yaf_loader.h Minor opt Aug 12, 2016
yaf_logo.h Clean up Feb 11, 2015
yaf_namespace.h Clean up Feb 11, 2015
yaf_plugin.c Change version Feb 11, 2015
yaf_plugin.h Clean up Feb 11, 2015
yaf_registry.c cleanup Jul 6, 2016
yaf_registry.h Clean up Feb 11, 2015
yaf_request.c Fixed use of uninitialized var Dec 27, 2015
yaf_request.h Attempt to fix Issue #231 (php-fpm worker core dump BUG) Dec 27, 2015
yaf_response.c cleanup Jul 6, 2016
yaf_response.h Fixed issue #185 Aug 17, 2015
yaf_router.c cleanup Jul 5, 2016
yaf_router.h Clean up Feb 11, 2015
yaf_session.c Fixed test fails on ZTS Oct 27, 2015
yaf_session.h Clean up Feb 11, 2015
yaf_view.c Clean up Feb 11, 2015
yaf_view.h Clean up Feb 11, 2015

README.md

Yaf - Yet Another Framework

Build Status

PHP framework written in c and built as a PHP extension.

Requirement

  • PHP 5.2 +

Install

Install Yaf

Yaf is an PECL extension, thus you can simply install it by:

$pecl install yaf

Compile Yaf in Linux

$/path/to/phpize
$./configure --with-php-config=/path/to/php-config
$make && make install

Document

Yaf manual could be found at: http://www.php.net/manual/en/book.yaf.php

IRC

efnet.org #php.yaf

For IDE

you could find a documented prototype script here: https://github.com/elad-yosifon/php-yaf-doc

Tutorial

layout

A classic Application directory layout:

- .htaccess // Rewrite rules
+ public
  | - index.php // Application entry
  | + css
  | + js
  | + img
+ conf
  | - application.ini // Configure 
- application/
  - Bootstrap.php   // Bootstrap
  + controllers
     - Index.php // Default controller
  + views    
     |+ index   
        - index.phtml // View template for default controller
  - library
  - models  // Models
  - plugins // Plugins

DocumentRoot

you should set DocumentRoot to application/public, thus only the public folder can be accessed by user

index.php

index.php in the public directory is the only way in of the application, you should rewrite all request to it(you can use .htaccess in Apache+php mod)

<?php
define("APPLICATION_PATH",  dirname(dirname(__FILE__)));

$app  = new Yaf_Application(APPLICATION_PATH . "/conf/application.ini");
$app->bootstrap() //call bootstrap methods defined in Bootstrap.php
    ->run();

Rewrite rules

Apache

#.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php

Nginx

server {
  listen ****;
  server_name  domain.com;
  root   document_root;
  index  index.php index.html index.htm;

  if (!-e $request_filename) {
    rewrite ^/(.*)  /index.php/$1 last;
  }
}

Lighttpd

$HTTP["host"] =~ "(www.)?domain.com$" {
  url.rewrite = (
     "^/(.+)/?$"  => "/index.php/$1",
  )
}

application.ini

application.ini is the application config file

[product]
;CONSTANTS is supported
application.directory = APPLICATION_PATH "/application/" 

alternatively, you can use a PHP array instead:

<?php
$config = array(
   "application" => array(
       "directory" => application_path . "/application/",
    ),
);

$app  = new yaf_application($config);
....

default controller

In Yaf, the default controller is named IndexController:

<?php
class IndexController extends Yaf_Controller_Abstract {
   // default action name
   public function indexAction() {  
        $this->getView()->content = "Hello World";
   }
}
?>

view script

The view script for default controller and default action is in the application/views/index/index.phtml, Yaf provides a simple view engineer called "Yaf_View_Simple", which supported the view template written by PHP.

<html>
 <head>
   <title>Hello World</title>
 </head>
 <body>
   <?php echo $content; ?>
 </body>
</html>

Run the Applicatioin

http://www.yourhostname.com/

Alternative

you can generate the example above by using Yaf Code Generator: https://github.com/laruence/php-yaf/tree/master/tools/cg

More

More info could be found at Yaf Manual: http://www.php.net/manual/en/book.yaf.php