Skip to content

Commit

Permalink
Update phpdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Nov 30, 2023
1 parent c7f20ab commit 99999e9
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/Extension/Attribute/AsTwigExtension.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<?php

namespace Twig\Extension\Attribute;
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Twig\TwigFilter;
namespace Twig\Extension\Attribute;

/**
* Identifies a class that uses PHP attributes to define filters, functions, or tests.
Expand Down
18 changes: 17 additions & 1 deletion src/Extension/Attribute/AsTwigFilter.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
<?php

/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Twig\Extension\Attribute;

use Twig\TwigFilter;

/**
* Registers a method as template filter.
*
* If the first argument of the method has Twig\Environment type-hint, the filter will receive the current environment.
* If the next argument of the method is named $context and has array type-hint, the filter will receive the current context.
* Additional arguments of the method come from the filter call.
*
* #[AsTwigFilter('foo')]
* function fooFilter(Environment $env, array $context, $string, $arg1 = null, ...) { ... }
*
* @see TwigFilter
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class AsTwigFilter
{
public function __construct(
/**
* The name of the filter in Twig
* The name of the filter in Twig.
*
* @var non-empty-string $name
*/
Expand Down
18 changes: 17 additions & 1 deletion src/Extension/Attribute/AsTwigFunction.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
<?php

/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Twig\Extension\Attribute;

use Twig\TwigFunction;

/**
* Registers a method as template function.
*
* If the first argument of the method has Twig\Environment type-hint, the function will receive the current environment.
* If the next argument of the method is named $context and has array type-hint, the function will receive the current context.
* Additional arguments of the method come from the function call.
*
* #[AsTwigFunction('foo')]
* function fooFunction(Environment $env, array $context, $string, $arg1 = null, ...) { ... }
*
* @see TwigFunction
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class AsTwigFunction
{
public function __construct(
/**
* The name of the function in Twig
* The name of the function in Twig.
*
* @var non-empty-string $name
*/
Expand Down
16 changes: 16 additions & 0 deletions src/Extension/Attribute/AsTwigTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
<?php

/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Twig\Extension\Attribute;

use Twig\TwigTest;

/**
* Registers a method as template test.
*
* If the first argument of the method has Twig\Environment type-hint, the test will receive the current environment.
* If the next argument of the method is named $context and has array type-hint, the test will receive the current context.
* The last argument of the method is the value to be tested, if any.
*
* #[AsTwigTest('foo')]
* public function fooTest(Environment $env, array $context, $value, $arg1 = null) { ... }
*
* @see TwigTest
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
Expand Down
6 changes: 3 additions & 3 deletions src/Extension/AttributeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function initFromAttributes()
foreach ($method->getAttributes(AsTwigFilter::class) as $attribute) {
$attribute = $attribute->newInstance();

$name = $attribute->name ?? $method->getName();
$name = $attribute->name;
if (isset($filters[$name])) {
throw new \LogicException(sprintf('Multiple definitions of the "%s" filter.', $name));
}
Expand Down Expand Up @@ -127,7 +127,7 @@ private function initFromAttributes()
foreach ($method->getAttributes(AsTwigFunction::class) as $attribute) {
$attribute = $attribute->newInstance();

$name = $attribute->name ?? $method->getName();
$name = $attribute->name;
if (isset($functions[$name])) {
throw new \LogicException(sprintf('Multiple definitions of the "%s" function.', $name));
}
Expand All @@ -154,7 +154,7 @@ private function initFromAttributes()
foreach ($method->getAttributes(AsTwigTest::class) as $attribute) {
$attribute = $attribute->newInstance();

$name = $attribute->name ?? $method->getName();
$name = $attribute->name;
if (isset($tests[$name])) {
throw new \LogicException(sprintf('Multiple definitions of the "%s" test.', $name));
}
Expand Down

0 comments on commit 99999e9

Please sign in to comment.