Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
[TASK] Move code-snippet creation to new tool [11.5] (#532)
Browse files Browse the repository at this point in the history
* [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 <[email protected]>
  • Loading branch information
linawolf and linawolf authored Jul 12, 2022
1 parent 1ed8bbd commit d6c6a36
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -387,7 +387,7 @@ for example:

.. code-block:: php
:caption: extbase_example/Class/Controller/UserController.php
<?php
declare(strict_types=1);
Expand All @@ -410,7 +410,7 @@ for example:
}
Now there are two possibilities how validators can be
registered for domain objects:
registered for domain objects:

* directly in the model via ``@TYPO3\CMS\Extbase\Annotation\Validate`` annotation for single properties
* with an own validator class for complete domain objects.
Expand Down
17 changes: 17 additions & 0 deletions Documentation/CodeSnippets/PhpDomain/ValidatorInterface.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. Generated by https://github.com/linawolf/t3docs_restructured_api_tools
.. php:namespace:: TYPO3\CMS\Extbase\Validation\Validator
.. php:interface:: ValidatorInterface
Contract for a validator

.. php:method:: validate(unknown value)
Checks if the given value is valid according to the validator, and returns
the Error Messages object which occurred.

:param unknown $value: the value

.. php:method:: getOptions()
Returns the options of this validator which can be specified in the constructor

This file was deleted.

12 changes: 12 additions & 0 deletions Documentation/CodeSnippets/codesnippets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
// https://github.com/TYPO3-Documentation/t3docs-codesnippets
// ddev exec vendor/bin/typo3 restructured_api_tools:php_domain public/fileadmin/TYPO3CMS-Book-ExtbaseFluid/Documentation/CodeSnippets/

return [
[
"action"=> "createPhpClassDocs",
"class"=> \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class,
"targetFileName"=> "PhpDomain/ValidatorInterface.rst.txt",
"withCode"=> false
],
];

0 comments on commit d6c6a36

Please sign in to comment.