Ejemplo n.º 1
0
 public function current()
 {
     $line = $this->readLine();
     if (!$line) {
         return null;
     }
     if (preg_match('/^\\s/', $line)) {
         throw new SmoothSetupException('Illegal indentation on line ' . $this->line . ' of routes file "' . $this->filename . '".');
     }
     $result = array();
     $matches = array();
     if (preg_match('/(\\w+):/', $line, $matches)) {
         $result['name'] = $matches[1];
     } else {
         $result['name'] = null;
     }
     $line = preg_replace('/^(-|\\w+:)\\s*/', '', $line);
     $methods = self::HTTP_METHODS;
     $method_pattern = "/^({$methods}(?:\\s*,\\s*{$methods})*)\\s*/";
     if (preg_match($method_pattern, $line, $matches)) {
         $result['methods'] = preg_split('/\\s*,\\s*/', $matches[1]);
         $line = substr($line, strlen($matches[0]));
     } else {
         $result['methods'] = null;
     }
     $parts = preg_split('/\\s*=>\\s*/', $line, 2);
     if (count($parts) == 1) {
         $result['path'] = rtrim($parts[0]);
         $result['spec'] = array();
     } else {
         $result['path'] = $parts[0];
         if (preg_match('/^\\{.*\\}$/', $parts[1])) {
             $result['spec'] = yaml_load($parts[1]);
         } else {
             list($controller, $action) = explode('/', rtrim($parts[1]));
             $result['spec'] = array('controller' => $controller, 'action' => $action);
         }
     }
     $post = '';
     $indent = null;
     $matches = array();
     while ($line = $this->readLine()) {
         if (!preg_match('/^\\s+/', $line, $matches)) {
             // This is not an indented block
             $this->stashLine($line);
             break;
         } else {
             if (!$indent) {
                 // Define the indent for the first element; we'll strip it from
                 // the starts of all elements.
                 $indent = strlen($matches[0]);
             }
         }
         $post .= substr($line, $indent);
     }
     if (strlen($post) > 0) {
         $result['spec'] = array_merge($result['spec'], yaml_load($post));
     }
     return $result;
 }
Ejemplo n.º 2
0
function yaml($input = null)
{
    return yaml_load($input);
}
Ejemplo n.º 3
0
 function process($filename)
 {
     # load yaml
     $yaml =& yaml_load($filename);
     //$id = $yaml['id'];
     //		$base = isset ($yaml['base']) ? $this->_parse_base($yaml['base']) : dirname($filename) . '/';
     $base = isset($yaml['base']) ? $this->_parse_base($yaml['base']) : APPPATH;
     if (isset($yaml['includes'])) {
         foreach ($yaml['includes'] as $file) {
             if ($file != $filename) {
                 $this->process($base . $file);
             }
         }
     }
     #create property points
     if (isset($yaml['property-points'])) {
         foreach ($yaml['property-points'] as $file) {
             $name = basename($file, EXT);
             $this->registry->addPropertyPoint(new Drip_PropertyPoint($name, $base, $file));
         }
     }
     # create abstract service points
     if (isset($yaml['abstract-service-points'])) {
         foreach ($yaml['abstract-service-points'] as $aname => $asp) {
             $this->registry->addAbstractServicePoint($aname, $asp);
         }
     }
     # create service points
     if (isset($yaml['service-points'])) {
         # add configuration points
         foreach ($yaml['service-points'] as $name => $sp) {
             if (isset($sp['extends'])) {
                 $ext = $sp['extends'];
                 $ext_conf =& $this->registry->abstractServicePoint($ext);
                 if ($ext_conf != null) {
                     $sp = array_merge_recursive($ext_conf, $sp);
                 }
             }
             if (str_starts_with($name, '+')) {
                 $name = substr($name, 1);
                 $service_point =& $this->registry->servicePoint($name);
                 if ($service_point != null) {
                     if (isset($sp['implementor']['properties'])) {
                         $service_point->instantiator->addProperties($sp['implementor']['properties']);
                     }
                 }
             } else {
                 $service_point =& new Drip_ServicePoint($name, isset($sp['description']) ? $sp['description'] : "");
                 $this->registry->addServicePoint($service_point);
                 $service_point->instantiator = new Drip_Instantiator($sp['implementor'], isset($sp['base']) ? $this->_parse_base($sp['base']) : $base);
                 if (!isset($sp['model'])) {
                     $sp['model'] = 'singleton';
                 }
                 switch ($sp['model']) {
                     default:
                     case 'singleton':
                         $service_point->service_model =& new Drip_SingletonServiceModel(&$service_point->instantiator);
                         //$service_point->service_model->id = uniqid('');
                         break;
                     case 'prototype':
                         $service_point->service_model =& new Drip_PrototypeServiceModel(&$service_point->instantiator);
                         //$service_point->service_model->id = uniqid('');
                         break;
                 }
             }
             if (isset($sp['aliases'])) {
                 foreach ($sp['aliases'] as $alias) {
                     $service_point->addAlias($alias);
                     $this->registry->aliasMap[$alias] = $name;
                 }
             }
         }
     }
     return true;
 }
Ejemplo n.º 4
0
 public static function getConfiguration($root, $environment)
 {
     $exts = '{yml,yaml,conf}';
     $conf = new SmoothConfiguration();
     foreach (array('{app,application}', $environment) as $source) {
         $file = "{$source}.{$exts}";
         $pattern = path_join($root, '{config,configuration}', $file);
         $files = glob($pattern, GLOB_BRACE);
         if (!$files) {
             $files = glob(path_join($root, $file), GLOB_BRACE);
         }
         if (!$files) {
             return;
         }
         if (!is_readable($files[0])) {
             throw new SmoothSetupException('Configuration file "' . $files[0] . '" is not readable.');
         }
         $conf->merge(yaml_load($files[0]));
     }
     return $conf;
 }