/** * Reads configuration from the given source and creates * a Piece_Flow_Config object. * * @param mixed $source * @param string $driverName * @param string $cacheDirectory * @param string $configDirectory * @param string $configExtension * @return Piece_Flow_Config * @throws PIECE_FLOW_ERROR_NOT_FOUND * @static */ function &read($source, $driverName, $cacheDirectory, $configDirectory, $configExtension) { if (!is_callable($source)) { $flowName = $source; if (!is_null($configDirectory)) { $source = str_replace('_', '/', $source); $source = "{$configDirectory}/{$source}{$configExtension}"; } if (is_null($driverName)) { $driverName = strtoupper(substr(strrchr($source, '.'), 1)); if ($driverName != 'YAML' && $driverName != 'XML') { $driverName = 'YAML'; } } if ($driverName == 'XML') { if (version_compare(phpversion(), '5.0.0', '>=')) { $driverName = 'XML5'; } else { $driverName = 'XML4'; } } } else { $driverName = 'PHPArray'; } $class = "Piece_Flow_ConfigReader_{$driverName}"; if (!Piece_Flow_ClassLoader::loaded($class)) { Piece_Flow_ClassLoader::load($class); if (Piece_Flow_Error::hasErrors()) { $return = null; return $return; } if (!Piece_Flow_ClassLoader::loaded($class)) { Piece_Flow_Error::push(PIECE_FLOW_ERROR_NOT_FOUND, "The class [ {$class} ] not found in the loaded file."); $return = null; return $return; } } $driver =& new $class($source, $cacheDirectory); $config =& $driver->read(); if (Piece_Flow_Error::hasErrors()) { $return = null; return $return; } if (!is_callable($source)) { if (is_null($configDirectory)) { $flowName = basename($source); $positionOfExtension = strrpos($flowName, '.'); if ($positionOfExtension !== false) { $flowName = substr($flowName, 0, $positionOfExtension); } } $config->setName($flowName); } return $config; }
/** * Loads an action class corresponding to the given class name. * * @param string $class * @throws PIECE_FLOW_ERROR_NOT_GIVEN * @throws PIECE_FLOW_ERROR_NOT_FOUND */ function load($class) { if (!Piece_Flow_ClassLoader::loaded($class)) { if (is_null($GLOBALS['PIECE_FLOW_Action_Directory'])) { Piece_Flow_Error::push(PIECE_FLOW_ERROR_NOT_GIVEN, 'The action directory is not given.'); return; } Piece_Flow_ClassLoader::load($class, $GLOBALS['PIECE_FLOW_Action_Directory']); if (Piece_Flow_Error::hasErrors()) { return; } if (!Piece_Flow_ClassLoader::loaded($class)) { Piece_Flow_Error::push(PIECE_FLOW_ERROR_NOT_FOUND, "The class [ {$class} ] not found in the loaded file."); } } }