基于Swoole的高性能API框架
Switch branches/tags
Clone or download
PersiLiao Merge pull request #8 from PersiLiao/master
add Syx\Dispatcher::setDefaultControllerDir()
Latest commit 997f8f7 May 31, 2018
Permalink
Failed to load latest commit information.
configs Fixed issue#2 php7.2 Apr 12, 2018
requests Fixed issue#2 php7.2 Apr 12, 2018
responses init Mar 21, 2017
routes mismatch arginfo for Syx\RouterInterface::route May 17, 2018
travis init Mar 21, 2017
views init Mar 21, 2017
.gitignore add cmake to gitignore Apr 18, 2018
CREDITS init Mar 21, 2017
EXPERIMENTAL init Mar 21, 2017
LICENSE init Mar 21, 2017
README.md update readme.md Mar 21, 2017
config.m4 add restful route May 17, 2018
config.w32 init Mar 21, 2017
php_syx.h add restful route May 17, 2018
syx.c Update phpinfo display Jan 31, 2018
syx.dsp init Mar 21, 2017
syx.php init Mar 21, 2017
syx_action.c init Mar 21, 2017
syx_action.h init Mar 21, 2017
syx_application.c Fixed issue#2 php7.2 Apr 12, 2018
syx_application.h init Mar 21, 2017
syx_bootstrap.c init Mar 21, 2017
syx_bootstrap.h init Mar 21, 2017
syx_config.c init Mar 21, 2017
syx_config.h init Mar 21, 2017
syx_controller.c init Mar 21, 2017
syx_controller.h init Mar 21, 2017
syx_dispatcher.c add Syx\Dispatcher::setDefaultControllerDir() May 31, 2018
syx_dispatcher.h add Syx\Dispatcher::setDefaultControllerDir() May 31, 2018
syx_exception.c init Mar 21, 2017
syx_exception.h init Mar 21, 2017
syx_loader.c Fixed issue#2 php7.2 Apr 12, 2018
syx_loader.h init Mar 21, 2017
syx_logo.h Update phpinfo display Jan 31, 2018
syx_namespace.h init Mar 21, 2017
syx_plugin.c init Mar 21, 2017
syx_plugin.h init Mar 21, 2017
syx_registry.c Fixed issue#2 php7.2 Apr 12, 2018
syx_registry.h init Mar 21, 2017
syx_request.c init Mar 21, 2017
syx_request.h fixed upper controller bug Apr 23, 2018
syx_response.c init Mar 21, 2017
syx_response.h init Mar 21, 2017
syx_router.c add restful route May 17, 2018
syx_router.h init Mar 21, 2017
syx_session.c Fixed issue#2 php7.2 Apr 12, 2018
syx_session.h init Mar 21, 2017
syx_view.c init Mar 21, 2017
syx_view.h init Mar 21, 2017

README.md

Syx - base of Yaf 3.0.4

Requirement

  • PHP 7.0 +

Install

Compile Syx in Linux

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

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
  + index // index module
    + controller
      - Index.php // Default controller
    + model
      - User.php // Model
    + view
      |+ index
          - index.html // View template for default controller
    + plugin
      - System.php
+ library

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 Syx\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/",
       "namespace" => 'app'  // application default namespace
    ),
);

$app  = new Syx\Application($config);
....

default controller

In Syx, the default controller is named Index:

<?php
namespace app\index\controller;

class Index extends Syx\ControllerAbstract {
   // 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/index/view/index/index.html, Syx provides a simple view engineer called "Syx\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/

Todo list

  • Single module
  • Integrated swoole

QQ Group

QQ Group: 545348293