本文整理汇总了PHP中AgaviToolkit::expandVariables方法的典型用法代码示例。如果您正苦于以下问题:PHP AgaviToolkit::expandVariables方法的具体用法?PHP AgaviToolkit::expandVariables怎么用?PHP AgaviToolkit::expandVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AgaviToolkit
的用法示例。
在下文中一共展示了AgaviToolkit::expandVariables方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: loadModuleFiles
private function loadModuleFiles($tm, &$files)
{
$default = $tm->getDefaultDomain();
$translator = $tm->getDomainTranslator($default, AgaviTranslationManager::MESSAGE);
$locale = $tm->getCurrentLocale();
$domains = array();
if ($translator instanceof AppKitGettextTranslator) {
$basePath = $translator->getDomainPathPattern();
$modules = scandir(AgaviToolkit::literalize("%core.module_dir%"));
foreach ($modules as $m) {
if ($m != '.' && $m != '..') {
$domains[] = $m;
}
}
foreach ($domains as $domain) {
$path = AgaviToolkit::expandVariables($basePath, array('domain' => $domain));
foreach (AgaviLocale::getLookupPath($tm->getCurrentLocale()->getIdentifier()) as $prefix) {
$result = $this->loadFile($path, $prefix, $files);
if ($result) {
$files[$domain] = $result;
}
}
}
}
}
示例3: testExpandVariables
public function testExpandVariables()
{
$string = "{bbq}";
$arguments = array('hehe' => 'hihi', '{bbq}' => 'soon');
$this->assertEquals('{bbq}', AgaviToolkit::expandVariables($string));
$this->assertEquals('${foo}', AgaviToolkit::expandVariables('$foo'));
$this->assertEquals('${foo}', AgaviToolkit::expandVariables('{$foo}'));
}
示例4: getResourceStreamIdentifier
/**
* Get the full, resolved stream location name to the template resource.
*
* @return string A PHP stream resource identifier.
*
* @throws AgaviException If the template could not be found.
*
* @author David Zülke <dz@bitxtender.com>
* @since 0.11.0
*/
public function getResourceStreamIdentifier()
{
$template = $this->getParameter('template');
if ($template === null) {
// no template set, we return null so nothing gets rendered
return null;
}
$args = array();
if (AgaviConfig::get('core.use_translation')) {
// i18n is enabled, build a list of sprintf args with the locale identifier
foreach (AgaviLocale::getLookupPath($this->context->getTranslationManager()->getCurrentLocaleIdentifier()) as $identifier) {
$args[] = array('locale' => $identifier);
}
}
if (empty($args)) {
$args[] = array();
// add one empty arg to always trigger target lookups (even if i18n is disabled etc.)
}
$scheme = $this->getParameter('scheme');
// FIXME: a simple workaround for broken ubuntu and debian packages (fixed already), we can remove that for final 0.11
if ($scheme != 'file' && !in_array($scheme, stream_get_wrappers())) {
throw new AgaviException('Unknown stream wrapper "' . $scheme . '", must be one of "' . implode('", "', stream_get_wrappers()) . '".');
}
$check = $this->getParameter('check');
$attempts = array();
// try each of the patterns
foreach ((array) $this->getParameter('targets', array()) as $pattern) {
// try pattern with each argument list
foreach ($args as $arg) {
$target = AgaviToolkit::expandVariables($pattern, array_merge(array_filter($this->getParameters(), 'is_scalar'), array_filter($this->getParameters(), 'is_null'), $arg));
// FIXME (should they fix it): don't add file:// because suhosin's include whitelist is empty by default, does not contain 'file' as allowed uri scheme
if ($scheme != 'file') {
$target = $scheme . '://' . $target;
}
if (!$check || is_readable($target)) {
return $target;
}
$attempts[] = $target;
}
}
// no template found, time to throw an exception
throw new AgaviException('Template "' . $template . '" could not be found. Paths tried:' . "\n" . implode("\n", $attempts));
}
示例5: loadDomainData
/**
* Loads the data from the data file for the given domain with the current
* locale.
*
* @param string The domain to load the data for.
*
* @author Dominik del Bondio <ddb@bitxtender.com>
* @since 0.11.0
*/
public function loadDomainData($domain)
{
$localeName = $this->locale->getIdentifier();
$localeNameBases = AgaviLocale::getLookupPath($localeName);
if (!isset($this->domainPaths[$domain])) {
if (!$this->domainPathPattern) {
throw new AgaviException('Using domain "' . $domain . '" which has no path specified');
} else {
$basePath = $this->domainPathPattern;
}
} else {
$basePath = $this->domainPaths[$domain];
}
$basePath = AgaviToolkit::expandVariables($basePath, array('domain' => $domain));
$data = array();
foreach ($localeNameBases as $localeNameBase) {
$fileName = AgaviToolkit::expandVariables($basePath, array('locale' => $localeNameBase));
if ($fileName === $basePath) {
// no replacing of $locale happened
$fileName = $basePath . '/' . $localeNameBase . '.mo';
}
if (is_readable($fileName)) {
$fileData = AgaviGettextMoReader::readFile($fileName);
// instead of array_merge, which doesn't handle null bytes in keys properly. careful, the order matters here.
$data = $fileData + $data;
}
}
$headers = array();
if (count($data)) {
$headerData = str_replace("\r", '', $data['']);
$headerLines = explode("\n", $headerData);
foreach ($headerLines as $line) {
$values = explode(':', $line, 2);
// skip empty / invalid lines
if (count($values) == 2) {
$headers[$values[0]] = $values[1];
}
}
}
$this->pluralFormFunc = null;
if (isset($headers['Plural-Forms'])) {
$pf = $headers['Plural-Forms'];
if (preg_match('#nplurals=\\d+;\\s+plural=(.*)$#D', $pf, $match)) {
$funcCode = $match[1];
$validOpChars = array(' ', 'n', '!', '&', '|', '<', '>', '(', ')', '?', ':', ';', '=', '+', '*', '/', '%', '-');
if (preg_match('#[^\\d' . preg_quote(implode('', $validOpChars), '#') . ']#', $funcCode, $errorMatch)) {
throw new AgaviException('Illegal character ' . $errorMatch[0] . ' in plural form ' . $funcCode);
}
// add parenthesis around all ternary expressions. This is done
// to make the ternary operator (?) have precedence over the delimiter (:)
// This will transform
// "a ? 1 : b ? c ? 3 : 4 : 2" to "(a ? 1 : (b ? (c ? 3 : 4) : 2))" and
// "a ? b ? c ? d ? 5 : 4 : 3 : 2 : 1" to "(a ? (b ? (c ? (d ? 5 : 4) : 3) : 2) : 1)"
// "a ? b ? c ? 4 : 3 : d ? 5 : 2 : 1" to "(a ? (b ? (c ? 4 : 3) : (d ? 5 : 2)) : 1)"
// "a ? b ? c ? 4 : 3 : d ? 5 : e ? 6 : 2 : 1" to "(a ? (b ? (c ? 4 : 3) : (d ? 5 : (e ? 6 : 2))) : 1)"
$funcCode = rtrim($funcCode, ';');
$parts = preg_split('#(\\?|\\:)#', $funcCode, -1, PREG_SPLIT_DELIM_CAPTURE);
$parenthesisCount = 0;
$unclosedParenthesisCount = 0;
$firstParenthesis = true;
$funcCode = '';
for ($i = 0, $c = count($parts); $i < $c; ++$i) {
$lastPart = $i > 0 ? $parts[$i - 1] : null;
$part = $parts[$i];
$nextPart = $i + 1 < $c ? $parts[$i + 1] : null;
if ($nextPart == '?') {
if ($lastPart == ':') {
// keep track of parenthesis which need to be closed
// directly after this ternary expression
++$unclosedParenthesisCount;
--$parenthesisCount;
}
$funcCode .= ' (' . $part;
++$parenthesisCount;
} elseif ($lastPart == ':') {
$funcCode .= $part . ') ';
if ($unclosedParenthesisCount > 0) {
$funcCode .= str_repeat(')', $unclosedParenthesisCount);
$unclosedParenthesisCount = 0;
}
--$parenthesisCount;
} else {
$funcCode .= $part;
}
}
if ($parenthesisCount > 0) {
// add the missing top level parenthesis
$funcCode .= str_repeat(')', $parenthesisCount);
}
$funcCode .= ';';
$funcCode = 'return ' . str_replace('n', '$n', $funcCode);
//.........这里部分代码省略.........
示例6: insertErrorMessages
/**
* Insert the error messages from the given incidents into the given element
* using the given rules.
*
* @param DOMElement The element to work on.
* @param array An array of insertion rules
* @param array An array of AgaviValidationIncidents.
*
* @return bool Whether or not the inserts were successful.
*
* @author David Zülke <dz@bitxtender.com>
* @since 0.11.0
*/
protected function insertErrorMessages(DOMElement $element, array $rules, array $incidents)
{
$errorMessages = array();
foreach ($incidents as $incident) {
if ($incident->getSeverity() <= AgaviValidator::SILENT) {
continue;
}
foreach ($incident->getErrors() as $error) {
if (($errorMessage = $error->getMessage()) !== null && $errorMessage !== '') {
$errorMessages[] = $errorMessage;
}
}
}
if (!$errorMessages) {
// nothing to do here
return true;
}
$luie = libxml_use_internal_errors(true);
libxml_clear_errors();
$insertSuccessful = false;
foreach ($rules as $xpathExpression => $errorMessageInfo) {
$targets = $this->xpath->query(AgaviToolkit::expandVariables($xpathExpression, array('htmlnsPrefix' => $this->xmlnsPrefix)), $element);
if (!$targets || !$targets->length) {
continue;
}
if (!is_array($errorMessageInfo)) {
$errorMessageInfo = array('markup' => $errorMessageInfo);
}
if (isset($errorMessageInfo['markup'])) {
$errorMarkup = $errorMessageInfo['markup'];
} else {
throw new AgaviException('Form Population Filter was unable to insert an error message into the document using the XPath expression "' . $xpathExpression . '" because the element information did not contain markup to use.');
}
if (isset($errorMessageInfo['location'])) {
$errorLocation = $errorMessageInfo['location'];
} else {
$errorLocation = 'after';
}
if (isset($errorMessageInfo['container'])) {
$errorContainer = $errorMessageInfo['container'];
} else {
$errorContainer = null;
}
$errorElements = array();
foreach ($errorMessages as $errorMessage) {
if (is_string($errorMarkup)) {
// it's a string with the HTML to insert
// %s is the placeholder in the HTML for the error message
$errorElement = $this->doc->createDocumentFragment();
$errorElement->appendXML(AgaviToolkit::expandVariables($errorMarkup, array('elementId' => htmlspecialchars($element->getAttribute('id'), ENT_QUOTES, 'UTF-8'), 'elementName' => htmlspecialchars($element->getAttribute('name'), ENT_QUOTES, 'UTF-8'), 'errorMessage' => htmlspecialchars($errorMessage, ENT_QUOTES, 'UTF-8'))));
} elseif (is_callable($errorMarkup)) {
// it's a callback we can use to get a DOMElement
// we give it the element as the first, and the error message as the second argument
$errorElement = call_user_func($errorMarkup, $element, $errorMessage);
$this->doc->importNode($errorElement, true);
} else {
throw new AgaviException('Form Population Filter was unable to insert an error message into the document using the XPath expression "' . $xpathExpression . '" because the element information could not be evaluated as an XML/HTML fragment or as a PHP callback.');
}
$errorElements[] = $errorElement;
}
if ($errorContainer) {
// we have an error container.
// that means that instead of inserting each message element, we add the messages into the container
// then, the container is the only element scheduled for insertion
$errorStrings = array();
// add all error XML strings to an array
foreach ($errorElements as $errorElement) {
$errorStrings[] = $errorElement->ownerDocument->saveXML($errorElement);
}
// create the container element and replace the errors placeholder in the container
if (is_string($errorContainer)) {
// it's a string with the HTML to insert
// %s is the placeholder in the HTML for the error message
$containerElement = $this->doc->createDocumentFragment();
$containerElement->appendXML(AgaviToolkit::expandVariables($errorContainer, array('elementId' => htmlspecialchars($element->getAttribute('id'), ENT_QUOTES, 'UTF-8'), 'elementName' => htmlspecialchars($element->getAttribute('name'), ENT_QUOTES, 'UTF-8'), 'errorMessages' => implode("\n", $errorStrings))));
} elseif (is_callable($errorContainer)) {
// it's a callback we can use to get a DOMElement
// we give it the element as the first, and the error messages array(!) as the second argument
$containerElement = call_user_func($errorContainer, $element, $errorStrings);
$this->doc->importNode($containerElement, true);
} else {
throw new AgaviException('Form Population Filter was unable to insert an error message container into the document using the XPath expression "' . $xpathExpression . '" because the element information could not be evaluated as an XML/HTML fragment or as a PHP callback.');
}
// and now the trick: set the error container element as the only one in the errorElements variable
// that way, it's going to get inserted for us as if it were a normal error message element, using the location specified
$errorElements = array($containerElement);
}
//.........这里部分代码省略.........
示例7: getResourceStreamIdentifier
/**
* Get the full, resolved stream location name to the template resource.
*
* @return string A PHP stream resource identifier.
*
* @throws AgaviException If the template could not be found.
*
* @author David Zülke <dz@bitxtender.com>
* @since 0.11.0
*/
public function getResourceStreamIdentifier()
{
$retval = null;
$template = $this->getParameter('template');
if ($template === null) {
// no template set, we return null so nothing gets rendered
return null;
} elseif (AgaviToolkit::isPathAbsolute($template)) {
// the template is an absolute path, ignore the dir
$directory = dirname($template);
$template = basename($template);
} else {
$directory = $this->getParameter('directory');
}
// treat the directory as sprintf format string and inject module name
$directory = AgaviToolkit::expandVariables($directory, array_merge(array_filter($this->getParameters(), 'is_scalar'), array_filter($this->getParameters(), 'is_null')));
$this->setParameter('directory', $directory);
$this->setParameter('template', $template);
if (!$this->hasParameter('extension')) {
$this->setParameter('extension', $this->renderer->getDefaultExtension());
}
// everything set up for the parent
return parent::getResourceStreamIdentifier();
}
示例8: evaluateModuleDirective
/**
* Evaluates a given AgaviConfig per-module directive using the given info.
*
* @param string The name of the module
* @param string The relevant name fragment of the directive
* @param array The variables to expand in the directive value.
*
* @return string The final value
*
* @author David Zülke <david.zuelke@bitextender.com>
* @since 1.0.0
*/
public static function evaluateModuleDirective($moduleName, $directiveNameFragment, $variables = array())
{
return AgaviToolkit::expandVariables(AgaviToolkit::expandDirectives(AgaviConfig::get(sprintf('modules.%s.%s', strtolower($moduleName), $directiveNameFragment))), $variables);
}
示例9: execute
/**
* Matches the input against the routing info and sets the info as request
* parameter.
*
* @return mixed An AgaviExecutionContainer as a result of this execution,
* or an AgaviResponse if a callback returned one.
*
* @author Dominik del Bondio <ddb@bitxtender.com>
* @since 0.11.0
*/
public function execute()
{
$rq = $this->context->getRequest();
$rd = $rq->getRequestData();
$tm = $this->context->getTranslationManager();
$container = $this->context->getController()->createExecutionContainer();
if (!$this->isEnabled()) {
// routing disabled, just bail out here
return $container;
}
$matchedRoutes = array();
$input = $this->input;
$vars = array();
$ot = null;
$locale = null;
$method = null;
$umap = $rq->getParameter('use_module_action_parameters');
$ma = $rq->getParameter('module_accessor');
$aa = $rq->getParameter('action_accessor');
$requestMethod = $rq->getMethod();
$routes = array();
// get all top level routes
foreach ($this->routes as $name => $route) {
if (!$route['opt']['parent']) {
$routes[] = $name;
}
}
// prepare the working stack with the root routes
$routeStack = array($routes);
do {
$routes = array_pop($routeStack);
foreach ($routes as $key) {
$route =& $this->routes[$key];
$opts =& $route['opt'];
if (count($opts['constraint']) == 0 || in_array($requestMethod, $opts['constraint'])) {
if (count($opts['callbacks']) > 0 && !isset($route['callback_instances'])) {
foreach ($opts['callbacks'] as $key => $callback) {
$instance = new $callback['class']();
$instance->initialize($this->context, $route);
$instance->setParameters($callback['parameters']);
$route['callback_instances'][$key] = $instance;
}
}
$match = array();
if ($this->parseInput($route, $input, $match)) {
$varsBackup = $vars;
// backup the container, must be done here already
if (count($opts['callbacks']) > 0) {
$containerBackup = $container;
$container = clone $container;
}
$ign = array();
if (count($opts['ignores']) > 0) {
$ign = array_flip($opts['ignores']);
}
foreach ($opts['defaults'] as $key => $value) {
if (!isset($ign[$key]) && $value->getValue()) {
$vars[$key] = $value->getValue();
}
}
foreach ($route['par'] as $param) {
if (isset($match[$param]) && $match[$param][1] != -1) {
$vars[$param] = $match[$param][0];
}
}
foreach ($match as $name => $m) {
if (is_string($name) && $m[1] != -1) {
$route['matches'][$name] = $m[0];
}
}
// /* ! Only use the parameters from this route for expandVariables !
// matches are arrays with value and offset due to PREG_OFFSET_CAPTURE, and we want index 0, the value, which reset() will give us. Long story short, this removes the offset from the individual match
$matchvals = array_map('reset', $match);
// */
/* ! Use the parameters from ALL routes for expandVariables !
$matchvals = $vars;
// ignores need of the current route need to be added
$foreach($opts['ignores'] as $ignore) {
if(isset($match[$ignore]) && $match[$ignore][1] != -1) {
$matchvals[$ignore] = $match[$ignore][0];
}
}
// */
if ($opts['module']) {
$module = AgaviToolkit::expandVariables($opts['module'], $matchvals);
$container->setModuleName($module);
if ($umap) {
$vars[$ma] = $module;
}
}
//.........这里部分代码省略.........
示例10: main
/**
* Executes the task.
*/
public function main()
{
if ($this->property === null) {
throw new BuildException('The property attribute must be specified');
}
if ($this->string === null) {
throw new BuildException('The string attribute must be specified');
}
$this->tryLoadAgavi();
$this->tryBootstrapAgavi();
$assigns = array();
foreach ($this->variables as $variable) {
$assigns[$variable->getName()] = $variable->getValue();
}
$result = AgaviToolkit::expandVariables($this->expandDirectives ? AgaviToolkit::expandDirectives($this->string) : $this->string, $assigns);
$this->project->setUserProperty($this->property, $result);
}
示例11: main
/**
* Executes the task.
*/
public function main()
{
if ($this->name === null) {
throw new BuildException('The name attribute must be specified');
}
$this->tryLoadAgavi();
$this->tryBootstrapAgavi();
/* Oookay. This is interesting. */
$moduleName = $this->name;
require_once AgaviConfigCache::checkConfig(sprintf('%s/%s/%s/%s/module.xml', (string) $this->project->getProperty('project.directory'), (string) $this->project->getProperty('project.directory.app.modules'), $this->name, (string) $this->project->getProperty('module.config.directory')));
/* Set up us the values.
*
* XXX: With regards to the defaults:
*
* You might expect to use the <property>.default properties defined in
* build.xml. But this is not so; consider that someone might have decided
* to upgrade their project properties but still have some legacy modules
* lying around. We need to use the actual Agavi defaults to ensure
* consistency.
*
* If you change this, you're fucking asking for it. */
$values = array();
$lowerModuleName = strtolower($moduleName);
$values['action.path'] = AgaviConfig::get(sprintf('modules.%s.agavi.action.path', $lowerModuleName), '%core.module_dir%/${moduleName}/actions/${actionName}Action.class.php');
$values['action.path'] = AgaviToolkit::expandVariables($values['action.path'], array('moduleName' => $moduleName));
$values['cache.path'] = AgaviConfig::get(sprintf('modules.%s.agavi.cache.path', $lowerModuleName), '%core.module_dir%/${moduleName}/cache/${actionName}.xml');
$values['cache.path'] = AgaviToolkit::expandVariables($values['cache.path'], array('moduleName' => $moduleName));
$values['templates.directory'] = AgaviConfig::get(sprintf('modules.%s.agavi.template.directory', $lowerModuleName), '%core.module_dir%/${module}/templates');
$values['templates.directory'] = AgaviToolkit::expandVariables($values['templates.directory'], array('module' => $moduleName));
$values['validate.path'] = AgaviConfig::get(sprintf('modules.%s.agavi.validate.path', $lowerModuleName), '%core.module_dir%/${moduleName}/validate/${actionName}.xml');
$values['validate.path'] = AgaviToolkit::expandVariables($values['validate.path'], array('moduleName' => $moduleName));
$values['view.path'] = AgaviConfig::get(sprintf('modules.%s.agavi.view.path', $lowerModuleName), '%core.module_dir%/${moduleName}/views/${viewName}View.class.php');
$values['view.path'] = AgaviToolkit::expandVariables($values['view.path'], array('moduleName' => $moduleName));
$values['view.name'] = AgaviConfig::get(sprintf('modules.%s.agavi.view.name', $lowerModuleName), '${actionName}${viewName}');
/* Main screen turn on. */
foreach ($values as $name => $value) {
$this->project->setUserProperty(sprintf('%s.%s', $this->prefix, $name), $value);
}
}