Esempio n. 1
0
 /**
  * Execute a finite number of stages and end the execution.
  * If the number of stages to be executed are less than zero than the entire
  * pipeline is executed.
  * 
  * @param int $steps number of stages to be passed before stopping the execution
  *
  * @throws \InvalidArgumentException invalid arguments passed
  */
 public function __invoke($steps = -1)
 {
     //check the number of steps
     if (!is_int($steps)) {
         throw new \InvalidArgumentException('The number of steps to execute must be given as an integer number');
     }
     //register the current runtime
     PipelineSupport::RegisterRuntime($this);
     //get the exact number of stages that should be executed
     $stepsNumber = $steps < 0 ? $this->pipeline->countStages() : $steps;
     for ($i = $this->getCompletedStagesCount(); $stepsNumber > 0 && $i < $this->pipeline->countStages() && $this->status != RuntimeStatus::ABORTED; ++$i) {
         try {
             //the pipeline is working right now
             $this->status = RuntimeStatus::WORKING;
             //get the starting time
             $startTime = time();
             $start = microtime(true);
             //register the currently used runtime
             self::$currentExecution =& $this;
             //fetch & execute the pipeline stage
             $reflectedFunction = $this->pipeline->reflectFunctionByIndex($i);
             $executionResult = $reflectedFunction->invokeArgs([&$this->serializableCollection]);
             //unregister the currently used runtime
             self::$currentExecution = null;
             //get the final time
             $time_elapsed_secs = microtime(true) - $start;
             $finalTime = time();
             //generate and store the report
             $this->completionReports[] = ['start_time' => $startTime, 'end_time' => $finalTime, 'elapse_time' => $time_elapsed_secs, 'result' => $executionResult];
             //the pipeline is stopped right now
             $this->status = RuntimeStatus::STOPPED;
         } catch (\Gishiki\Pipeline\PipelineAbortSignal $abortSignal) {
             //the pipeline was aborted
             $this->status = RuntimeStatus::ABORTED;
             //the abort reason must be saved
             $this->abortMessage = $abortSignal->getMessage();
         }
         if (is_null($this->abortMessage) && $this->status != RuntimeStatus::ABORTED && $i == $this->pipeline->countStages() - 1) {
             $this->status = RuntimeStatus::COMPLETED;
         }
         //register the currently active runtime
         PipelineSupport::saveCurrentPupeline();
         --$stepsNumber;
     }
     //runtime ended
     PipelineSupport::UnregisterRuntime();
 }
Esempio n. 2
0
 /**
  * Load the framework configuration from the config file and return it in an
  * format kwnown to the framework.
  */
 private function loadConfiguration()
 {
     //get the security configuration of the current application
     $config = [];
     if (self::applicationExists()) {
         $config = self::getApplicationSettings();
         //General Configuration
         $this->configuration = ['DEVELOPMENT_ENVIRONMENT' => isset($config['general']['development']) ? $config['general']['development'] : false, 'AUTOLOG_URL' => isset($config['general']['autolog']) ? $config['general']['autolog'] : 'null', 'SECURITY' => ['MASTER_SYMMETRIC_KEY' => $config['security']['serverPassword'], 'MASTER_ASYMMETRIC_KEY' => $config['security']['serverKey']], 'CONNECTIONS' => array_key_exists('connections', $config) ? $config['connections'] : array(), 'PIPELINE' => ['CONNECTION' => isset($config['pipeline']['connection']) ? $config['pipeline']['connection'] : null, 'COLLECTION' => isset($config['pipeline']['collection']) ? $config['pipeline']['collection'] : null]];
     }
     //check for the environment configuration
     if ($this->configuration['DEVELOPMENT_ENVIRONMENT']) {
         ini_set('display_errors', 1);
         error_reporting(E_ALL);
     } else {
         ini_set('display_errors', 0);
         error_reporting(0);
     }
     //connect every db connection
     foreach ($this->configuration['CONNECTIONS'] as $connection) {
         \Gishiki\Database\DatabaseManager::Connect($connection['name'], $connection['query']);
     }
     //setup the pipeline execution support
     \Gishiki\Pipeline\PipelineSupport::Initialize($this->GetConfigurationProperty('PIPELINE_CONNECTION_NAME'), $this->GetConfigurationProperty('PIPELINE_TABLE_NAME'));
 }