sukoshi/sukoshi

This package is abandoned and no longer maintained. No replacement package was suggested.

PHP micro-framework

1.2.3 2015-05-31 10:41 UTC

This package is not auto-updated.

Last update: 2016-02-25 22:14:50 UTC


README

Sukoshi is a PHP based micro-web-framework created for some personnal projects.

What's inside ?

Sukoshi provides the following components :

* Application : the main container which is in charge of routing, dispatching and service registration and injection
* Autoloader : a PSR-0 autoloader
* Event : An event manager

Plus some classes :

* Response : send response to a client
* Request : contains the current HTTP request 

That's it !

Requirements

Sukoshi requires :

  • PHP 5.4+
  • HTTP server with url rewriting capability

Installation

Composer

The recommended method to install Sukoshi is through Composer.

  • Create a composer.json file with the following content :
    {
        "require": {
            "denxp/sukoshi": "~1.2"
        }
    }
  • Run the command :
php composer.phar install

Old fashion

If you don't want to use composer, you can simply include it in your code.

Usage

Create a bootstrap file

Bootstrap is your entry point. Usually it's the "index.php" file which is located in your www folder.


    ├── vendor
    │ └── denxp
    │           └── Sukoshi
    │               └── src
    └── www
        └── index.php
    // www/index.php
    $app = require_once('../vendor/denxp/Sukoshi/src/bootstrap.php');
    ...
    $app->run();

Routes

Sukoshi provides a simple way to define pretty URL. First of all, you have to configure your web server.

Apache

Enable the "mod_rewrite" module and add the following lines to the .htaccess file.


    <IfModule mod_rewrite.c>
        RewriteEngine On  
        RewriteCond %{REQUEST_FILENAME} !-f  
        RewriteRule ^ index.php [L]  
    </IfModule>

nginx

Configure your vhost to look like this :

server {

        ...

        location / {
                try_files $uri $uri/ /index.php$is_args$args;
        }

        location ~ \.php$ {
                try_files $uri =404;
                    fastcgi_index index.php;
                    fastcgi_pass php5-fpm-sock;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include /etc/nginx/fastcgi_params;
        }

        ...
}


Routes are stored as an array into the routes property. A route is defined by a name, a path, a controller, a method and optional parameters. The dynamic parts of the path use named subpatterns.

    $app->routes = [  
        'home' => [  
            'path' => '/',  
            'controller' => 'homeController:executeIndex',  
        ],   
        'post' => [  
            'path' => '/post/(?P<id>\d+)',  
            'controller' => 'blogController:executePost, 
            'params' => [  
                'id' => '0',  
            ],  
            'method' => 'GET'
        ],
        'rest_resource' => [
            'path' => '/resources',
            'multi' => [
                'GET' => 'blogController:executeRessourceGet',
                'POST' => 'blogController:executeRessourcePost',
            ]
        ]
    ];  

Services

@TODO ...

Sample app

You may have a look at this sample application

License

Sukoshi is licensed under the Apache License v2.0