Beispiel #1
0
 /**
  * Loads a scheme along with its attributes, behaviors, relations, tasks, store and other information about the
  * scheme
  *
  * @param $schemeName
  * @return One_Scheme
  */
 public static function load($schemeName)
 {
     $scheme = new One_Scheme($schemeName);
     $schemePath = One_Locator::locate('meta' . DIRECTORY_SEPARATOR . 'scheme' . DIRECTORY_SEPARATOR . $schemeName . '.xml');
     if ($schemePath === null) {
         throw new One_Exception("The scheme {$schemeName} could not be located.");
     }
     $dom = new DOMDocument('1.0', 'utf-8');
     if (!$dom->load($schemePath)) {
         throw new One_Exception("The scheme {$schemeName} could not be loaded.");
     }
     $xpath = new DOMXPath($dom);
     $nodelist = $xpath->query('/scheme');
     if ($nodelist->length > 0) {
         $meta = $nodelist->item(0);
     } else {
         throw new One_Exception("The definition for scheme {$schemeName} is invalid.");
     }
     self::setAttributes($scheme, $xpath, $meta);
     self::setRelationships($scheme, $xpath, $meta);
     self::setBehaviors($scheme, $xpath, $meta);
     self::setRules($scheme, $xpath, $meta);
     self::setConnection($scheme, $xpath, $meta);
     self::setInformation($scheme, $xpath, $meta);
     self::setRoutings($scheme, $xpath, $meta);
     return $scheme;
 }
Beispiel #2
0
 /**
  * Loads a relation by it's name
  *
  * @param string $relationName
  * @return One_Relation
  * @static
  */
 public static function load($relationName)
 {
     $relation = new One_Relation($relationName);
     $roles = array();
     if (preg_match('/^subscheme%([^%]+)%(.+)/', $relationName, $relMatch) > 0) {
         $rS = new One_Relation_Role($relMatch[1], $relMatch[1], array('cardinality' => 'one'));
         $rSu = new One_Relation_Role($relMatch[2], $relMatch[1] . '%' . $relMatch[2], array('cardinality', 'subscheme'));
         $roles[$relMatch[1]] = $rS;
         $roles[$relMatch[2]] = $rSu;
     } else {
         $relationpath = One_Locator::locate('meta' . DIRECTORY_SEPARATOR . 'relation' . DIRECTORY_SEPARATOR . $relationName . '.xml');
         if ($relationpath === null) {
             throw new One_Exception('Could not load the relation "' . $relationName . '"');
         }
         $dom = new DOMDocument('1.0', 'utf-8');
         if ($dom->load($relationpath)) {
             $relAttributes = array();
             $relationSpec = $dom->getElementsByTagName('relation');
             if ($relationSpec->length > 0) {
                 $relEle = $relationSpec->item(0);
                 $attributes = $relEle->attributes;
                 for ($i = 0; $i < $attributes->length; $i++) {
                     $attr = $attributes->item($i);
                     $relAttributes[$attr->name] = $attr->value;
                 }
             }
             $relation->setMeta($relAttributes);
             $xpath = new DOMXPath($dom);
             // create the attribute set for this scheme
             $roleSpecs = $xpath->query('/relation/roles/role');
             for ($i = 0; $i < $roleSpecs->length; $i++) {
                 unset($r);
                 $roleOptions = array();
                 $roleSpec = $roleSpecs->item($i);
                 $attributes = $roleSpec->attributes;
                 for ($j = 0; $j < $attributes->length; $j++) {
                     $attr = $attributes->item($j);
                     switch ($attr->name) {
                         case 'name':
                             $name = $attr->value;
                             break;
                         case 'scheme':
                             $scheme = $attr->value;
                             break;
                         default:
                             $roleOptions[$attr->name] = $attr->value;
                             break;
                     }
                 }
                 $r = new One_Relation_Role($name, $scheme, $roleOptions);
                 $roles[$r->name] = $r;
             }
         }
     }
     $relation->setRoles($roles);
     return $relation;
 }
Beispiel #3
0
 /**
  * Look for the specified file using the locator. If it exists, autoload it and return true, otherwise return false
  *
  * @param string $filename
  * @return boolean
  */
 public static function tryLoading($filename)
 {
     $path = One_Locator::locate($filename);
     if ($path === null) {
         return false;
     }
     require_once $path;
     return true;
 }
