|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the sauls/helpers package. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Saulius Vaičeliūnas <[email protected]> |
|
6
|
|
|
* @link http://saulius.vaiceliunas.lt |
|
7
|
|
|
* @copyright 2018 |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Sauls\Component\Helper; |
|
14
|
|
|
|
|
15
|
|
|
use Sauls\Component\Helper\Exception\ClassPropertyNotSetException; |
|
16
|
|
|
use Sauls\Component\Helper\Exception\PropertyNotAccessibleException; |
|
17
|
|
|
use Sauls\Component\Helper\Operation\Factory\OperationFactory; |
|
18
|
|
|
use Sauls\Component\Helper\Operation\ObjectOperation; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @throws PropertyNotAccessibleException |
|
22
|
|
|
*/ |
|
23
|
|
|
function define_object(object $object, array $properties, array $methodPrefixes = ['set', 'add']): object |
|
24
|
|
|
{ |
|
25
|
5 |
|
return (new ObjectOperation\DefineObject)->execute($object, $properties, $methodPrefixes); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @throws PropertyNotAccessibleException |
|
30
|
|
|
*/ |
|
31
|
|
|
function get_object_property_value(object $object, string $property, array $methodPrefixes = ['get', 'is']) |
|
32
|
|
|
{ |
|
33
|
2 |
|
return (new ObjectOperation\GetPropertyValue)->execute($object, $property, $methodPrefixes); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @throws ClassPropertyNotSetException |
|
38
|
|
|
*/ |
|
39
|
|
|
function set_object_property_value(object $object, string $property, $value): void |
|
40
|
|
|
{ |
|
41
|
2 |
|
(new ObjectOperation\SetPropertyValue)->execute($object, $property, $value); |
|
42
|
1 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
function object_ucnp(object $value): string |
|
45
|
|
|
{ |
|
46
|
2 |
|
return OperationFactory::create(ObjectOperation\Ucnp::class)->execute($value); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function object_to_array($object, array $properties = [], bool $recursive = true): array |
|
50
|
|
|
{ |
|
51
|
6 |
|
return OperationFactory::create(ObjectOperation\ToArray::class)->execute($object, $properties, $recursive); |
|
52
|
|
|
} |
|
53
|
|
|
|