mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 02:16:41 +00:00
renamed blockExists to hasBlock
This commit is contained in:
@@ -40,7 +40,7 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
|
||||
{
|
||||
if ($this->getAttribute('is_defined_test')) {
|
||||
$compiler
|
||||
->raw('$this->blockExists(')
|
||||
->raw('$this->hasBlock(')
|
||||
->subcompile($this->getNode('name'))
|
||||
->raw(', $context, $blocks)')
|
||||
;
|
||||
|
||||
+26
-52
@@ -270,29 +270,40 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a block exists or not.
|
||||
* Returns whether a block exists or not in the current context of the template.
|
||||
*
|
||||
* This method is for internal use only and should never be called
|
||||
* directly.
|
||||
* This method checks blocks defined in the current template
|
||||
* or defined in "used" traits or defined in parent templates.
|
||||
*
|
||||
* This method does only return blocks defined in the current template
|
||||
* or defined in "used" traits.
|
||||
*
|
||||
* It does not return blocks from parent templates as the parent
|
||||
* template name can be dynamic, which is only known based on the
|
||||
* current context.
|
||||
*
|
||||
* @param string $name The block name
|
||||
* @param string $name The block name
|
||||
* @param array $context The context
|
||||
* @param array $blocks The current set of blocks
|
||||
*
|
||||
* @return bool true if the block exists, false otherwise
|
||||
*
|
||||
* @see blockExists
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function hasBlock($name)
|
||||
public function hasBlock($name, array $context = null, array $blocks = array())
|
||||
{
|
||||
return isset($this->blocks[(string) $name]);
|
||||
if (null === $context) {
|
||||
@trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED);
|
||||
|
||||
return isset($this->blocks[(string) $name]);
|
||||
}
|
||||
|
||||
if (isset($blocks[$name])) {
|
||||
return $blocks[$name][0] instanceof self;
|
||||
}
|
||||
|
||||
if (isset($this->blocks[$name])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (false !== $parent = $this->getParent($context)) {
|
||||
return $parent->hasBlock($name, $context);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,8 +314,6 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
*
|
||||
* @return array An array of block names
|
||||
*
|
||||
* @see hasBlock
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getBlockNames()
|
||||
@@ -351,8 +360,6 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
*
|
||||
* @return array An array of blocks
|
||||
*
|
||||
* @see hasBlock
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getBlocks()
|
||||
@@ -655,37 +662,4 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a block exists or not in the current context of the template.
|
||||
*
|
||||
* This method checks blocks defined in the current template
|
||||
* or defined in "used" traits or defined in parent templates.
|
||||
*
|
||||
* @param string $name The block name
|
||||
* @param array $context The context
|
||||
* @param array $blocks The current set of blocks
|
||||
*
|
||||
* @return bool true if the block exists, false otherwise
|
||||
*
|
||||
* @see hasBlock
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
protected function blockExists($name, array $context, array $blocks = array())
|
||||
{
|
||||
if (isset($blocks[$name])) {
|
||||
return $blocks[$name][0] instanceof self;
|
||||
}
|
||||
|
||||
if (isset($this->blocks[$name])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (false !== $parent = $this->getParent($context)) {
|
||||
return $parent->blockExists($name, $context);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user