|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
5 |
* |
|
|
6 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
7 |
* you may not use this file except in compliance with the License. |
|
|
8 |
* You may obtain a copy of the License at |
|
|
9 |
* |
|
|
10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
|
11 |
* |
|
|
12 |
* Unless required by applicable law or agreed to in writing, software |
|
|
13 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
15 |
* See the License for the specific language governing permissions and |
|
|
16 |
* limitations under the License. |
|
|
17 |
*/ |
|
|
18 |
|
|
|
19 |
namespace Metadata; |
|
|
20 |
|
|
|
21 |
/** |
|
|
22 |
* Base class for class metadata. |
|
|
23 |
* |
|
|
24 |
* This class is intended to be extended to add your own application specific |
|
|
25 |
* properties, and flags. |
|
|
26 |
* |
|
|
27 |
* @author Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
28 |
*/ |
|
|
29 |
class ClassMetadata implements \Serializable |
|
|
30 |
{ |
|
|
31 |
public $name; |
|
|
32 |
public $reflection; |
|
|
33 |
public $methodMetadata = array(); |
|
|
34 |
public $propertyMetadata = array(); |
|
|
35 |
public $fileResources = array(); |
|
|
36 |
public $createdAt; |
|
|
37 |
|
|
|
38 |
public function __construct($name) |
|
|
39 |
{ |
|
|
40 |
$this->name = $name; |
|
|
41 |
|
|
|
42 |
$this->reflection = new \ReflectionClass($name); |
|
|
43 |
$this->createdAt = time(); |
|
|
44 |
} |
|
|
45 |
|
|
|
46 |
public function addMethodMetadata(MethodMetadata $metadata) |
|
|
47 |
{ |
|
|
48 |
$this->methodMetadata[$metadata->name] = $metadata; |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
public function addPropertyMetadata(PropertyMetadata $metadata) |
|
|
52 |
{ |
|
|
53 |
$this->propertyMetadata[$metadata->name] = $metadata; |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
public function isFresh($timestamp = null) |
|
|
57 |
{ |
|
|
58 |
if (null === $timestamp) { |
|
|
59 |
$timestamp = $this->createdAt; |
|
|
60 |
} |
|
|
61 |
|
|
|
62 |
foreach ($this->fileResources as $filepath) { |
|
|
63 |
if (!file_exists($filepath)) { |
|
|
64 |
return false; |
|
|
65 |
} |
|
|
66 |
|
|
|
67 |
if ($timestamp < filemtime($filepath)) { |
|
|
68 |
return false; |
|
|
69 |
} |
|
|
70 |
} |
|
|
71 |
|
|
|
72 |
return true; |
|
|
73 |
} |
|
|
74 |
|
|
|
75 |
public function serialize() |
|
|
76 |
{ |
|
|
77 |
return serialize(array( |
|
|
78 |
$this->name, |
|
|
79 |
$this->methodMetadata, |
|
|
80 |
$this->propertyMetadata, |
|
|
81 |
$this->fileResources, |
|
|
82 |
$this->createdAt, |
|
|
83 |
)); |
|
|
84 |
} |
|
|
85 |
|
|
|
86 |
public function unserialize($str) |
|
|
87 |
{ |
|
|
88 |
list( |
|
|
89 |
$this->name, |
|
|
90 |
$this->methodMetadata, |
|
|
91 |
$this->propertyMetadata, |
|
|
92 |
$this->fileResources, |
|
|
93 |
$this->createdAt |
|
|
94 |
) = unserialize($str); |
|
|
95 |
|
|
|
96 |
$this->reflection = new \ReflectionClass($this->name); |
|
|
97 |
} |
|
|
98 |
} |