Example #1
0
 /**
  * Request intantiation process
  *
  * @param   Collection Juriya\Collection
  * @throws  object     RuntimeException
  */
 public function __construct(Collection $config)
 {
     // Initialize the request
     if ($config->valid()) {
         // Get the request environment runtime setting
         $this->path = $config->get('path', array());
         $this->socket = $config->get('socket', NULL);
         $this->arguments = $config->get('arguments', array());
         $this->tunnel = $config->get('tunnel', 'HMVC');
     } else {
         throw new \RuntimeException(I18n::translate('class_cannot_start', __CLASS__));
     }
 }
Example #2
0
 /**
  * Process arguments from $_SERVER
  *
  * @param  array Server arguments
  * @return stream
  */
 public static function processArguments(array $arguments)
 {
     array_shift($arguments);
     if (empty($arguments)) {
         self::showInfo();
     } else {
         $availableCommands = array('-h', '--help', '-v', '--version', '-a', '--app', '-m', '--module', '-t', '--test');
         $commands = new Collection($arguments);
         while ($commands->valid()) {
             $command = $commands->current();
             if (!in_array($command, $availableCommands)) {
                 self::out(I18n::translate('command_not_implemented', $command));
             } else {
                 if ($command == '-h' || $command == '--help') {
                     self::showInfo();
                     $commands->end();
                 } elseif ($command == '-v' || $command == '--version') {
                     self::showVersion();
                     $commands->end();
                 } elseif ($command == '-a' || $command == '--app') {
                     self::generate();
                     $commands->end();
                 } elseif ($command == '-m' || $command == '--module') {
                     $namespace = $commands->next();
                     if (!$namespace) {
                         self::out(I18n::translate('cannot_register_empty_namespace'));
                         self::out(I18n::translate('command_generate_fail'));
                     } else {
                         self::generate($namespace);
                     }
                     $commands->end();
                 } elseif ($command == '-t' || $command == '--test') {
                     $target = $commands->next();
                     self::runTest($target);
                     $commands->end();
                 }
             }
             $commands->next();
         }
     }
 }
Example #3
0
 public function testArrayAccessImplementor()
 {
     $data = array('1' => 'One', '2' => 'Two', '3' => 'Three');
     $collection = new Collection($data);
     $this->assertTrue($collection->valid());
     $this->assertFalse($collection->isEmpty());
     $this->assertEquals(3, $collection->count());
     $this->assertEquals('One', $collection->current());
     $collection->next();
     $this->assertEquals('Two', $collection->current());
     $this->assertEquals('2', $collection->key());
     $collection->rewind();
     $this->assertEquals('1', $collection->key());
     $this->assertEquals('One', $collection->current());
     $collection->ksortDesc();
     $this->assertEquals('3', $collection->key());
     $collection->ksortAsc();
     $this->assertEquals('1', $collection->key());
     $this->assertEquals('Three', $collection->last());
     $collection->end();
     $this->assertEquals('Three', $collection->current());
 }