Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 protected function decode($content)
 {
     try {
         return Json::decode($content);
     } catch (JsonException $e) {
         throw new AccessException('Invalid JSON file: ' . $e->getMessage(), 0, $e);
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function decode(DataType $type, $value)
 {
     if (!isset($value)) {
         return null;
     }
     switch ($type->type) {
         case DataType::BOOLEAN:
             return $value != 0;
         case DataType::INTEGER:
         case DataType::DATE:
         case DataType::DATETIME:
             return intval($value);
         case DataType::FLOAT:
             return floatval($value);
         case DataType::TEXT:
         case DataType::BINARY:
         case DataType::STRING:
         case DataType::ENUM:
             return strval($value);
         case DataType::OBJECT:
             return Json::decode($value);
     }
 }
Beispiel #3
0
 /**
  * Get information about a database driver.
  *
  * The returned information array is of the format:
  * <code>
  * array(
  * 'driver' => ..., // Driver name (string)
  * 'name' => ..., // Formal name, e.g. 'MySQL' instead of 'MySql' (string)
  * 'requiredOptions' => array(...), // List of required options (string[])
  * 'optionalOptions' => array(...), // List of optional options (string[])
  * 'isAvailable' => ..., // Whether or not driver is available (bool)
  * 'missingExtensions => array(...) // List of missing extensions (string[])
  * )
  * </code>
  *
  * @param string $driver
  *            Driver name
  * @return array Driver information as an associative array.
  * @throws InvalidDriverException If driver is missing or invalid.
  */
 public function checkDriver($driver)
 {
     if (!file_exists($this->drivers . '/' . $driver . '/' . $driver . 'Database.php')) {
         throw new InvalidDriverException('Driver class not found: ' . $driver);
     }
     if (!file_exists($this->drivers . '/' . $driver . '/driver.json')) {
         throw new InvalidDriverException('Driver manifest not found: ' . $driver);
     }
     try {
         $info = Json::decodeFile($this->drivers . '/' . $driver . '/driver.json');
     } catch (JsonException $e) {
         throw new InvalidDriverException('Invalid driver manifest: ' . $driver . ' (' . $e->getMessage() . ')', 0, $e);
     }
     if (!isset($info['required'])) {
         $info['required'] = array();
     }
     if (!isset($info['optional'])) {
         $info['optional'] = array();
     }
     if (!isset($info['phpExtensions'])) {
         $info['phpExtensions'] = array();
     }
     $missing = array();
     foreach ($info['phpExtensions'] as $dependency) {
         if (!extension_loaded($dependency)) {
             $missing[] = $dependency;
         }
     }
     return array('driver' => $driver, 'name' => $info['name'], 'requiredOptions' => $info['required'], 'optionalOptions' => $info['optional'], 'isAvailable' => count($missing) < 1, 'missingExtensions' => $missing);
 }