Beispiel #4
0
 /**
  * Loads a store instantiation
  *
  * @param string $connectionName
  * @return One_Store_Connection
  */
 public static function load($connectionName)
 {
     // read the scheme's metafile
     $connectionpath = One_Locator::locate('meta' . DIRECTORY_SEPARATOR . 'connection' . DIRECTORY_SEPARATOR . $connectionName . '.xml');
     if ($connectionpath === null) {
         throw new One_Exception('Could not find the one|content store-connection called <strong>' . $connectionName . '</strong>.');
     }
     // read the scheme's metafile
     $dom = new DOMDocument('1.0', 'utf-8');
     if ($dom->load($connectionpath)) {
         // Check if the connection tag was defined
         $connectionSpecs = $dom->getElementsByTagName('connection');
         if ($connectionSpecs->length == 0) {
             throw new One_Exception('one|content store-connection called <strong>' . $connectionName . '</strong> was not properly defined');
         }
         $connectionSpec = $connectionSpecs->item(0);
         $xpath = new DOMXPath($dom);
         // Get the connection type
         $type = self::getType($xpath);
         //Create the One_Store_Connection
         $className = 'One_Store_Connection_' . ucfirst(strtolower($type));
         if (!class_exists($className)) {
             throw new One_Exception('A connection of type "' . $type . '" does not exist');
         }
         $connection = new $className($connectionName);
         // get and set the store
         $store = self::getStore($xpath);
         $connection->setStore($store);
         // get and set the encoding for the connection
         $encoding = self::getEncoding($xpath);
         $connection->setEncoding($encoding);
         $meta = array();
         if ($connectionSpec->hasChildNodes()) {
             $child = $connectionSpec->firstChild;
             do {
                 if ($child->nodeType == XML_ELEMENT_NODE) {
                     unset($childName);
                     unset($attributes);
                     $childName = $child->nodeName;
                     $meta[$childName] = array();
                     $attributes = $child->attributes;
                     if (count($attributes) > 0) {
                         for ($i = 0; $i < $attributes->length; $i++) {
                             $attribute = $attributes->item($i);
                             $meta[$childName][$attribute->name] = $attribute->value;
                         }
                     }
                 }
                 $child = $child->nextSibling;
             } while (!is_null($child));
         }
         $connection->setMeta($meta);
         return $connection;
     } else {
         throw new One_Exception('one|content store-connection called <strong>' . $connectionName . '</strong> was not properly defined');
     }
 }
Beispiel #5
0
 public static function isPackage($pkName)
 {
     $path = One_Locator::locate('script' . DIRECTORY_SEPARATOR . 'package' . DIRECTORY_SEPARATOR . $pkName . '.php');
     //    echo '<br><b>', $pkName, '</b> is ', ($path === null ? 'NOT' : ' '), ' a package';
     //*** temporary
     if ($path) {
         return true;
     }
     $path = One_Locator::locate('script' . DIRECTORY_SEPARATOR . 'package' . DIRECTORY_SEPARATOR . $pkName . '_tbd.php');
     return $path !== null;
 }
Beispiel #6
0
    public static function addBlockToken($token, $endToken)
    {
        self::$nodeBlockTokens[$token] = $endToken;
    }
    public static function addIgnoreTag($tag)
    {
        self::$ignoreTags[] = $tag;
    }
    public static function addHandler($handler)
    {
        array_unshift(self::$tagHandlers, $handler);
    }
    public static function setNanoContentBase($server, $database, $user, $pass)
    {
        self::$ncServer = $server;
        self::$ncDatabase = $database;
        self::$ncUser = $user;
        self::$ncPass = $pass;
        self::$ncEnabled = 1;
    }
}
One_Script_Config::addHandler(new One_Script_Tag_Handler_Catchall());
One_Script_Config::addHandler(new One_Script_Tag_Handler_Ignore());
One_Script_Config::$ncEnabled = 0;
// load custom config if there is any
$additionalConfigPaths = One_Locator::locate('script/config_add.php');
if (is_array($additionalConfigPaths)) {
    foreach ($additionalConfigPaths as $additionalConfig) {
        include_once $additionalConfig;
    }
}