-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPythonDecorator.php
53 lines (51 loc) · 1.56 KB
/
PythonDecorator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Sagittaracc\PhpPythonDecorator;
/**
* Интерпретация PHP атрибута как Python декоратора
* @author Yuriy Arutyunyan <[email protected]>
*/
abstract class PythonDecorator
{
/**
* Ссылка на объект в котором применяется данный декоратор
* @var object
*/
protected object $object;
/**
* Название метода или свойства в объекте к которому применяется данный декоратор
* @var string
*/
protected ?string $propertyOrMethod;
/**
* Привязывается к методу или свойству объекта
* @param object $object
* @param ?string $propertyOrMethod
* @return static
*/
public function bindTo(object $object, ?string $propertyOrMethod = null): static
{
$this->object = $object;
$this->propertyOrMethod = $propertyOrMethod;
return $this;
}
/**
* @return object
*/
public function getObject(): object
{
return $this->object;
}
/**
* Получает название свойства или метода к которому привязан декоратор
* @return string
*/
public function getPropertyOrMethod(): string
{
return $this->propertyOrMethod;
}
/**
* Враппер декоратора
* @return mixed
*/
abstract public function wrapper(mixed $callback_or_object_or_property_or_value);
}