示例#1
0
 /**
  * Runs the CLI Generate process
  *
  * @param array $args CLI arguments
  *
  * @return void
  */
 public function run($args)
 {
     if (!file_exists($this->cwd . '/bootstrap.php')) {
         Index::error('This command requires ' . $this->cwd . '/bootstrap.php to be present.');
     }
     //expecting cradle install cradle/address
     if (count($args) < 3) {
         Index::error('Not enough arguments. Usage: cradle package vendor/package command');
     }
     $cradle = cradle();
     if (file_exists($this->cwd . '/bootstrap.php')) {
         include $this->cwd . '/bootstrap.php';
     }
     try {
         $cradle->package($args[1]);
     } catch (Exception $e) {
         //it means that the package wasn't registered
         $cradle->register($args[1]);
     }
     //Setup a default error handler
     $cradle->error(function ($request, $response, $error) {
         Index::error($error->getMessage() . PHP_EOL . $error->getTraceAsString());
     });
     //prepare data
     $data = Index::parseArgs(array_slice($args, 3));
     //case for root packages
     if (strpos($args[1], '/') === 0) {
         $args[1] = substr($args[1], 1);
     }
     list($author, $package) = explode('/', $args[1], 2);
     $event = $author . '-' . $package . '-' . $args[2];
     //set the the request and response
     $request = $cradle->getRequest();
     $response = $cradle->getResponse();
     $request->setStage($data);
     //see HttpTrait->render() for similar implementation
     //if prepared returned false
     if (!$cradle->prepare()) {
         //dont do anything else
         return $this;
     }
     if ($response->getStatus() == 200) {
         $continue = $cradle->trigger($event, $request, $response)->getEventHandler()->getMeta();
         if (!$continue) {
             return $this;
         }
     }
     if (!$response->hasContent() && $response->hasJson()) {
         $json = json_encode($response->get('json'));
         $response->setContent($json);
     }
     if ($response->hasContent()) {
         echo $response->getContent();
     } else {
         Index::info($args[2] . ' has successfully completed.');
     }
     //the connection is already closed
     //also remember there are no more sessions
     $cradle->shutdown();
 }
示例#2
0
 /**
  * Runs the CLI Generate process
  *
  * @param array $args CLI arguments
  *
  * @return void
  */
 public function run($args)
 {
     if (!file_exists($this->cwd . '/bootstrap.php')) {
         Index::error('This command requires ' . $this->cwd . '/bootstrap.php to be present.');
     }
     //expecting cradle install cradle/address
     if (count($args) < 2) {
         Index::error('Not enough arguments. Usage: cradle event name');
     }
     $cradle = cradle();
     if (file_exists($this->cwd . '/bootstrap.php')) {
         include $this->cwd . '/bootstrap.php';
     }
     //Setup a default error handler
     $cradle->error(function ($request, $response, $error) {
         Index::error($error->getMessage() . PHP_EOL . $error->getTraceAsString());
     });
     //prepare data
     $event = $args[1];
     $data = Index::parseArgs(array_slice($args, 2));
     //set the the request and response
     $request = $cradle->getRequest();
     $response = $cradle->getResponse();
     $request->setStage($data);
     //see HttpTrait->render() for similar implementation
     //if prepared returned false
     if (!$cradle->prepare()) {
         //dont do anything else
         return $this;
     }
     if ($response->getStatus() == 200) {
         $continue = $cradle->trigger($event, $request, $response)->getEventHandler()->getMeta();
         if (!$continue) {
             return $this;
         }
     }
     if (!$response->hasContent() && $response->hasJson()) {
         $json = json_encode($response->get('json'));
         $response->setContent($json);
     }
     if ($response->hasContent()) {
         echo $response->getContent();
     } else {
         Index::info($args[1] . ' has successfully completed.');
     }
     //the connection is already closed
     //also remember there are no more sessions
     $cradle->shutdown();
 }
示例#3
0
<?php

//-->
include __DIR__ . '/../bootstrap.php';
return cradle()->get('/', function ($request, $response) {
    $message = '<h1>Welcome to Cradle!</h1>';
    $response->setContent($message);
})->render();
示例#4
0
<?php

//-->
require_once 'vendor/autoload.php';
//use the cradle function
Cradle\Framework\Decorator::DECORATE;
/**
 * This is where you would add CLI related tools
 */
return cradle()->preprocess(function ($request, $response) {
    //errors
    ini_set('display_errors', '1');
    //timezone
    date_default_timezone_set('GMT');
    //prevent starting session in cli mode
    if (php_sapi_name() !== 'cli') {
        //start session
        session_start();
        //sync the session
        $request->setSession($_SESSION);
    }
});