mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 14:58:43 +02:00
N°3567 - PHPDoc and coding conventions fixes
This commit is contained in:
@@ -15,8 +15,18 @@ use SetupUtils;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class UIBlockExtension
|
||||
*
|
||||
* @package Combodo\iTop\Application\TwigBase\UI
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class UIBlockExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTokenParsers()
|
||||
{
|
||||
$aParsers = [];
|
||||
@@ -31,7 +41,12 @@ class UIBlockExtension extends AbstractExtension
|
||||
return $aParsers;
|
||||
}
|
||||
|
||||
public static function GetClassForInterface($sInterface)
|
||||
/**
|
||||
* @param string $sInterface
|
||||
*
|
||||
* @return array|mixed
|
||||
*/
|
||||
public static function GetClassForInterface(string $sInterface)
|
||||
{
|
||||
$aFactoryClasses = [];
|
||||
|
||||
|
||||
@@ -16,6 +16,13 @@ use Twig\Error\SyntaxError;
|
||||
use Twig\Node\Node;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Class UIBlockNode
|
||||
*
|
||||
* @package Combodo\iTop\Application\TwigBase\UI
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class UIBlockNode extends Node
|
||||
{
|
||||
/** @var string */
|
||||
@@ -23,20 +30,26 @@ class UIBlockNode extends Node
|
||||
/** @var string */
|
||||
protected $sBlockClass;
|
||||
|
||||
public function __construct($sFactoryClass, $sBlockClass, $sType, $oParams, $oBody, $lineno = 0, $tag = null)
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct(string $sFactoryClass, string $sBlockClass, string $sType, $oParams, $oBody, int $iLineNo = 0, ?string $sTag = null)
|
||||
{
|
||||
parent::__construct(['body' => $oBody], ['type' => $sType, 'params' => $oParams], $lineno, $tag);
|
||||
parent::__construct(['body' => $oBody], ['type' => $sType, 'params' => $oParams], $iLineNo, $sTag);
|
||||
$this->sFactoryClass = $sFactoryClass;
|
||||
$this->sBlockClass = $sBlockClass;
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler)
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function compile(Compiler $oCompiler)
|
||||
{
|
||||
$aClassPath = explode("\\", $this->sBlockClass);
|
||||
$sClassName = end($aClassPath);
|
||||
$sBlockVar = str_replace('.', '', uniqid('o'.$sClassName.'_', true));
|
||||
$oParams = $this->getAttribute('params');
|
||||
$compiler
|
||||
$oCompiler
|
||||
->addDebugInfo($this)
|
||||
->write("\$sHtml = trim(ob_get_contents());\n")
|
||||
->write("ob_end_clean();\n")
|
||||
@@ -64,9 +77,9 @@ class UIBlockNode extends Node
|
||||
if ($oParameter->isOptional()) {
|
||||
$sDefault = $oParameter->getDefaultValue();
|
||||
$sDefault = var_export($sDefault, true);
|
||||
$compiler->write("\${$sName} = \$aParams['{$sName}'] ?? {$sDefault};\n");
|
||||
$oCompiler->write("\${$sName} = \$aParams['{$sName}'] ?? {$sDefault};\n");
|
||||
} else {
|
||||
$compiler
|
||||
$oCompiler
|
||||
->write("if (!isset(\$aParams['{$sName}'])) {\n")
|
||||
->indent()->write("throw new Exception('{$this->getTemplateName()}: Missing parameter {$sName} for {$this->getNodeTag()} at line {$this->getTemplateLine()}');\n")->outdent()
|
||||
->write("}\n")
|
||||
@@ -75,18 +88,18 @@ class UIBlockNode extends Node
|
||||
}
|
||||
|
||||
// Call the factory
|
||||
$compiler->write("\${$sBlockVar} = {$this->sFactoryClass}::Make{$sType}(");
|
||||
$oCompiler->write("\${$sBlockVar} = {$this->sFactoryClass}::Make{$sType}(");
|
||||
$bIsFirst = true;
|
||||
foreach ($aParameters as $oParameter) {
|
||||
$sName = $oParameter->getName();
|
||||
if ($bIsFirst) {
|
||||
$bIsFirst = false;
|
||||
} else {
|
||||
$compiler->write(", ");
|
||||
$oCompiler->write(", ");
|
||||
}
|
||||
$compiler->write("\${$sName}");
|
||||
$oCompiler->write("\${$sName}");
|
||||
}
|
||||
$compiler->write(");\n");
|
||||
$oCompiler->write(");\n");
|
||||
|
||||
// Call the setters if exists
|
||||
$aSetters = [];
|
||||
@@ -98,19 +111,19 @@ class UIBlockNode extends Node
|
||||
}
|
||||
}
|
||||
foreach ($aSetters as $sSetter) {
|
||||
$compiler
|
||||
$oCompiler
|
||||
->write("if (isset(\$aParams['{$sSetter}'])) {\n")
|
||||
->indent()->write("\${$sBlockVar}->Set{$sSetter}(\$aParams['{$sSetter}']);\n")->outdent()
|
||||
->write("}\n");
|
||||
}
|
||||
|
||||
// Attach to parent UIBlock
|
||||
$compiler->write("end(\$context['UIBlockParent'])->AddSubBlock(\${$sBlockVar});\n");
|
||||
$oCompiler->write("end(\$context['UIBlockParent'])->AddSubBlock(\${$sBlockVar});\n");
|
||||
|
||||
// Add sub UIBlocks
|
||||
$oSubNode = $this->getNode('body');
|
||||
if ($oSubNode) {
|
||||
$compiler
|
||||
$oCompiler
|
||||
->write("array_push(\$context['UIBlockParent'], \${$sBlockVar});\n")
|
||||
->write("ob_start();\n")
|
||||
->subcompile($oSubNode)
|
||||
@@ -121,6 +134,6 @@ class UIBlockNode extends Node
|
||||
->write("}\n")
|
||||
->write("array_pop(\$context['UIBlockParent']);\n");
|
||||
}
|
||||
$compiler->write("ob_start();\n");
|
||||
$oCompiler->write("ob_start();\n");
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,13 @@ namespace Combodo\iTop\Application\TwigBase\UI;
|
||||
use Twig\Token;
|
||||
use Twig\TokenParser\AbstractTokenParser;
|
||||
|
||||
/**
|
||||
* Class UIBlockParser
|
||||
*
|
||||
* @package Combodo\iTop\Application\TwigBase\UI
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @since 3.0.0
|
||||
*/
|
||||
class UIBlockParser extends AbstractTokenParser
|
||||
{
|
||||
/** @var string */
|
||||
@@ -41,9 +48,9 @@ class UIBlockParser extends AbstractTokenParser
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function parse(Token $token)
|
||||
public function parse(Token $sToken)
|
||||
{
|
||||
$iLineno = $token->getLine();
|
||||
$iLineno = $sToken->getLine();
|
||||
$oStream = $this->parser->getStream();
|
||||
|
||||
$sType = $oStream->expect(Token::NAME_TYPE)->getValue();
|
||||
@@ -70,8 +77,8 @@ class UIBlockParser extends AbstractTokenParser
|
||||
return $this->sTag;
|
||||
}
|
||||
|
||||
public function decideForEnd(Token $token)
|
||||
public function decideForEnd(Token $sToken)
|
||||
{
|
||||
return $token->test('End'.$this->sTag);
|
||||
return $sToken->test('End'.$this->sTag);
|
||||
}
|
||||
}
|
||||
@@ -8,16 +8,37 @@
|
||||
namespace Combodo\iTop\Application\UI\Base;
|
||||
|
||||
|
||||
/**
|
||||
* Class AbstractUIBlockFactory
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @since 3.0.0
|
||||
*/
|
||||
abstract class AbstractUIBlockFactory implements iUIBlockFactory
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @used-by static::GetTwigTagName()
|
||||
*/
|
||||
public const TWIG_TAG_NAME = 'UIBlock';
|
||||
public const UI_BLOCK_CLASS_NAME = "Combodo\\iTop\\Application\\UI\\Base\\UIBlock";
|
||||
/**
|
||||
* @var string
|
||||
* @useb-by static::GetUIBlockClassName()
|
||||
*/
|
||||
public const UI_BLOCK_CLASS_NAME = UIBlock::class;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function GetTwigTagName(): string
|
||||
{
|
||||
return static::TWIG_TAG_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function GetUIBlockClassName(): string
|
||||
{
|
||||
return static::UI_BLOCK_CLASS_NAME;
|
||||
|
||||
@@ -8,9 +8,22 @@
|
||||
namespace Combodo\iTop\Application\UI\Base;
|
||||
|
||||
|
||||
/**
|
||||
* Interface UIBlockNode
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Base
|
||||
* @author Eric Espie <eric.espie@combodo.com>
|
||||
* @since 3.0.0
|
||||
*/
|
||||
interface iUIBlockFactory
|
||||
{
|
||||
/**
|
||||
* @return string TWIG tag name that will be associated with this factory
|
||||
*/
|
||||
public static function GetTwigTagName(): string;
|
||||
|
||||
/**
|
||||
* @return string FQCN of the UIBlock produced by this factory
|
||||
*/
|
||||
public static function GetUIBlockClassName(): string;
|
||||
}
|
||||
Reference in New Issue
Block a user