예제 #1
0
 public function testEvaluateFunction()
 {
     $this->assertEquals(1, Utils::evaluate(1));
     $this->assertEquals(2, Utils::evaluate(function () {
         return 2;
     }));
 }
예제 #2
0
 public function createDB($ds)
 {
     if (empty($ds)) {
         return;
     }
     $dbutil = new DBUtil();
     $user = @$ds['user'];
     $pass = @$ds['pass'];
     if (isset($ds['dsn'])) {
         $params = Utils::breakDSN($ds['dsn']);
         $ds = array_merge($ds, $params);
     }
     if (isset($ds[':memory:'])) {
         $this->logger->info('skip :memory: database');
         return;
     }
     if (!isset($ds['database'])) {
         $this->logger->notice('database is not defined.');
         return;
     }
     if (!isset($ds['host'])) {
         $ds['host'] = 'localhost';
     }
     $this->logger->info("creating database {$ds['database']}...");
     $dbutil->create($ds['driver'], array('username' => $user, 'password' => $pass, 'database' => $ds['database'], 'host' => $ds['host']));
 }
예제 #3
0
 public function execute()
 {
     $logger = $this->getLogger();
     $options = $this->getOptions();
     $this->logger->debug("Loading config");
     $loader = ConfigLoader::getInstance();
     $loader->loadFromSymbol(true);
     $loader->initForBuild();
     $this->logger->debug("Initializing schema generator...");
     $generator = new SchemaGenerator($loader, $logger);
     $args = func_get_args();
     $classes = Utils::findSchemasByArguments($loader, $args, $this->logger);
     foreach ($classes as $class) {
         $rfc = new ReflectionClass($class);
         $this->logger->info(sprintf("  %-50s %s", $class, $rfc->getFilename()));
     }
     $logger->info('Done');
 }
예제 #4
0
 public function display($value)
 {
     if ($this->validPairs && isset($this->validPairs[$value])) {
         return $this->validPairs[$value];
     }
     if ($this->validValues && ($validValues = Utils::evaluate($this->validValues))) {
         // search value in validValues array
         // because we store the validValues in an (label => value) array.
         if (ArrayUtils::is_assoc_array($validValues)) {
             if (false !== ($label = array_search($value, $validValues))) {
                 return $label;
             }
             return;
         } elseif (in_array($value, $validValues)) {
             return $value;
         }
     }
     // Optional Values
     if ($this->optionValues && ($optionValues = Utils::evaluate($this->optionValues))) {
         // search value in validValues array
         // because we store the validValues in an (label => value) array.
         if (ArrayUtils::is_assoc_array($optionValues)) {
             if (false !== ($label = array_search($value, $optionValues))) {
                 return $label;
             }
             return $value;
         } elseif (in_array($value, $optionValues)) {
             return $value;
         }
         return $value;
     }
     // backward compatible method
     if ($this->validValueBuilder && ($values = call_user_func($this->validValueBuilder))) {
         if (ArrayUtils::is_assoc_array($values)) {
             if (false !== ($label = array_search($value, $values))) {
                 return $label;
             }
             return;
         } elseif (in_array($value, $values)) {
             return $value;
         }
     }
     if ($this->isa == 'bool') {
         return $value ? _('Yes') : _('No');
     }
     if ($value) {
         if (is_string($value)) {
             return _($value);
         } elseif ($value instanceof DateTime) {
             return $value->format(DateTime::ATOM);
         }
     }
     return $value;
 }