Skip to content
This repository

a php framework written in c, built in php-ext

Merge pull request #88 from DigDeeply/master

YAF_SHUTDOWN_FUNCTION marco error.
latest commit 1097e4073e
Xinchen Hui authored
Octocat-spinner-32 configs Fix: [-Wreturn-type] January 08, 2014
Octocat-spinner-32 requests fix a bug September 10, 2013
Octocat-spinner-32 responses [-Wformat=] January 08, 2014
Octocat-spinner-32 routes Fix [-Wunused-variable] [-Wparentheses] January 08, 2014
Octocat-spinner-32 tests Fixed test case December 07, 2013
Octocat-spinner-32 tools added some TODOs.. fixed typos and a possible bug fix September 15, 2013
Octocat-spinner-32 travis Fix typo December 08, 2013
Octocat-spinner-32 views Assign should return $this not boolean December 31, 2013
Octocat-spinner-32 .gitattributes attributes September 05, 2012
Octocat-spinner-32 .travis.yml Add PHP 5.5 into test cycles April 19, 2013
Octocat-spinner-32 CREDITS 1. Fixed issues #4 August 17, 2012
Octocat-spinner-32 EXPERIMENTAL initial commit December 13, 2011
Octocat-spinner-32 LICENSE Add LICENSE file October 08, 2012
Octocat-spinner-32 README.md Update README.md September 16, 2013
Octocat-spinner-32 check-package.sh Missing files, fix #82 January 08, 2014
Octocat-spinner-32 config.m4 Fixed compile fails with VS January 18, 2013
Octocat-spinner-32 config.w32 try to fix windws build January 09, 2014
Octocat-spinner-32 package.xml Prepare for 2.3.2 January 09, 2014
Octocat-spinner-32 php_yaf.h Merge pull request #88 from DigDeeply/master March 12, 2014
Octocat-spinner-32 yaf.c Fixed version constant January 14, 2014
Octocat-spinner-32 yaf.dsp Add working folder to include path January 18, 2013
Octocat-spinner-32 yaf.php initial commit December 13, 2011
Octocat-spinner-32 yaf_action.c Remove unnecessary includes January 18, 2013
Octocat-spinner-32 yaf_action.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_application.c fix bug (issues #80) December 31, 2013
Octocat-spinner-32 yaf_application.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_bootstrap.c Remove unnecessary includes January 18, 2013
Octocat-spinner-32 yaf_bootstrap.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_config.c Fixed misleading error message when providing a string in Yaf_Applica… September 13, 2013
Octocat-spinner-32 yaf_config.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_controller.c Fixes few minor typos in argument and method names April 23, 2013
Octocat-spinner-32 yaf_controller.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_dispatcher.c Fix: [-Wunused-but-set-variable] (comment as usage if commented) January 08, 2014
Octocat-spinner-32 yaf_dispatcher.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_exception.c Fixed memory leak in 5.2 December 07, 2013
Octocat-spinner-32 yaf_exception.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_loader.c make code better April 11, 2013
Octocat-spinner-32 yaf_loader.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_logo.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_namespace.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_plugin.c Fix signature May 31, 2013
Octocat-spinner-32 yaf_plugin.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_registry.c Remove unnecessary includes January 18, 2013
Octocat-spinner-32 yaf_registry.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_request.c Fixes few minor typos in argument and method names April 23, 2013
Octocat-spinner-32 yaf_request.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_response.c refactor the implementation November 25, 2013
Octocat-spinner-32 yaf_response.h move setAllHeaders、clearHeaders、getHeader、setHeader to yaf_response_h… November 13, 2013
Octocat-spinner-32 yaf_router.c Merge branch 'dev' of https://github.com/wenjun1055/php-yaf November 25, 2013
Octocat-spinner-32 yaf_router.h Fixed issue #69 November 25, 2013
Octocat-spinner-32 yaf_session.c Add Yaf_Session::clear May 20, 2013
Octocat-spinner-32 yaf_session.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
Octocat-spinner-32 yaf_view.c Fixed compile fails with VS January 18, 2013
Octocat-spinner-32 yaf_view.h Support dynmaic routing for Regex/Rewrite route January 14, 2013
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

For windows

Yaf binary dlls could be found at http://code.google.com/p/yafphp/downloads/list

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 = APP_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

Something went wrong with that request. Please try again.