PluginProbe
FluentSnippets – High-Performance Code Snippets, Header & Footer Code, Custom CSS & PHP Code Manager / 1.1
FluentSnippets – High-Performance Code Snippets, Header & Footer Code, Custom CSS & PHP Code Manager v1.1
10.56 1.2.1 10 10.1 10.2 10.3 10.31 10.32 10.33 10.34 10.50 10.51 10.52 10.53 10.55 9.0 9.0.1 9.4 trunk 1.0.0 1.1 1.2
easy-code-manager / framework / events / definition.class.php

definition.class.php in FluentSnippets – High-Performance Code Snippets, Header & Footer Code, Custom CSS & PHP Code Manager 1.1, at framework/events/definition.class.php

110 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 /**
7 *
8 */
9 class CJTEventsDefinition {
10
11 /**
12 * put your comment there...
13 *
14 * @var mixed
15 */
16 protected $bases = array();
17
18 /**
19 * put your comment there...
20 *
21 * @var mixed
22 */
23 protected $definitions = array();
24
25 /**
26 * put your comment there...
27 *
28 */
29 public function __construct() {}
30
31 /**
32 * put your comment there...
33 *
34 * @param mixed $className
35 */
36 public function addBaseClass($className, $options = array()) {
37 $this->bases[$className] = $options;
38 // Chaining!
39 return $this;
40 }
41
42 /**
43 * put your comment there...
44 *
45 * @param mixed $class
46 * @param mixed $options
47 */
48 public function define($className, $options = array()) {
49 $definition = array();
50 $definition['options'] = $options;
51 // Get class properties to find out the events!
52 $class = new ReflectionClass($className);
53 $properties = $class->getProperties(ReflectionProperty::IS_PROTECTED);
54 $values = $class->getDefaultProperties();
55 // protected (static + non-static) represent an event!
56 foreach ($properties as $property) {
57 $propertyName = $property->getName();
58 $propertyClass = $property->getDeclaringClass()->getName();
59 if (strpos($propertyName, $options['prefix']) === 0) {
60 // Get event properties!
61 $eventName = substr($propertyName, strlen($options['prefix']));
62 // If the event is already defined inherits the options!
63 $inheritedOptions = array();
64 if (isset($this->definitions[$propertyClass]['events'][$propertyName])) {
65 $inheritedOptions = $this->definitions[$propertyClass]['events'][$propertyName]['type'];
66 }
67 $definition['events'][$propertyName] = array(
68 'fullName' => $propertyName,
69 'name' => $eventName,
70 'class' => $propertyClass,
71 'id' => $eventName,
72 'type' => array_merge($options, $inheritedOptions, ((array) $values[$propertyName]))
73 );
74 }
75 }
76 $this->definitions[$className] = $this->extend($definition);
77 return $this;
78 }
79
80 /**
81 * put your comment there...
82 *
83 * @param mixed $definition
84 */
85 protected function & extend(& $definition) {
86 // Extend events from all base classes!
87 foreach ($this->bases as $baseClassName => $options) {
88 $baseClass = $this->get($baseClassName);
89 // E_ALL complain!
90 if (isset($baseClass['events'])) {
91 foreach ($baseClass['events'] as $name => $event) {
92 $event['type'] = array_merge($event['type'], $options);
93 $definition['events'][$name] = $event;
94 }
95 }
96 }
97 return $definition;
98 }
99
100 /**
101 * put your comment there...
102 *
103 * @param mixed $class
104 */
105 public function get($class) {
106 return $this->definitions[$class];
107 }
108
109 } // End class.
110