本文整理汇总了PHP中AgaviToolkit::expandDirectives方法的典型用法代码示例。如果您正苦于以下问题:PHP AgaviToolkit::expandDirectives方法的具体用法?PHP AgaviToolkit::expandDirectives怎么用?PHP AgaviToolkit::expandDirectives使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AgaviToolkit
的用法示例。
在下文中一共展示了AgaviToolkit::expandDirectives方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
/**
* Executes this task.
*/
public function main()
{
if ($this->path === null) {
throw new BuildException('The path attribute must be specified');
}
$check = new AgaviModuleFilesystemCheck();
$check->setConfigDirectory($this->project->getProperty('module.config.directory'));
$check->setPath($this->path->getAbsolutePath());
if (!$check->check()) {
throw new BuildException('The path attribute must be a valid module base directory');
}
/* We don't know whether the module is configured or not here, so load the
* values we want properly. */
$this->tryLoadAgavi();
$this->tryBootstrapAgavi();
require_once AgaviConfigCache::checkConfig(sprintf('%s/%s/module.xml', $this->path->getAbsolutePath(), (string) $this->project->getProperty('module.config.directory')));
$actionPath = AgaviToolkit::expandVariables(AgaviToolkit::expandDirectives(AgaviConfig::get(sprintf('modules.%s.agavi.action.path', strtolower($this->path->getName())), '%core.module_dir%/${moduleName}/actions/${actionName}Action.class.php')), array('moduleName' => $this->path->getName()));
$pattern = '#^' . AgaviToolkit::expandVariables(str_replace('\\$\\{actionName\\}', '${actionName}', preg_quote($actionPath, '#')), array('actionName' => '(?P<action_name>.*?)')) . '$#';
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path->getAbsolutePath()));
for (; $iterator->valid(); $iterator->next()) {
$rdi = $iterator->getInnerIterator();
if ($rdi->isDot() || !$rdi->isFile()) {
continue;
}
$file = $rdi->getPathname();
if (preg_match($pattern, $file, $matches)) {
$this->log(str_replace(DIRECTORY_SEPARATOR, '.', $matches['action_name']));
}
}
}
示例2: importModuleXML
private function importModuleXML($accessLocation)
{
$config = (include AgaviConfigCache::checkConfig(AgaviToolkit::expandDirectives($accessLocation)));
$this->instances = array_merge_recursive($this->instances, $config["instances"]);
$this->defaults = array_merge_recursive($this->defaults, $config["defaults"]);
$this->hosts = array_merge_recursive($this->hosts, $config["hosts"]);
}
示例3: parseRoutesAndFiles
protected function parseRoutesAndFiles(AgaviRouting $routing, $routes, &$data)
{
$controller = $this->context->getController();
$request = $this->context->getRequest();
foreach ($routes as $route) {
$outputTypes = array();
$routeName = $route->getAttribute('name');
if ($routeName !== '*' && is_null($routing->getRoute($routeName))) {
throw new AgaviConfigurationException('Route name "' . $routeName . '" does not exist or is not correct.');
}
if ($route->hasAttribute('output_type')) {
foreach (explode(' ', $route->getAttribute('output_type')) as $ot) {
if ($controller->getOutputType($ot)) {
$outputTypes[] = $ot;
}
}
} else {
$outputTypes[] = $controller->getOutputType()->getName();
// Defaults to HTML
}
foreach ($route->get('filelist') as $filelist) {
$metatype = $filelist->getAttribute('metatype');
foreach ($filelist->getElementsByTagName('file') as $file) {
foreach ($outputTypes as $ot) {
if ($file->hasAttribute('name')) {
$data[$routeName][$ot][$metatype][$file->getAttribute('name')] = AgaviToolkit::expandDirectives($file->getValue());
} else {
$data[$routeName][$ot][$metatype][] = AgaviToolkit::expandDirectives($file->getValue());
}
}
}
}
}
}
示例4: execute
/**
* Execute this configuration handler.
*
* @param AgaviXmlConfigDomDocument The document to parse.
*
* @return string Data to be written to a cache file.
*
* @throws <b>AgaviParseException</b> If a requested configuration file is
* improperly formatted.
*
* @author Sean Kerr <skerr@mojavi.org>
* @author Dominik del Bondio <ddb@bitxtender.com>
* @author David Zülke <david.zuelke@bitextender.com>
* @since 0.9.0
*/
public function execute(AgaviXmlConfigDomDocument $document)
{
// set up our default namespace
$document->setDefaultNamespace(self::XML_NAMESPACE, 'compile');
$config = $document->documentURI;
$data = array();
// let's do our fancy work
foreach ($document->getConfigurationElements() as $configuration) {
if (!$configuration->has('compiles')) {
continue;
}
foreach ($configuration->get('compiles') as $compileFile) {
$file = trim($compileFile->getValue());
$file = AgaviToolkit::expandDirectives($file);
$file = self::replacePath($file);
$file = realpath($file);
if (!is_readable($file)) {
// file doesn't exist
$error = 'Configuration file "%s" specifies nonexistent ' . 'or unreadable file "%s"';
$error = sprintf($error, $config, $compileFile->getValue());
throw new AgaviParseException($error);
}
if (AgaviConfig::get('core.debug', false)) {
// debug mode, just require() the files, makes for nicer stack traces
$contents = 'require(' . var_export($file, true) . ');';
} else {
// no debug mode, so make things fast
$contents = $this->formatFile(file_get_contents($file));
}
// append file data
$data[$file] = $contents;
}
}
return $this->generate($data, $config);
}
示例5: testExpandDirectives
public function testExpandDirectives()
{
AgaviConfig::set('whatever', 'something');
$value = "whatever %directive% asdasdasd %whatever% ";
$result = "whatever %directive% asdasdasd something ";
$this->assertEquals($result, AgaviToolkit::expandDirectives($value));
}
示例6: initialize
public function initialize(AgaviContext $ctx, array $parameters = array())
{
parent::initialize($ctx, $parameters);
$this->dqlViews = (include AgaviConfigCache::checkConfig(AgaviToolkit::expandDirectives('%core.module_dir%/Api/config/views.xml')));
$this->view = $parameters["view"];
$this->viewParameters = isset($parameters["parameters"]) ? $parameters["parameters"] : array();
$this->validateTarget();
$connection = $this->defaultConnection;
if (isset($parameters["connection"])) {
$connection = $parameters["connection"];
}
if ($this->view["connection"]) {
$connection = $this->view["connection"];
}
AppKitLogger::verbose("Switching to connection %s", $connection);
$db = $this->getContext()->getDatabaseManager()->getDatabase($connection);
$this->useRetained = $db->useRetained();
$this->connection = $ctx->getDatabaseConnection($connection);
if ($this->connection != "icinga") {
$ctx->getModel("DBALMetaManager", "Api")->switchIcingaDatabase($connection);
}
$this->user = $this->getContext()->getUser()->getNsmUser();
$this->parseBaseDQL();
$this->parseCustomVariables();
$this->parseDQLExtensions();
$this->parseDependencies();
}
示例7: loadConfig
public static function loadConfig()
{
if (self::$configLoaded) {
return;
}
self::$config = (include AgaviConfigCache::checkConfig(AgaviToolkit::expandDirectives('%core.module_dir%/Api/config/access.xml')));
self::$configLoaded = true;
}
示例8: initialize
/**
* Load Propel config
*
* @param AgaviDatabaseManager The database manager of this instance.
* @param array An assoc array of initialization params.
*
* @author David Zülke <dz@bitxtender.com>
* @since 0.10.0
*/
public function initialize(AgaviDatabaseManager $databaseManager, array $parameters = array())
{
parent::initialize($databaseManager, $parameters);
$configPath = AgaviToolkit::expandDirectives($this->getParameter('config'));
$datasource = $this->getParameter('datasource', null);
$use_as_default = $this->getParameter('use_as_default', false);
$config = (require $configPath);
if ($datasource === null || $datasource == 'default') {
if (isset($config['propel']['datasources']['default'])) {
$datasource = $config['propel']['datasources']['default'];
} elseif (isset($config['datasources']['default'])) {
$datasource = $config['datasources']['default'];
} else {
throw new AgaviDatabaseException('No datasource given for Propel connection, and no default datasource specified in runtime configuration file.');
}
}
if (!class_exists('Propel')) {
include 'propel/Propel.php';
}
if (!Propel::isInit()) {
Propel::init($configPath);
}
$is13 = version_compare(Propel::VERSION, '1.4', '<');
// grab the configuration values and inject possibly defined overrides for this data source
if ($is13) {
// old-style config array; PropelConfiguration was added after 1.3.0, http://trac.agavi.org/ticket/1195
$config = Propel::getConfiguration();
$config['datasources'][$datasource]['adapter'] = $this->getParameter('overrides[adapter]', $config['datasources'][$datasource]['adapter']);
$config['datasources'][$datasource]['connection'] = array_merge($config['datasources'][$datasource]['connection'], $this->getParameter('overrides[connection]', array()));
// also the autoload classes
$config['datasources'][$datasource]['classes'] = array_merge($config['datasources'][$datasource]['classes'], $this->getParameter('overrides[classes]', array()));
// and init queries
if (!isset($config['datasources'][$datasource]['connection']['settings']['queries']['query'])) {
$config['datasources'][$datasource]['connection']['settings']['queries']['query'] = array();
}
// array cast because "query" might be a string if just one init query was given, http://trac.agavi.org/ticket/1194
$config['datasources'][$datasource]['connection']['settings']['queries']['query'] = array_merge((array) $config['datasources'][$datasource]['connection']['settings']['queries']['query'], (array) $this->getParameter('init_queries'));
// set the new config
Propel::setConfiguration($config);
} else {
$config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT);
$overrides = (array) $this->getParameter('overrides');
// set override values
foreach ($overrides as $key => $value) {
$config->setParameter($key, $value);
}
// handle init queries in a cross-adapter fashion (they all support the "init_queries" param)
$queries = (array) $config->getParameter('datasources.' . $datasource . '.connection.settings.queries.query', array());
// yes... it's one array, [connection][settings][queries][query], with all the init queries from the config, so we append to that
$queries = array_merge($queries, (array) $this->getParameter('init_queries'));
$config->setParameter('datasources.' . $datasource . '.connection.settings.queries.query', $queries);
}
if (true === $this->getParameter('enable_instance_pooling')) {
Propel::enableInstancePooling();
} elseif (false === $this->getParameter('enable_instance_pooling')) {
Propel::disableInstancePooling();
}
}
示例9: initialize
public function initialize(AgaviContext $context, array $parameters = array())
{
parent::initialize($context, $parameters);
$this->config = (include AgaviConfigCache::checkConfig(AgaviToolkit::expandDirectives('%core.module_dir%/Api/config/icingaCommands.xml')));
$this->user = $context->getUser();
if ($this->user->getNsmUser()->hasTarget('IcingaCommandRestrictions')) {
$this->filterCommandsByUser($this->config);
}
}
示例10: execute
/**
* Execute this configuration handler.
*
* @param AgaviXmlConfigDomDocument The document to handle.
*
* @return string Data to be written to a cache file.
*
* @throws <b>AgaviUnreadableException</b> If a requested configuration
* file does not exist or is not
* readable.
* @throws <b>AgaviParseException</b> If a requested configuration file is
* improperly formatted.
*
* @author Dominik del Bondio <ddb@bitxtender.com>
* @author Noah Fontes <noah.fontes@bitextender.com>
* @author David Zülke <david.zuelke@bitextender.com>
* @since 0.11.0
*/
public function execute(AgaviXmlConfigDomDocument $document)
{
// set up our default namespace
$document->setDefaultNamespace(self::XML_NAMESPACE, 'config_handlers');
// init our data arrays
$handlers = array();
foreach ($document->getConfigurationElements() as $configuration) {
if (!$configuration->has('handlers')) {
continue;
}
// let's do our fancy work
foreach ($configuration->get('handlers') as $handler) {
$pattern = $handler->getAttribute('pattern');
$category = AgaviToolkit::normalizePath(AgaviToolkit::expandDirectives($pattern));
$class = $handler->getAttribute('class');
$transformations = array(AgaviXmlConfigParser::STAGE_SINGLE => array(), AgaviXmlConfigParser::STAGE_COMPILATION => array());
if ($handler->has('transformations')) {
foreach ($handler->get('transformations') as $transformation) {
$path = AgaviToolkit::literalize($transformation->getValue());
$for = $transformation->getAttribute('for', AgaviXmlConfigParser::STAGE_SINGLE);
$transformations[$for][] = $path;
}
}
$validations = array(AgaviXmlConfigParser::STAGE_SINGLE => array(AgaviXmlConfigParser::STEP_TRANSFORMATIONS_BEFORE => array(AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array(), AgaviXmlConfigParser::VALIDATION_TYPE_SCHEMATRON => array(), AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array()), AgaviXmlConfigParser::STEP_TRANSFORMATIONS_AFTER => array(AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array(), AgaviXmlConfigParser::VALIDATION_TYPE_SCHEMATRON => array(), AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array())), AgaviXmlConfigParser::STAGE_COMPILATION => array(AgaviXmlConfigParser::STEP_TRANSFORMATIONS_BEFORE => array(AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array(), AgaviXmlConfigParser::VALIDATION_TYPE_SCHEMATRON => array(), AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array()), AgaviXmlConfigParser::STEP_TRANSFORMATIONS_AFTER => array(AgaviXmlConfigParser::VALIDATION_TYPE_RELAXNG => array(), AgaviXmlConfigParser::VALIDATION_TYPE_SCHEMATRON => array(), AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array())));
if ($handler->has('validations')) {
foreach ($handler->get('validations') as $validation) {
$path = AgaviToolkit::literalize($validation->getValue());
$type = null;
if (!$validation->hasAttribute('type')) {
$type = $this->guessValidationType($path);
} else {
$type = $validation->getAttribute('type');
}
$for = $validation->getAttribute('for', AgaviXmlConfigParser::STAGE_SINGLE);
$step = $validation->getAttribute('step', AgaviXmlConfigParser::STEP_TRANSFORMATIONS_AFTER);
$validations[$for][$step][$type][] = $path;
}
}
$handlers[$category] = isset($handlers[$category]) ? $handlers[$category] : array('parameters' => array());
$handlers[$category] = array('class' => $class, 'parameters' => $handler->getAgaviParameters($handlers[$category]['parameters']), 'transformations' => $transformations, 'validations' => $validations);
}
}
$data = array('return ' . var_export($handlers, true));
return $this->generate($data, $document->documentURI);
}
示例11: execute
/**
* Execute this configuration handler.
*
* @param AgaviXmlConfigDomDocument The document to parse.
*
* @return string Data to be written to a cache file.
*
* @throws <b>AgaviParseException</b> If a requested configuration file is
* improperly formatted.
*
* @author Sean Kerr <skerr@mojavi.org>
* @author Dominik del Bondio <ddb@bitxtender.com>
* @author Noah Fontes <noah.fontes@bitextender.com>
* @author David Zülke <david.zuelke@bitextender.com>
* @since 0.9.0
*/
public function execute(AgaviXmlConfigDomDocument $document)
{
// set up our default namespace
$document->setDefaultNamespace(self::XML_NAMESPACE, 'autoload');
$classes = $namespaces = array();
foreach ($document->getConfigurationElements() as $configuration) {
if (!$configuration->has('autoloads')) {
continue;
}
// let's do our fancy work
foreach ($configuration->get('autoloads') as $autoload) {
// we can have variables in the filename
$path = AgaviToolkit::expandDirectives($autoload->getValue());
// sanity check; XML Schema can't do <xs:choice> on attributes...
if (($isClass = $autoload->hasAttribute('class')) && $autoload->hasAttribute('namespace')) {
$error = sprintf('Configuration file "%s" specifies both "class" and "namespace" attribute for path "%s"', $document->documentURI, $path);
throw new AgaviParseException($error);
}
// prepend the app dir if the path is not absolute
$file = self::replacePath($path);
// check if absolute path is readable or try to resolve it against the include path
if (!file_exists($file) && ($path == $file || !($file = stream_resolve_include_path($path)))) {
// the class path doesn't exist and couldn't be resolved against the include path either
$error = sprintf('Configuration file "%s" specifies %s "%s" with non-existent path "%s"', $document->documentURI, $isClass ? 'file' : 'namespace', $isClass ? $autoload->getAttribute('class') : $autoload->getAttribute('namespace'), $path);
throw new AgaviParseException($error);
}
if ($isClass) {
// it's a class
$classes[$autoload->getAttribute('class')] = $file;
} else {
// it's a whole namespace
// trim backslashes from the namespace and trailing slashes or backslashes from the path
$namespaces[trim($autoload->getAttribute('namespace'), '\\')] = rtrim($file, '/\\');
}
}
}
$code = array('AgaviAutoloader::addClasses(' . var_export($classes, true) . ');', 'AgaviAutoloader::addNamespaces(' . var_export($namespaces, true) . ');');
return $this->generate($code, $document->documentURI);
}
示例12: execute
/**
* Execute this configuration handler.
*
* @param AgaviXmlConfigDomDocument The document to parse.
*
* @return string Data to be written to a cache file.
*
* @throws <b>AgaviParseException</b> If a requested configuration file is
* improperly formatted.
*
* @author Sean Kerr <skerr@mojavi.org>
* @author Dominik del Bondio <ddb@bitxtender.com>
* @author Noah Fontes <noah.fontes@bitextender.com>
* @since 0.9.0
*/
public function execute(AgaviXmlConfigDomDocument $document)
{
// set up our default namespace
$document->setDefaultNamespace(self::XML_NAMESPACE, 'autoload');
$data = array();
foreach ($document->getConfigurationElements() as $configuration) {
if (!$configuration->has('autoloads')) {
continue;
}
// let's do our fancy work
foreach ($configuration->get('autoloads') as $autoload) {
// we can have variables in the filename
$file = AgaviToolkit::expandDirectives($autoload->getValue());
// we need the filename w/o app dir prepended since the file could
// be placed in the include path
$originalFile = $file;
// if the filename is not absolute we assume its relative to the app dir
$file = self::replacePath($file);
$class = $autoload->getAttribute('name');
if (!($fp = @fopen($file, 'r', true))) {
if ($originalFile != $file && ($fpOriginal = @fopen($originalFile, 'r', true))) {
$file = $originalFile;
$fp = $fpOriginal;
} else {
// the class path doesn't exist
$error = 'Configuration file "%s" specifies class "%s" with ' . 'nonexistent or unreadable file "%s"';
$error = sprintf($error, $document->documentURI, $class, $file);
throw new AgaviParseException($error);
}
}
fclose($fp);
$data[$class] = $file;
}
}
$code = array('return ' . var_export($data, true) . ';');
return $this->generate($code, $document->documentURI);
}
示例13: getLiteralValue
/**
* Returns the literal value. By default, that means whitespace is trimmed,
* boolean literals ("on", "yes", "true", "no", "off", "false") are converted
* and configuration directives ("%core.app_dir%") are expanded.
*
* Takes attributes {http://www.w3.org/XML/1998/namespace}space and
* {http://agavi.org/agavi/config/global/envelope/1.1}literalize into account
* when computing the literal value. This way, users can control the trimming
* and the literalization of values.
*
* AEP-100 has a list of all the conversion rules that apply.
*
* @return mixed The element content converted according to the rules
* defined in AEP-100.
*
* @author David Zülke <david.zuelke@bitextender.com>
* @since 1.1.0
*/
public function getLiteralValue()
{
$value = $this->getValue();
// XML specifies [\x9\xA\xD\x20] as whitespace
// trim strips more than that
// no problem though, because these other chars aren't legal in XML
$trimmedValue = trim($value);
$preserveWhitespace = $this->getAttributeNS(AgaviXmlConfigParser::NAMESPACE_XML_1998, 'space') == 'preserve';
$literalize = AgaviToolkit::literalize($this->getAttributeNS(AgaviXmlConfigParser::NAMESPACE_AGAVI_ENVELOPE_LATEST, 'literalize')) !== false;
if ($literalize) {
if ($preserveWhitespace && ($trimmedValue === '' || $value != $trimmedValue)) {
// we must preserve whitespace, and there is leading or trailing whitespace in the original value, so we won't run AgaviToolkit::literalize(), which trims the input and then converts "true" to a boolean and so forth
// however, we should still expand possible occurrences of config directives
$value = AgaviToolkit::expandDirectives($value);
} else {
// no need to preserve whitespace, or no leading/trailing whitespace, which means we can expand "true", "false" and so forth using AgaviToolkit::literalize()
$value = AgaviToolkit::literalize($trimmedValue);
}
} elseif (!$preserveWhitespace) {
$value = $trimmedValue;
if ($value === '') {
// with or without literalize, an empty string must be converted to NULL if xml:space is default (see ticket #1203 and AEP-100)
$value = null;
}
}
return $value;
}
示例14: replaceConstants
/**
* Replace configuration directive identifiers in a string.
*
* @param string The value on which to run the replacement procedure.
*
* @return string The new value.
*
* @author Sean Kerr <skerr@mojavi.org>
* @author Johan Mjones <johan.mjones@ongame.com>
* @author David Zülke <dz@bitxtender.com>
* @since 0.9.0
*
* @deprecated Use AgaviToolkit::expandDirectives() instead.
*/
public static function replaceConstants($value)
{
return AgaviToolkit::expandDirectives($value);
}
示例15: validateXsi
/**
* Validate a given document according to XMLSchema-instance (xsi)
* declarations.
*
* @param AgaviXmlConfigDomDocument The document to act upon.
*
* @author David Zülke <dz@bitxtender.com>
* @author Noah Fontes <noah.fontes@bitextender.com>
* @since 1.0.0
*/
public static function validateXsi(AgaviXmlConfigDomDocument $document)
{
// next, find (and validate against) XML schema instance declarations
$sources = array();
if ($document->documentElement->hasAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation')) {
// find locations. for namespaces, they are space separated pairs of a namespace URI and a schema location
$locations = preg_split('/\\s+/', $document->documentElement->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation'));
for ($i = 1; $i < count($locations); $i = $i + 2) {
$sources[] = $locations[$i];
}
}
// no namespace? then it's only one schema location in this attribute
if ($document->documentElement->hasAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'noNamespaceSchemaLocation')) {
$sources[] = $document->documentElement->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'noNamespaceSchemaLocation');
}
if ($sources) {
// we have instances to validate against...
$schemas = array();
foreach ($sources as &$source) {
// so for each location, we need to grab the file and validate against this grabbed source code, as libxml often has a hard time retrieving stuff over HTTP
$source = AgaviToolkit::expandDirectives($source);
if (parse_url($source, PHP_URL_SCHEME) === null && !AgaviToolkit::isPathAbsolute($source)) {
// the schema location is relative to the XML file
$source = dirname($document->documentURI) . DIRECTORY_SEPARATOR . $source;
}
$schema = @file_get_contents($source);
if ($schema === false) {
throw new AgaviUnreadableException(sprintf('XML Schema validation file "%s" for configuration file "%s" does not exist or is unreadable', $source, $document->documentURI));
}
$schemas[] = $schema;
}
// now validate them all
self::validateXmlschemaSource($document, $schemas);
}
}