Array.php
1 year ago
Broken.php
1 year ago
ClassWithCtor.php
1 year ago
ComplexClassWithCtor.php
1 year ago
DependencyInjector.php
1 year ago
DerivedClass.php
1 year ago
DerivedClass2.php
1 year ago
FactoryMethod.php
1 year ago
FactoryMethodWithError.php
1 year ago
JsonMapperCommentsDiscardedException.php
1 year ago
JsonMapperForCheckingAllowedPaths.php
1 year ago
Logger.php
1 year ago
MapsWithSetters.php
1 year ago
Php7TypedClass.php
1 year ago
Php7_1TypedClass.php
1 year ago
PrivateWithSetter.php
1 year ago
Simple.php
1 year ago
SimpleBase.php
1 year ago
SimpleBaseWithMissingDiscrimType.php
1 year ago
ValueObject.php
1 year ago
FactoryMethod.php
121 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Part of JsonMapper |
| 4 | * |
| 5 | * PHP version 5 |
| 6 | * |
| 7 | * @package JsonMapper |
| 8 | * @author Mehdi Raza <mehdi.jaffery@apimatic.io> |
| 9 | * @license OSL-3.0 http://opensource.org/licenses/osl-3.0 |
| 10 | * @link https://apimatic.io/ |
| 11 | */ |
| 12 | |
| 13 | /** |
| 14 | * Unit test helper class for testing property mapping |
| 15 | * |
| 16 | * @package JsonMapper |
| 17 | * @author Mehdi Raza <mehdi.jaffery@apimatic.io> |
| 18 | * @license OSL-3.0 http://opensource.org/licenses/osl-3.0 |
| 19 | * @link https://apimatic.io/ |
| 20 | */ |
| 21 | class FactoryMethod |
| 22 | { |
| 23 | private $privateValue; |
| 24 | |
| 25 | /** |
| 26 | * @var string |
| 27 | */ |
| 28 | public $simple; |
| 29 | |
| 30 | /** |
| 31 | * @factory FactoryMethod::createFromValue |
| 32 | */ |
| 33 | public $value; |
| 34 | |
| 35 | /** |
| 36 | * @var bool |
| 37 | * @factory FactoryMethod::createFromInt |
| 38 | */ |
| 39 | public $bool; |
| 40 | |
| 41 | /** |
| 42 | * @factory FactoryMethod::createFromTimestamp |
| 43 | */ |
| 44 | public $datetime; |
| 45 | |
| 46 | /** |
| 47 | * @factory FactoryMethod::createObjectFromValue |
| 48 | */ |
| 49 | public $object; |
| 50 | |
| 51 | /** |
| 52 | * @factory FactoryMethod::createObjectFromValue |
| 53 | */ |
| 54 | public $objObj; |
| 55 | |
| 56 | /** |
| 57 | * @var int[] |
| 58 | * @factory FactoryMethod::createArrayFromArray |
| 59 | */ |
| 60 | public $array; |
| 61 | |
| 62 | /** |
| 63 | * @var int |
| 64 | * @factory FactoryMethod::createValueFromArray |
| 65 | */ |
| 66 | public $valueArr; |
| 67 | |
| 68 | /** |
| 69 | * @factory FactoryMethod::createFromValue |
| 70 | */ |
| 71 | public function setPrivateValue($val) |
| 72 | { |
| 73 | $this->privateValue = $val; |
| 74 | } |
| 75 | |
| 76 | public function getPrivateValue() |
| 77 | { |
| 78 | return $this->privateValue; |
| 79 | } |
| 80 | |
| 81 | public static function createFromValue($value) |
| 82 | { |
| 83 | return 'value is ' . $value; |
| 84 | } |
| 85 | |
| 86 | public static function createFromInt($value) |
| 87 | { |
| 88 | return $value === 1; |
| 89 | } |
| 90 | |
| 91 | public static function createFromTimestamp($value) |
| 92 | { |
| 93 | return new DateTime('@' . $value); |
| 94 | } |
| 95 | |
| 96 | public static function createObjectFromValue($value) |
| 97 | { |
| 98 | return new JsonMapperTest_ValueObject($value); |
| 99 | } |
| 100 | |
| 101 | public static function createArrayFromArray($value) |
| 102 | { |
| 103 | return array_map('FactoryMethod::cube', $value); |
| 104 | } |
| 105 | |
| 106 | public static function createValueFromArray($value) |
| 107 | { |
| 108 | $val = 0; |
| 109 | for ($i=0; $i < count($value); $i++) { |
| 110 | $val += $value[$i]; |
| 111 | } |
| 112 | return $val; |
| 113 | } |
| 114 | |
| 115 | public static function cube($n) |
| 116 | { |
| 117 | return($n * $n); |
| 118 | } |
| 119 | } |
| 120 | ?> |
| 121 |