Author: Stefano Azzolini (lastguest@gmail.com)
Example #1
0
<?php

require_once 'vendor/autoload.php';
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use PersonalQueue\JobDealer;
use Pheanstalk\Job;
use Pheanstalk\Pheanstalk;
use Pheanstalk\PheanstalkInterface;
$app = new µ();
$app->cfg('views', __DIR__ . '/templates')->cfg('tube', 'personal-queue')->cfg('log.channel', 'personal-queue')->cfg('log.path', 'app.log')->cfg('log.handler', function (µ $app) {
    return new StreamHandler($app->cfg('log.path'));
})->cfg('log', function (µ $app) {
    $logger = new Logger($app->cfg('log.channel'));
    $logger->pushHandler($app->cfg('log.handler'));
    return $logger;
})->cfg('pheanstalk.host', '127.0.0.1')->cfg('pheanstalk.port', PheanstalkInterface::DEFAULT_PORT)->cfg('pheanstalk', function (µ $app) {
    return new Pheanstalk($app->cfg('pheanstalk.host'), $app->cfg('pheanstalk.port'));
})->cfg('job-dealer', function (µ $app) {
    return (new JobDealer())->setLogger($app->cfg('log'))->setPheanstalk($app->cfg('pheanstalk'))->setTube($app->cfg('tube'));
})->cfg('getParams', function (µ $app) {
    $query = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
    parse_str($query, $getParams);
    return $getParams;
});
if (file_exists('config.php')) {
    $config = (require 'config.php');
    foreach ($config as $key => $value) {
        $app->cfg($key, $value);
    }
}
Example #2
0
 * @author Stefano Azzolini <*****@*****.**>
 */
include 'mu.php';
/**
*
* Define routes callbacks with this syntax :
*	µ::METHOD('ROUTE',CALLBACK);
*
*	- METHOD can be GET,POST,PUT,DELETE,HEAD or some custom HTTP verb
*	- ROUTE is the URL path fragment
*	- CALLBACK is a callable object () invoked by the router.
*/
µ::GET('/', function () {
    echo 'What is your name?';
    echo '<form method=post><input type=text name=username><input type=submit></form>';
});
/**
*	This is executed only when the browser call a POST on '/' route
*/
µ::POST('/', function () {
    echo 'Hello ', $_POST['username'], ', how are you?';
});
/**
*	Invoke the phpinfo function on /php/info route
*/
µ::GET('/php/info', 'phpinfo');
/**
*	Run the application
*/
µ::_();