Updating modules/cms/twig
This commit is contained in:
parent
e114f29582
commit
9c1dcb0dba
|
|
@ -43,4 +43,4 @@ class ComponentNode extends Twig_Node
|
|||
|
||||
$compiler->write("unset(\$context['__cms_component_params']);\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,11 @@ class ComponentTokenParser extends Twig_TokenParser
|
|||
break;
|
||||
|
||||
default:
|
||||
throw new Twig_Error_Syntax(sprintf('Invalid syntax in the partial tag. Line %s', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename());
|
||||
throw new Twig_Error_Syntax(
|
||||
sprintf('Invalid syntax in the partial tag. Line %s', $lineno),
|
||||
$stream->getCurrent()->getLine(),
|
||||
$stream->getFilename()
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -66,4 +70,4 @@ class ComponentTokenParser extends Twig_TokenParser
|
|||
{
|
||||
return 'component';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,4 +31,4 @@ class ContentNode extends Twig_Node
|
|||
->write(");\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,4 +39,4 @@ class ContentTokenParser extends Twig_TokenParser
|
|||
{
|
||||
return 'content';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,15 @@ class DebugExtension extends Twig_Extension
|
|||
*/
|
||||
protected $commentMap = [];
|
||||
|
||||
protected $blockMethods = ['componentDetails', 'defineProperties', 'getPropertyOptions', 'offsetExists', 'offsetGet', 'offsetSet', 'offsetUnset'];
|
||||
protected $blockMethods = [
|
||||
'componentDetails',
|
||||
'defineProperties',
|
||||
'getPropertyOptions',
|
||||
'offsetExists',
|
||||
'offsetGet',
|
||||
'offsetSet',
|
||||
'offsetUnset'
|
||||
];
|
||||
|
||||
/**
|
||||
* Creates the extension instance.
|
||||
|
|
@ -54,7 +62,11 @@ class DebugExtension extends Twig_Extension
|
|||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
new Twig_SimpleFunction('dump', [$this, 'runDump'], array('is_safe' => ['html'], 'needs_context' => true, 'needs_environment' => true)),
|
||||
new Twig_SimpleFunction('dump', [$this, 'runDump'], array(
|
||||
'is_safe' => ['html'],
|
||||
'needs_context' => true,
|
||||
'needs_environment' => true
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -84,8 +96,7 @@ class DebugExtension extends Twig_Extension
|
|||
}
|
||||
|
||||
$result .= $this->dump($vars, static::PAGE_CAPTION);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->variablePrefix = false;
|
||||
for ($i = 2; $i < $count; $i++) {
|
||||
$var = func_get_arg($i);
|
||||
|
|
@ -124,19 +135,21 @@ class DebugExtension extends Twig_Extension
|
|||
$info = [];
|
||||
|
||||
if (!is_array($variables)) {
|
||||
if ($variables instanceof Paginator)
|
||||
if ($variables instanceof Paginator) {
|
||||
$variables = $this->paginatorToArray($variables);
|
||||
elseif (is_object($variables))
|
||||
} elseif (is_object($variables)) {
|
||||
$variables = $this->objectToArray($variables);
|
||||
else
|
||||
} else {
|
||||
$variables = [$variables];
|
||||
}
|
||||
}
|
||||
|
||||
$output = [];
|
||||
$output[] = '<table>';
|
||||
|
||||
if ($caption)
|
||||
if ($caption) {
|
||||
$output[] = $this->makeTableHeader($caption);
|
||||
}
|
||||
|
||||
foreach ($variables as $key => $item) {
|
||||
$output[] = $this->makeTableRow($key, $item);
|
||||
|
|
@ -185,15 +198,12 @@ class DebugExtension extends Twig_Extension
|
|||
{
|
||||
if ($this->variablePrefix === true) {
|
||||
$output = '{{ <span>%s</span> }}';
|
||||
}
|
||||
elseif (is_array($this->variablePrefix)) {
|
||||
} elseif (is_array($this->variablePrefix)) {
|
||||
$prefix = implode('.', $this->variablePrefix);
|
||||
$output = '{{ <span>'.$prefix.'.%s</span> }}';
|
||||
}
|
||||
elseif ($this->variablePrefix) {
|
||||
} elseif ($this->variablePrefix) {
|
||||
$output = '{{ <span>'.$this->variablePrefix.'.%s</span> }}';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$output = '%s';
|
||||
}
|
||||
|
||||
|
|
@ -228,8 +238,9 @@ class DebugExtension extends Twig_Extension
|
|||
protected function getType($variable)
|
||||
{
|
||||
$type = gettype($variable);
|
||||
if ($type == 'string' && substr($variable, 0, 12) == '___METHOD___')
|
||||
if ($type == 'string' && substr($variable, 0, 12) == '___METHOD___') {
|
||||
return 'method';
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
|
@ -244,17 +255,15 @@ class DebugExtension extends Twig_Extension
|
|||
$class = get_class($variable);
|
||||
$label = class_basename($variable);
|
||||
|
||||
if ($variable instanceof ComponentBase)
|
||||
if ($variable instanceof ComponentBase) {
|
||||
$label = '<strong>Component</strong>';
|
||||
|
||||
elseif ($variable instanceof Collection)
|
||||
} elseif ($variable instanceof Collection) {
|
||||
$label = 'Collection('.$variable->count().')';
|
||||
|
||||
elseif ($variable instanceof Paginator)
|
||||
} elseif ($variable instanceof Paginator) {
|
||||
$label = 'Paged Collection('.$variable->count().')';
|
||||
|
||||
elseif ($variable instanceof Model)
|
||||
} elseif ($variable instanceof Model) {
|
||||
$label = 'Model';
|
||||
}
|
||||
|
||||
return '<abbr title="'.e($class).'">'.$label.'</abbr>';
|
||||
}
|
||||
|
|
@ -268,17 +277,21 @@ class DebugExtension extends Twig_Extension
|
|||
{
|
||||
$type = $this->getType($variable);
|
||||
|
||||
if ($type == 'method')
|
||||
if ($type == 'method') {
|
||||
return $this->evalMethodDesc($variable);
|
||||
}
|
||||
|
||||
if (isset($this->commentMap[$key]))
|
||||
if (isset($this->commentMap[$key])) {
|
||||
return $this->commentMap[$key];
|
||||
}
|
||||
|
||||
if ($type == 'array')
|
||||
if ($type == 'array') {
|
||||
return $this->evalArrDesc($variable);
|
||||
}
|
||||
|
||||
if ($type == 'object')
|
||||
if ($type == 'object') {
|
||||
return $this->evalObjDesc($variable);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
|
@ -291,8 +304,9 @@ class DebugExtension extends Twig_Extension
|
|||
protected function evalMethodDesc($variable)
|
||||
{
|
||||
$parts = explode('|', $variable);
|
||||
if (count($parts) < 2)
|
||||
if (count($parts) < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$method = $parts[1];
|
||||
return isset($this->commentMap[$method]) ? $this->commentMap[$method] : null;
|
||||
|
|
@ -370,13 +384,25 @@ class DebugExtension extends Twig_Extension
|
|||
|
||||
$methods = [];
|
||||
foreach ($info->getMethods() as $method) {
|
||||
if (!$method->isPublic()) continue; // Only public
|
||||
if ($method->class != $class) continue; // Only locals
|
||||
if (!$method->isPublic()) {
|
||||
continue; // Only public
|
||||
}
|
||||
if ($method->class != $class) {
|
||||
continue; // Only locals
|
||||
}
|
||||
$name = $method->getName();
|
||||
if (in_array($name, $this->blockMethods)) continue; // Blocked methods
|
||||
if (preg_match('/^on[A-Z]{1}[\w+]*$/', $name)) continue; // AJAX methods
|
||||
if (preg_match('/^get[A-Z]{1}[\w+]*Options$/', $name)) continue; // getSomethingOptions
|
||||
if (substr($name, 0, 1) == '_') continue; // Magic/hidden method
|
||||
if (in_array($name, $this->blockMethods)) {
|
||||
continue; // Blocked methods
|
||||
}
|
||||
if (preg_match('/^on[A-Z]{1}[\w+]*$/', $name)) {
|
||||
continue; // AJAX methods
|
||||
}
|
||||
if (preg_match('/^get[A-Z]{1}[\w+]*Options$/', $name)) {
|
||||
continue; // getSomethingOptions
|
||||
}
|
||||
if (substr($name, 0, 1) == '_') {
|
||||
continue; // Magic/hidden method
|
||||
}
|
||||
$name .= '()';
|
||||
$methods[$name] = '___METHOD___|'.$name;
|
||||
$this->commentMap[$name] = $this->evalDocBlock($method);
|
||||
|
|
@ -384,8 +410,12 @@ class DebugExtension extends Twig_Extension
|
|||
|
||||
$vars = [];
|
||||
foreach ($info->getProperties() as $property) {
|
||||
if (!$property->isPublic()) continue; // Only public
|
||||
if ($property->class != $class) continue; // Only locals
|
||||
if (!$property->isPublic()) {
|
||||
continue; // Only public
|
||||
}
|
||||
if ($property->class != $class) {
|
||||
continue; // Only locals
|
||||
}
|
||||
$name = $property->getName();
|
||||
$vars[$name] = $object->{$name};
|
||||
$this->commentMap[$name] = $this->evalDocBlock($property);
|
||||
|
|
@ -426,8 +456,9 @@ class DebugExtension extends Twig_Extension
|
|||
];
|
||||
|
||||
$type = gettype($variable);
|
||||
if ($type == 'NULL')
|
||||
if ($type == 'NULL') {
|
||||
$css['color'] = '#999';
|
||||
}
|
||||
|
||||
return $this->arrayToCss($css);
|
||||
}
|
||||
|
|
@ -484,5 +515,4 @@ class DebugExtension extends Twig_Extension
|
|||
|
||||
return join('; ', $strings);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,4 +28,4 @@ class DefaultNode extends Twig_Node
|
|||
->write("echo '<!-- X_OCTOBER_DEFAULT_BLOCK_CONTENT -->';\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,4 +41,4 @@ class DefaultTokenParser extends Twig_TokenParser
|
|||
{
|
||||
return 'default';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,8 +151,9 @@ class Extension extends Twig_Extension
|
|||
*/
|
||||
public function placeholderFunction($name, $default = null)
|
||||
{
|
||||
if (($result = Block::get($name)) === null)
|
||||
if (($result = Block::get($name)) === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = str_replace('<!-- X_OCTOBER_DEFAULT_BLOCK_CONTENT -->', trim($default), $result);
|
||||
return $result;
|
||||
|
|
@ -199,8 +200,9 @@ class Extension extends Twig_Extension
|
|||
*/
|
||||
public function displayBlock($name, $default = null)
|
||||
{
|
||||
if (($result = Block::placeholder($name)) === null)
|
||||
if (($result = Block::placeholder($name)) === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = str_replace('<!-- X_OCTOBER_DEFAULT_BLOCK_CONTENT -->', trim($default), $result);
|
||||
return $result;
|
||||
|
|
@ -213,4 +215,4 @@ class Extension extends Twig_Extension
|
|||
{
|
||||
Block::endBlock($append);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,8 +43,7 @@ class FlashNode extends Twig_Node
|
|||
->outdent()
|
||||
->write('}'.PHP_EOL)
|
||||
;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write('$context["type"] = ')
|
||||
|
|
@ -66,4 +65,4 @@ class FlashNode extends Twig_Node
|
|||
->write('$context["message"] = $_message;')
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,7 @@ class FlashTokenParser extends Twig_TokenParser
|
|||
|
||||
if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) {
|
||||
$name = $token->getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$name = 'all';
|
||||
}
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
|
@ -53,4 +52,4 @@ class FlashTokenParser extends Twig_TokenParser
|
|||
{
|
||||
return 'flash';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,14 +28,17 @@ class FrameworkNode extends Twig_Node
|
|||
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write("echo '<script src=\"'. Request::getBasePath() .'/modules/system/assets/js/framework.js\"></script>'.PHP_EOL;" . PHP_EOL)
|
||||
->write("echo '<script src=\"'. Request::getBasePath()
|
||||
.'/modules/system/assets/js/framework.js\"></script>'.PHP_EOL;" . PHP_EOL)
|
||||
;
|
||||
|
||||
if ($includeExtras) {
|
||||
$compiler
|
||||
->write("echo '<script src=\"'. Request::getBasePath() .'/modules/system/assets/js/framework.extras.js\"></script>'.PHP_EOL;" . PHP_EOL)
|
||||
->write("echo '<link href=\"'. Request::getBasePath() .'/modules/system/assets/css/framework.extras.css\" rel=\"stylesheet\">'.PHP_EOL;" . PHP_EOL)
|
||||
->write("echo '<script src=\"'. Request::getBasePath()
|
||||
.'/modules/system/assets/js/framework.extras.js\"></script>'.PHP_EOL;" . PHP_EOL)
|
||||
->write("echo '<link href=\"'. Request::getBasePath()
|
||||
.'/modules/system/assets/css/framework.extras.css\" rel=\"stylesheet\">'.PHP_EOL;" . PHP_EOL)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,4 +45,4 @@ class FrameworkTokenParser extends Twig_TokenParser
|
|||
{
|
||||
return 'framework';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,4 +39,4 @@ class Loader implements Twig_LoaderInterface
|
|||
{
|
||||
return $this->obj->isLoadedFromCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,4 +28,4 @@ class PageNode extends Twig_Node
|
|||
->write("echo \$this->env->getExtension('CMS')->pageFunction();\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ class PageTokenParser extends Twig_TokenParser
|
|||
{
|
||||
return 'page';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,4 +43,4 @@ class PartialNode extends Twig_Node
|
|||
|
||||
$compiler->write("unset(\$context['__cms_partial_params']);\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,11 @@ class PartialTokenParser extends Twig_TokenParser
|
|||
break;
|
||||
|
||||
default:
|
||||
throw new Twig_Error_Syntax(sprintf('Invalid syntax in the partial tag. Line %s', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename());
|
||||
throw new Twig_Error_Syntax(
|
||||
sprintf('Invalid syntax in the partial tag. Line %s', $lineno),
|
||||
$stream->getCurrent()->getLine(),
|
||||
$stream->getFilename()
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -70,4 +74,4 @@ class PartialTokenParser extends Twig_TokenParser
|
|||
{
|
||||
return 'partial';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ class PlaceholderNode extends Twig_Node
|
|||
public function __construct($name, $body, $lineno, $tag = 'placeholder')
|
||||
{
|
||||
$nodes = [];
|
||||
if ($body)
|
||||
if ($body) {
|
||||
$nodes['default'] = $body;
|
||||
}
|
||||
|
||||
parent::__construct($nodes, ['name'=>$name], $lineno, $tag);
|
||||
}
|
||||
|
|
@ -62,4 +63,4 @@ class PlaceholderNode extends Twig_Node
|
|||
->raw("'".$varId."'")
|
||||
->raw("]);");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,4 +60,4 @@ class PlaceholderTokenParser extends Twig_TokenParser
|
|||
{
|
||||
return 'placeholder';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,6 @@ class PutNode extends Twig_Node
|
|||
->write("echo \$this->env->getExtension('CMS')->endBlock(")
|
||||
->raw($isOverwrite ? 'false' : 'true')
|
||||
->write(");\n")
|
||||
;
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,4 +63,4 @@ class PutTokenParser extends Twig_TokenParser
|
|||
{
|
||||
return 'put';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,4 +29,4 @@ class ScriptsNode extends Twig_Node
|
|||
->write("echo \$this->env->getExtension('CMS')->displayBlock('scripts');\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,4 +38,4 @@ class ScriptsTokenParser extends Twig_TokenParser
|
|||
{
|
||||
return 'scripts';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,4 +29,4 @@ class StylesNode extends Twig_Node
|
|||
->write("echo \$this->env->getExtension('CMS')->displayBlock('styles');\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,4 +38,4 @@ class StylesTokenParser extends Twig_TokenParser
|
|||
{
|
||||
return 'styles';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue