Exemple #1
0
 /**
  * The entry method.
  *
  * @access  public
  * @return  int
  */
 public function main()
 {
     $reset = false;
     $generate = false;
     $cache = 'hoa://Application/Cache/Route.php';
     $route = 'hoa://Application/Config/Route.php';
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case 'g':
                 $generate = true;
             case 'r':
                 $reset = true;
                 break;
             case 'h':
             case '?':
                 return $this->usage();
                 break;
         }
     }
     if ($reset === true) {
         if (file_exists($cache)) {
             $result = unlink($cache);
             if ($result) {
                 echo \Hoa\Console\Chrome\Text::colorize('[OK] Cache flush', 'foreground(green)') . "\n";
             } else {
                 echo \Hoa\Console\Chrome\Text::colorize('[!!] Cache flush', 'foreground(white) background(red)') . "\n";
             }
         } else {
             echo \Hoa\Console\Chrome\Text::colorize('No cache found', 'foreground(green)') . "\n";
         }
     }
     if ($generate === true) {
         $core = Core::getInstance();
         $parameters = $core->getParameters();
         $cwd = $parameters->getKeyword('cwd');
         $parameters->setKeyword('cwd', $cwd . '/Public');
         $framework = new Framework();
         $router = $framework->getRouter();
         $dir = dirname($cache);
         $router->saveCache($cache);
         echo 'Save your router result in' . \Hoa\Console\Chrome\Text::colorize(resolve($cache), 'foreground(green)') . "\n";
     }
     if ($reset === false && $generate === false) {
         return $this->usage();
     }
 }
Exemple #2
0
 public static function initialize($cwd = null)
 {
     if (static::$_initialize === true) {
         return;
     }
     static::$_initialize = true;
     /**
      * @var \Hoa\Core\Parameter\Parameter $parameters
      * @var \Hoa\Core\Core $core
      */
     $core = Core::getInstance();
     $parameters = $core->getParameters();
     if ($cwd !== null) {
         $parameters->setKeyword('cwd', $cwd);
     }
     $parameters->setParameter('protocol.Application', '(:cwd:h:)/Application/');
     $parameters->setParameter('protocol.Public', '(:%root.application:)/Public/');
     $parameters->setParameter('namespace.prefix.Application', '(:cwd:h:)/');
     $core->setProtocol();
 }
Exemple #3
0
 /**
  * The entry method.
  *
  * @access  public
  * @return  int
  */
 public function main()
 {
     $command = null;
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case 'h':
             case '?':
                 return $this->usage();
                 break;
         }
     }
     $cache = 'hoa://Application/Cache/Route.php';
     $route = 'hoa://Application/Config/Route.php';
     $core = Core::getInstance();
     $parameters = $core->getParameters();
     $cwd = $parameters->getKeyword('cwd');
     $parameters->setKeyword('cwd', $cwd . '/Public');
     $framework = new Framework();
     $router = $framework->getRouter();
     $router->construct();
     echo '# Router rules in ' . resolve($route) . "\n\n";
     echo Text::columnize($router->dump()) . "\n\n";
     return;
 }
Exemple #4
0
header('Content-Type: application/json');
if ('OPTIONS' === $_SERVER['REQUEST_METHOD'] && isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
    header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE');
    die;
}
/**
 * PHP Settings
 */
date_default_timezone_set('Europe/Paris');
/**
 * Autoloader Composer
 */
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
/** ******************************************************************************************************* **/
use Hoa\Core, Hoa\Dispatcher;
$hoa = Core\Core::getInstance();
$hoa->getParameters()->setParameter('root.data', dirname(dirname(dirname(__DIR__))) . DS . 'data');
$hoa->setProtocol();
Core\Core::enableErrorHandler();
Core\Core::enableExceptionHandler();
Hoa\Database\Dal::initializeParameters(array('connection.list.default.dal' => Hoa\Database\Dal::PDO, 'connection.list.default.dsn' => 'sqlite:' . resolve('hoa://Data') . '/comments.sqlite'));
$dal = Hoa\Database\Dal::getInstance('default');
$baseUri = '/api/v1/';
$router = new Hoa\Router\Http\Http();
$router->get('p', $baseUri . 'posts', function () use($dal) {
    $statement = $dal->query('SELECT t.*, (select group_concat(c.id) from comments as c where c.tid = t.id) as comments FROM threads as t');
    $posts = [];
    while ($row = $statement->fetchNext()) {
        $row['comments'] = explode(',', $row['comments']);
        foreach ($row['comments'] as &$c) {
            $c = (int) $c;
Exemple #5
0
 * User: Camael24
 * Date: 16/01/14
 * Time: 16:57
 */
namespace Sohapi\Bin;

use Hoa\Core\Core;
require __DIR__ . '/../../vendor/autoload.php';
/**
 * Here we go…
 */
try {
    unset($_SERVER['TERM']);
    ini_set('xdebug.max_nesting_level', '300');
    ini_set('xdebug.max_nesting_level', '300');
    $core = Core::getInstance();
    $parameters = $core->getParameters();
    /**
     * @var \Hoa\Core\Parameter\Parameter $parameters
     */
    $cwd = __DIR__ . '/../../../../../../';
    $parameters->setKeyword('cwd', realpath($cwd));
    $parameters->setParameter('protocol.Application', '(:cwd:)/Application/');
    $parameters->setParameter('protocol.Public', '(:%root.application:)/Public/');
    $parameters->setParameter('namespace.prefix.Application', '(:cwd:)/');
    $core->setProtocol();
    $router = new \Hoa\Router\Cli();
    $router->get('g', '(?:(?<vendor>\\w+)\\s+)?(?<library>\\w+)?(?::(?<command>\\w+))?(?<_tail>.*?)', 'main', 'main', array('vendor' => 'sohapi', 'library' => 'core', 'command' => 'generate'));
    $dispatcher = new \Hoa\Dispatcher\ClassMethod(array('synchronous.call' => '(:%variables.vendor:lU:)\\Bin\\Command\\(:%variables.library:lU:)\\(:%variables.command:lU:)', 'synchronous.able' => 'main'));
    $dispatcher->setKitName('Hoa\\Console\\Dispatcher\\Kit');
    exit($dispatcher->dispatch($router));