From d6c6a362fe625ebd530e5f7b89242083d33fe7af Mon Sep 17 00:00:00 2001 From: Lina Wolf <48202465+linawolf@users.noreply.github.com> Date: Tue, 12 Jul 2022 19:49:48 +0200 Subject: [PATCH] [TASK] Move code-snippet creation to new tool [11.5] (#532) * [TASK] Move code-snippet creation to new tool * [TASK] Move code-snippet creation to new tool (v 11.5) Move file so it aligns with main Co-authored-by: lina.wolf --- .../2-validating-domain-objects.rst | 16 +++---- .../PhpDomain/ValidatorInterface.rst.txt | 17 +++++++ .../StyleguideCode/ValidatorInterface.rst.txt | 44 ------------------- Documentation/CodeSnippets/codesnippets.php | 12 +++++ 4 files changed, 37 insertions(+), 52 deletions(-) create mode 100644 Documentation/CodeSnippets/PhpDomain/ValidatorInterface.rst.txt delete mode 100644 Documentation/CodeSnippets/StyleguideCode/ValidatorInterface.rst.txt create mode 100644 Documentation/CodeSnippets/codesnippets.php diff --git a/Documentation/9-CrosscuttingConcerns/2-validating-domain-objects.rst b/Documentation/9-CrosscuttingConcerns/2-validating-domain-objects.rst index 640ba20c..0ef197fd 100644 --- a/Documentation/9-CrosscuttingConcerns/2-validating-domain-objects.rst +++ b/Documentation/9-CrosscuttingConcerns/2-validating-domain-objects.rst @@ -39,7 +39,7 @@ A validator is a PHP class that has to check a certain invariant. All validators that are used in Extbase extensions have to implement the interface :php:`ValidatorInterface`: -.. include:: /CodeSnippets/StyleguideCode/ValidatorInterface.rst.txt +.. include:: /CodeSnippets/PhpDomain/ValidatorInterface.rst.txt This interface requires validators to implement two methods: @@ -54,15 +54,15 @@ The value to be validated is passed to the :php:validate() method where it's val The example below never returns anything but is using $this->addError() instead. No return-values are given for validate() although the interface states, that the method `validate` should return - a :php:`\TYPO3\CMS\Extbase\Error\Result` object. + a :php:`\TYPO3\CMS\Extbase\Error\Result` object. Most people who create custom validators extend the class :php:`\TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator`. Instead the bool method isValid is called. - This enables you to call the addError()` or `$this->addError($error, 1624260704)` + This enables you to call the addError()` or `$this->addError($error, 1624260704)` method and let the abstract - validator method `validate` take care of returning a proper result object + validator method `validate` take care of returning a proper result object of type `\TYPO3\CMS\Extbase\Error\Result` to the validation - framework. + framework. There are 2 types of validation checks: @@ -244,7 +244,7 @@ When you have created your own validator to check the invariants you can use it in the ``@TYPO3\CMS\Extbase\Annotation\Validate`` annotation using the full class name. -Example: +Example: .. code-block:: php :caption: blog_example/Class/Domain/Model/Post.php @@ -387,7 +387,7 @@ for example: .. code-block:: php :caption: extbase_example/Class/Controller/UserController.php - + "createPhpClassDocs", + "class"=> \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, + "targetFileName"=> "PhpDomain/ValidatorInterface.rst.txt", + "withCode"=> false + ], +];