Esempio n. 1
0
 /**
  * Dispatches the command handler.
  * @param string $call The command handler to execute.
  * @return void
  * @throws CommandNotFoundException
  */
 public function dispatch($call = null)
 {
     $command = $this->routes->get($this->arguments->getCommand(1), false);
     if ($this->routes->get($call, false)) {
         $command = $this->routes->get($call, false);
     }
     if ($command) {
         $handler = new ClassMethodHandler($command, $this->arguments);
         return $handler->call($this->arguments);
     }
     throw new CommandNotFoundException(sprintf('Command %s is not registered.', $call));
 }
Esempio n. 2
0
 /**
  * Detects and sets "option" type arguments.
  * @param type $argument The argument string.
  * @return boolean
  */
 private function detectOptions($argument)
 {
     if (substr($argument, 0, 2) === '--') {
         $name = substr($argument, 2);
         $value = '';
         if (strpos($name, '=')) {
             list($name, $value) = explode('=', $argument, 2);
         }
         $this->options->put(ltrim($name, '-'), trim($value, '"'));
         return true;
     }
     return false;
 }
Esempio n. 3
0
 /**
  * Requires that the password/string is not found in the collection.
  * @param array The array of passwords/strings to check against.
  * @return \Ballen\Plexity\Plexity
  */
 public function notIn(array $array)
 {
     $this->rules->put(self::RULE_NOT_IN, $array);
     return $this;
 }
Esempio n. 4
0
 public function testRandomItem()
 {
     $fruits = new Collection([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
     $random = $fruits->random();
     $assertion = false;
     if ($random > 0 && $random <= 10) {
         $assertion = true;
     }
     $this->assertTrue($assertion, $random);
 }
Esempio n. 5
0
<?php

require_once '../lib/collection.inc.php';
use Ballen\Collection\Collection;
$eol = '<br>';
$fruits = new Collection(['strawberry' => 'Red', 'orange' => 'Orange', 'lemon' => 'Yellow', 'grape' => 'Purple']);
echo 'Total fruits in our collection:' . $fruits->count() . $eol;
// We'll add Apples to our collection...
$fruits->push(['apple' => 'Green']);
echo 'We added an Apple to our collection so now we have: ' . $fruits->count() . ' fruits.' . $eol;
// We'll not iterate over our fruits and output the data...
$fruits->each(function ($key, $value) use($eol) {
    echo 'An ' . $key . ' is ' . $value . $eol;
});
echo "The first fruit is: " . $fruits->first();
echo "The last fruit is: " . $fruits->last();
// We can reset our fruit collection (to either a new list or emtpy it entirely)
$fruits->reset();
echo 'Now that we\'ve reset the collection we now have ' . $fruits->count() . ' items!';
Esempio n. 6
0
 /**
  * Writes the environmental variables to the Nginx configuration file.
  * @param Collection $envars
  * @return boolean
  */
 private function writeToVhostConf(Collection $envars)
 {
     $vhost_conf = NginxHandler::VHOST_AVAILABLE_DIR . DIRECTORY_SEPARATOR . $this->identifier . '.conf';
     $configuration = '';
     foreach ($envars->all()->toArray() as $key => $value) {
         $configuration .= '    fastcgi_param               ' . $key . ' ' . $value . ';' . PHP_EOL;
     }
     if (!@file_put_contents($vhost_conf, replace_between(file_get_contents($vhost_conf), '# [[ENVARS]]', '# [[!ENVARS]]', PHP_EOL . $configuration))) {
         return false;
     }
     return true;
 }
Esempio n. 7
0
<?php

require_once '../lib/collection.inc.php';
use Ballen\Collection\Collection;
$cars = new Collection();
// Add some cars...
$cars->push('Ford Focus');
$cars->push('BMW 580i');
$cars->push('Toyota Avensis');
$cars->push('Marcos Martina Spyder');
// Lets output the cars as a JSON object
echo $cars->all()->toJson();
// How many cars do we have?
echo '<p>Total cars:' . $cars->count() . '</p>';
// Add some more cars...
$cars->push(['Ferrari Modena', 'Seat Leon', 'Peugeot 307', 'Toyota Auris']);
// How many do we have now?
echo '<p>Total cars after adding four:' . $cars->count() . '</p>';
// Lets get the first car in our collection...
echo '<p>First car added was: ' . $cars->first() . '</p>';
// Get the last car from our collection...
echo '<p>Last car added was: ' . $cars->last() . '</p>';
$mini_cooper = 'Nope!';
if ($cars->has('Mini Cooper')) {
    $mini_cooper = 'Yes!';
}
echo '<p>Do we have a Mini Cooper in our collection? ' . $mini_cooper . '</p>';
// Lets shuffle (randomise) our collection...
$cars->shuffle();
echo '<p>Randomised our order now looks like: ' . $cars->all()->toJson() . '</p>';
// We now have zero items in our collection...