Drop::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * Platine Template
5
 *
6
 * Platine Template is a template engine that has taken a lot of inspiration from Django.
7
 *
8
 * This content is released under the MIT License (MIT)
9
 *
10
 * Copyright (c) 2020 Platine Template
11
 * Copyright (c) 2014 Guz Alexander, http://guzalexander.com
12
 * Copyright (c) 2011, 2012 Harald Hanek, http://www.delacap.com
13
 * Copyright (c) 2006 Mateo Murphy
14
 *
15
 * Permission is hereby granted, free of charge, to any person obtaining a copy
16
 * of this software and associated documentation files (the "Software"), to deal
17
 * in the Software without restriction, including without limitation the rights
18
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
 * copies of the Software, and to permit persons to whom the Software is
20
 * furnished to do so, subject to the following conditions:
21
 *
22
 * The above copyright notice and this permission notice shall be included in all
23
 * copies or substantial portions of the Software.
24
 *
25
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
 * SOFTWARE.
32
 */
33
34
/**
35
 *  @file Drop.php
36
 *
37
 *  The Template Drop class
38
 *
39
 *  @package    Platine\Template\Parser
40
 *  @author Platine Developers Team
41
 *  @copyright  Copyright (c) 2020
42
 *  @license    http://opensource.org/licenses/MIT  MIT License
43
 *  @link   https://www.platine-php.com
44
 *  @version 1.0.0
45
 *  @filesource
46
 */
47
48
declare(strict_types=1);
49
50
namespace Platine\Template\Parser;
51
52
use Stringable;
53
54
/**
55
 * @class Drop
56
 * @package Platine\Template\Parser
57
 *
58
 */
59
 /**
60
 * A drop is a class which allows you to export DOM like things to template.
61
 * Methods of drops are callable.
62
 * The main use for drops is the implement lazy loaded objects.
63
 * If you would like to make data available to the web designers which you don't
64
 * want loaded unless needed then a drop is a great way to do that.
65
 */
66
abstract class Drop implements Stringable
67
{
68
    /**
69
     * The context instance to use
70
     * @var Context
71
     */
72
    protected Context $context;
73
74
    /**
75
     * Set the context instance for future use
76
     * @param Context $context
77
     * @return $this
78
     */
79
    public function setContext(Context $context): self
80
    {
81
        $this->context = $context;
82
83
        return $this;
84
    }
85
86
    /**
87
     * Returns true if the drop supports the given method
88
     * @param string $key
89
     * @return bool
90
     */
91
    public function hasKey(string $key): bool
92
    {
93
        return true;
94
    }
95
96
    /**
97
     * Invoke a specific method
98
     * @param string $method
99
     * @return mixed
100
     */
101
    public function invokeDrop(string $method): mixed
102
    {
103
        $result = $this->beforeMethod($method);
104
        if ($result === null && is_callable([$this, $method])) {
105
            $result = $this->{$method}();
106
        }
107
108
        return $result;
109
    }
110
111
    /**
112
     * Return the current instance
113
     * @return $this
114
     */
115
    public function toObject(): self
116
    {
117
        return $this;
118
    }
119
120
    /**
121
     * The string representation of this class
122
     * @return string
123
     */
124
    public function __toString(): string
125
    {
126
        return get_class($this);
127
    }
128
129
    /**
130
     * Catch all method that is invoked before a specific method
131
     * @param string $method
132
     * @return mixed
133
     */
134
    protected function beforeMethod(string $method): mixed
135
    {
136
        return null;
137
    }
138
}
139