Completed
Push — feature/improve-form-definitio... ( 49be60...b9e9c1 )
by Romain
15:06
created

formDefinitionFrozenMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Exceptions;
15
16
use Romm\Formz\Form\FormObject\FormObject;
17
18
class PropertyNotAccessibleException extends FormzException
19
{
20
    const FIELD_NOT_ACCESSIBLE_IN_FORM = 'The form "%s" does not have an accessible property "%s". Please be sure this property exists, and it has a proper getter to access its value.';
21
22
    const FORM_INSTANCE_NOT_SET = 'The form instance is not accessible yet. You must use proxy methods after the form instance has been injected in the form object.';
23
24
    const FORM_DEFINITION_FROZEN_METHOD = 'Trying to call the method "%s::%s()" when the form definition has been frozen. If you need to modify the form definition, you must do it in the form object builder only.';
25
26
    const FORM_DEFINITION_FROZEN_PROPERTY = 'Trying to modify the property "%s::$%s" when the form definition has been frozen. If you need to modify the form definition, you must do it in the form object builder only.';
27
28
    /**
29
     * @code 1465243619
30
     *
31
     * @param FormObject $formObject
32
     * @param string     $fieldName
33
     * @return self
34
     */
35
    final public static function fieldViewHelperFieldNotAccessibleInForm(FormObject $formObject, $fieldName)
36
    {
37
        /** @var self $exception */
38
        $exception = self::getNewExceptionInstance(
39
            self::FIELD_NOT_ACCESSIBLE_IN_FORM,
40
            [$formObject->getClassName(), $fieldName]
41
        );
42
43
        return $exception;
44
    }
45
46
    /**
47
     * @code 1491815527
48
     *
49
     * @return self
50
     */
51
    final public static function formInstanceNotSet()
52
    {
53
        /** @var self $exception */
54
        $exception = self::getNewExceptionInstance(self::FORM_INSTANCE_NOT_SET);
55
56
        return $exception;
57
    }
58
59
    /**
60
     * @code 1494440357
61
     *
62
     * @param string $className
63
     * @param string $methodName
64
     * @return self
65
     */
66
    final public static function formDefinitionFrozenMethod($className, $methodName)
67
    {
68
        /** @var self $exception */
69
        $exception = self::getNewExceptionInstance(
70
            self::FORM_DEFINITION_FROZEN_METHOD,
71
            [$className, $methodName]
72
        );
73
74
        return $exception;
75
    }
76
77
    /**
78
     * @code 1494440395
79
     *
80
     * @param string $className
81
     * @param string $propertyName
82
     * @return self
83
     */
84
    final public static function formDefinitionFrozenProperty($className, $propertyName)
85
    {
86
        /** @var self $exception */
87
        $exception = self::getNewExceptionInstance(
88
            self::FORM_DEFINITION_FROZEN_PROPERTY,
89
            [$className, $propertyName]
90
        );
91
92
        return $exception;
93
    }
94
}
95