Skip to content

Commit 5c4445f

Browse files
committed
>> Refactor into psr-0, stage 2
1 parent 9767580 commit 5c4445f

File tree

66 files changed

+526
-466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+526
-466
lines changed

Maslosoft/Addendum/Addendum.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use CApplicationComponent;
66
use CCache;
7-
use EComponentMeta;
8-
use IAnnotated;
97
use Maslosoft\Addendum\Builder\DocComment;
8+
use Maslosoft\Addendum\Collections\Meta;
9+
use Maslosoft\Addendum\Interfaces\IAnnotated;
1010
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedClass;
1111
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedMethod;
1212
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedProperty;
@@ -49,7 +49,7 @@ public function hasAnnotations($class)
4949

5050
public function meta($component)
5151
{
52-
return EComponentMeta::create($component);
52+
return Meta::create($component);
5353
}
5454

5555
/**
@@ -72,7 +72,7 @@ public function annotate($class, $other = null)
7272
if(!$this->hasAnnotations($class))
7373
{
7474
$className = is_object($class) ? get_class($class) : $class;
75-
throw new ReflectionException(sprintf('To annotate class "%s", it must implement interface IAnnotated', $className));
75+
throw new ReflectionException(sprintf('To annotate class "%s", it must implement interface %s', $className, IAnnotated::class));
7676
}
7777
if(null !== $other)
7878
{

EValidatorAnnotation.php renamed to Maslosoft/Addendum/Base/ValidatorAnnotation.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<?php
22

3+
namespace Maslosoft\Addendum\Base;
4+
5+
use Maslosoft\Addendum\Collections\MetaAnnotation;
6+
37
/**
48
* Base class for validator annotations
59
*
610
* @author Piotr
711
*/
8-
abstract class EValidatorAnnotation extends EComponentMetaAnnotation
12+
abstract class ValidatorAnnotation extends MetaAnnotation
913
{
14+
1015
/**
1116
* @var string the user-defined error message. Different validators may define various
1217
* placeholders in the message that are to be replaced with actual values. All validators
@@ -51,8 +56,9 @@ abstract class EValidatorAnnotation extends EComponentMetaAnnotation
5156
public function init()
5257
{
5358
$name = preg_replace('~Annotation$~', '', lcfirst(get_class($this)));
54-
$value = array_intersect_key((array)$this, array_flip($this->_publicProperties));
59+
$value = array_intersect_key((array) $this, array_flip($this->_publicProperties));
5560
unset($value['name']);
5661
$this->_entity->$name = $value;
5762
}
58-
}
63+
64+
}
Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
<?php
2+
namespace Maslosoft\Addendum\Collections;
23

4+
use Maslosoft\Addendum\Interfaces\IAnnotated;
5+
use Maslosoft\Addendum\Interfaces\IMetaAnnotation;
36
use Maslosoft\Addendum\Reflection\ReflectionAnnotatedProperty;
7+
use ReflectionMethod;
8+
use ReflectionProperty;
9+
use Yii;
410

511
/**
612
* Description of EComponentMeta
7-
* @property EComponentMetaProperty $field
13+
* @property MetaProperty $field
814
* @author Piotr
915
*/
10-
class EComponentMeta
16+
class Meta
1117
{
1218
const Type = 1;
1319
const Field = 2;
@@ -30,9 +36,10 @@ protected function __construct(IAnnotated $component = null)
3036
// For example, for development annotation based extractor could be used, which could compile
3137
// Metadata to arrays, and for production environment, compiled arrays could be used
3238
$annotations = [];
33-
39+
3440
// Get reflection data
3541
$info = Yii::app()->addendum->annotate($component);
42+
3643
$properties = $info->getProperties(ReflectionProperty::IS_PUBLIC);
3744
$methods = $info->getMethods(ReflectionMethod::IS_PUBLIC);
3845

@@ -48,10 +55,10 @@ protected function __construct(IAnnotated $component = null)
4855
* OR add function to Annotation to setEntity, which should point to _field, _main or _method?
4956
*/
5057
// Setup class annotations
51-
$this->_type = new EComponentMetaType($info);
58+
$this->_type = new MetaType($info);
5259
foreach($info->getAllAnnotations() as $annotation)
5360
{
54-
if(!$annotation instanceof IComponentMetaAnnotation)
61+
if(!$annotation instanceof IMetaAnnotation)
5562
{
5663
continue;
5764
}
@@ -66,10 +73,10 @@ protected function __construct(IAnnotated $component = null)
6673
foreach($methods as $method)
6774
{
6875
$hasAnnotations = false;
69-
$methodMeta = new EComponentMetaMethod($method);
76+
$methodMeta = new MetaMethod($method);
7077
foreach($method->getAllAnnotations() as $annotation)
7178
{
72-
if(!$annotation instanceof IComponentMetaAnnotation)
79+
if(!$annotation instanceof IMetaAnnotation)
7380
{
7481
continue;
7582
}
@@ -100,7 +107,7 @@ protected function __construct(IAnnotated $component = null)
100107
{
101108
$name = $property->name;
102109
/* @var $property ReflectionAnnotatedProperty */
103-
$field = new EComponentMetaProperty($property);
110+
$field = new MetaProperty($property);
104111

105112
// Access options
106113
$field->callGet = isset($mes[$field->methodGet]) && $mes[$field->methodGet];
@@ -121,7 +128,7 @@ protected function __construct(IAnnotated $component = null)
121128

122129
foreach($property->getAllAnnotations() as $annotation)
123130
{
124-
if(!$annotation instanceof IComponentMetaAnnotation)
131+
if(!$annotation instanceof IMetaAnnotation)
125132
{
126133
continue;
127134
}
@@ -152,7 +159,7 @@ public static function __set_state($data)
152159
/**
153160
* Create flyghtweight instace of EComponentMeta
154161
* @param IAnnotated $component
155-
* @return EComponentMeta
162+
* @return Meta
156163
*/
157164
public static function create(IAnnotated $component)
158165
{
@@ -166,10 +173,11 @@ public static function create(IAnnotated $component)
166173
}
167174
else
168175
{
169-
self::$_instances[$id] = new self($component);
176+
self::$_instances[$id] = new Meta($component);
170177
self::_cacheSet($id, self::$_instances[$id]);
171178
}
172179
}
180+
173181
return self::$_instances[$id];
174182
}
175183

@@ -198,7 +206,7 @@ public function initModel(IAnnotated $component)
198206
* @param enum $type type of entities to return EComponentMeta::Type|EComponentMeta::Field|EComponentMeta::Method
199207
* @return type
200208
*/
201-
public function properties($fieldName, $type = EComponentMeta::Field)
209+
public function properties($fieldName, $type = Meta::Field)
202210
{
203211
$result = array();
204212
switch($type)
@@ -244,7 +252,7 @@ public function annotations($fieldName = null)
244252

245253
/**
246254
* Get class metadata
247-
* @return EComponentMetaType
255+
* @return MetaType
248256
*/
249257
public function type()
250258
{
@@ -253,7 +261,7 @@ public function type()
253261

254262
/**
255263
* Get all fields metadata with field name as key
256-
* @return EComponentMetaProperty[]
264+
* @return MetaProperty[]
257265
*/
258266
public function fields()
259267
{
@@ -263,7 +271,7 @@ public function fields()
263271
/**
264272
* Get field by name
265273
* @param string $name
266-
* @return EComponentMetaProperty
274+
* @return MetaProperty
267275
*/
268276
public function field($name)
269277
{
@@ -272,7 +280,7 @@ public function field($name)
272280

273281
/**
274282
* Get all methods metadata
275-
* @return EComponentMetaMethod[]
283+
* @return MetaMethod[]
276284
*/
277285
public function methods()
278286
{
@@ -282,7 +290,7 @@ public function methods()
282290
/**
283291
* Get method metadata by name
284292
* @param string $name
285-
* @return EComponentMetaMethod
293+
* @return MetaMethod
286294
*/
287295
public function method($name)
288296
{
@@ -296,7 +304,7 @@ public function method($name)
296304
/**
297305
* Get fields directly-like
298306
* @param string $name
299-
* @return EComponentMetaProperty|boolean
307+
* @return MetaProperty|boolean
300308
*/
301309
public function __get($name)
302310
{
@@ -323,7 +331,7 @@ private static function _getCacheKey($id)
323331
/**
324332
* Try to get metadata from cache
325333
* @param type $id
326-
* @return EComponentMeta|boolean
334+
* @return Meta|boolean
327335
*/
328336
private static function _cacheGet($id)
329337
{
@@ -343,10 +351,10 @@ private static function _cacheGet($id)
343351
/**
344352
* Set instance data to cache
345353
* @param string $id
346-
* @param EComponentMeta $value
347-
* @return EComponentMeta|boolean
354+
* @param Meta $value
355+
* @return Meta|boolean
348356
*/
349-
private static function _cacheSet($id, EComponentMeta $value)
357+
private static function _cacheSet($id, Meta $value)
350358
{
351359
if(!isset(Yii::app()->cache))
352360
{

EComponentMetaAnnotation.php renamed to Maslosoft/Addendum/Collections/MetaAnnotation.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<?php
22

3+
namespace Maslosoft\Addendum\Collections;
4+
35
use Maslosoft\Addendum\Annotation;
6+
use Maslosoft\Addendum\Interfaces\IAnnotationEntity;
7+
use Maslosoft\Addendum\Interfaces\IMetaAnnotation;
48

59
/**
6-
* Annotation used for EComponentMeta
10+
* Annotation used for Collections\Meta
711
* @author Piotr
812
*/
9-
abstract class EComponentMetaAnnotation extends Annotation implements IComponentMetaAnnotation
13+
abstract class MetaAnnotation extends Annotation implements IMetaAnnotation
1014
{
15+
1116
/**
1217
* Name of annotated field/method/class
1318
* @var string
@@ -16,7 +21,7 @@ abstract class EComponentMetaAnnotation extends Annotation implements IComponent
1621

1722
/**
1823
* Model metadata object
19-
* @var EComponentMeta
24+
* @var Meta
2025
*/
2126
protected $_meta = null;
2227

@@ -29,9 +34,9 @@ abstract class EComponentMetaAnnotation extends Annotation implements IComponent
2934

3035
/**
3136
* Set metada class to be accessible for annotation for init etc. methods
32-
* @param EComponentMeta $meta
37+
* @param Meta $meta
3338
*/
34-
public function setMeta(EComponentMeta $meta)
39+
public function setMeta(Meta $meta)
3540
{
3641
$this->_meta = $meta;
3742
}
@@ -52,6 +57,7 @@ public function setEntity(IAnnotationEntity $entity)
5257
*/
5358
public function afterInit()
5459
{
55-
60+
5661
}
57-
}
62+
63+
}

EComponentMetaMethod.php renamed to Maslosoft/Addendum/Collections/MetaMethod.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
2+
namespace Maslosoft\Addendum\Collections;
23

4+
use Maslosoft\Addendum\Interfaces\IAnnotationEntity;
5+
use ReflectionMethod;
36
/**
47
* Container for method metadata generated by method annotations
58
*
69
* @author Piotr
710
*/
8-
class EComponentMetaMethod implements IAnnotationEntity
11+
class MetaMethod implements IAnnotationEntity
912
{
1013
/**
1114
* Name of method

EComponentMetaProperty.php renamed to Maslosoft/Addendum/Collections/MetaProperty.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
2+
namespace Maslosoft\Addendum\Collections;
23

4+
use Maslosoft\Addendum\Interfaces\IAnnotationEntity;
5+
use ReflectionProperty;
36
/**
47
* Container for metadata generated by property annotations
58
*
69
* @author Piotr
710
*/
8-
class EComponentMetaProperty implements IAnnotationEntity
11+
class MetaProperty implements IAnnotationEntity
912
{
1013
// Access control
1114
/**

EComponentMetaType.php renamed to Maslosoft/Addendum/Collections/MetaType.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
<?php
22

3+
namespace Maslosoft\Addendum\Collections;
4+
5+
use Maslosoft\Addendum\Interfaces\IAnnotationEntity;
6+
use ReflectionClass;
7+
38
/**
49
* Container for class metadata generated by class annotations
510
*
611
* @author Piotr
712
*/
8-
class EComponentMetaType implements IAnnotationEntity
13+
class MetaType implements IAnnotationEntity
914
{
15+
1016
/**
1117
* Class name
1218
* @var string
@@ -20,7 +26,7 @@ class EComponentMetaType implements IAnnotationEntity
2026
public function __construct(ReflectionClass $info = null)
2127
{
2228
// For internal use
23-
if(null === $info)
29+
if (null === $info)
2430
{
2531
return;
2632
}
@@ -30,7 +36,7 @@ public function __construct(ReflectionClass $info = null)
3036
public static function __set_state($data)
3137
{
3238
$obj = new self(null);
33-
foreach($data as $field => $value)
39+
foreach ($data as $field => $value)
3440
{
3541
$obj->$field = $value;
3642
}
@@ -41,4 +47,5 @@ public function __get($name)
4147
{
4248
return null;
4349
}
44-
}
50+
51+
}

IAnnotated.php renamed to Maslosoft/Addendum/Interfaces/IAnnotated.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
namespace Maslosoft\Addendum\Interfaces;
33
/**
44
* This interface is to instruct annotation extensions to annotate object.
55
* Annotations will be evalueated only if this interface is implemented.

IAnnotationEntity.php renamed to Maslosoft/Addendum/Interfaces/IAnnotationEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
namespace Maslosoft\Addendum\Interfaces;
33
/**
44
* This interface is to indicate annotation entity container
55
* ie. contaner for field annotations, method annotations or class annotations

IBuiltInValidatorAnnotation.php renamed to Maslosoft/Addendum/Interfaces/IBuiltInValidatorAnnotation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
namespace Maslosoft\Addendum\Interfaces;
33
/**
44
* Interface to distinguish built-in validators from user validators
55
* @author Piotr

0 commit comments

Comments
 (0)