summaryrefslogtreecommitdiff
path: root/framework/TComponent.php
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2015-01-20 23:53:59 +0100
committerFabio Bas <ctrlaltca@gmail.com>2015-01-20 23:53:59 +0100
commitbbda6a710849a46de98937e85e96ea06abe333fd (patch)
tree8325563cd0e406f1f6347dc8ad29560240d16430 /framework/TComponent.php
parentca22da21b0cedab985e698f4dedf3ac1158a1487 (diff)
Once class per file: framework/*.php; removed pradolite
Diffstat (limited to 'framework/TComponent.php')
-rw-r--r--framework/TComponent.php677
1 files changed, 1 insertions, 676 deletions
diff --git a/framework/TComponent.php b/framework/TComponent.php
index 484a3186..57ab7003 100644
--- a/framework/TComponent.php
+++ b/framework/TComponent.php
@@ -1727,679 +1727,4 @@ class TComponent
$exprops[] = "\0TComponent\0_m";
return array_diff($a,$exprops);
}
-}
-
-
-/**
- * IDynamicMethods interface.
- * IDynamicMethods marks an object to receive undefined global or dynamic events.
- *
- * @author Brad Anderson <javalizard@mac.com>
- * @version $Id$
- * @package System
- * @since 3.2.3
- */
-interface IDynamicMethods
-{
- public function __dycall($method,$args);
-}
-
-
-
-/**
- * TClassBehaviorEventParameter class.
- * TClassBehaviorEventParameter is the parameter sent with the class behavior changes.
- *
- * @author Brad Anderson <javalizard@mac.com>
- * @version $Id$
- * @package System
- * @since 3.2.3
- */
-class TClassBehaviorEventParameter extends TEventParameter
-{
- private $_class;
- private $_name;
- private $_behavior;
- private $_priority;
-
- /**
- * Holds the parameters for the Class Behavior Events
- * @param string $class this is the class to get the behavior
- * @param string $name the name of the behavior
- * @param object $behavior this is the behavior to implement the class behavior
- */
- public function __construct($class,$name,$behavior,$priority)
- {
- $this->_class=$class;
- $this->_name=$name;
- $this->_behavior=$behavior;
- $this->_priority=$priority;
- }
-
- /**
- * This is the class to get the behavior
- * @return string the class to get the behavior
- */
- public function getClass()
- {
- return $this->_class;
- }
-
- /**
- * name of the behavior
- * @return string the name to get the behavior
- */
- public function getName()
- {
- return $this->_name;
- }
-
- /**
- * This is the behavior which the class is to get
- * @return object the behavior to implement
- */
- public function getBehavior()
- {
- return $this->_behavior;
- }
-
- /**
- * This is the priority which the behavior is to get
- * @return numeric the priority of the behavior
- */
- public function getPriority()
- {
- return $this->_priority;
- }
-}
-
-
-/**
- * TEnumerable class.
- * TEnumerable is the base class for all enumerable types.
- * To define an enumerable type, extend TEnumberable and define string constants.
- * Each constant represents an enumerable value.
- * The constant name must be the same as the constant value.
- * For example,
- * <code>
- * class TTextAlign extends TEnumerable
- * {
- * const Left='Left';
- * const Right='Right';
- * }
- * </code>
- * Then, one can use the enumerable values such as TTextAlign::Left and
- * TTextAlign::Right.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @package System
- * @since 3.0
- */
-class TEnumerable implements Iterator
-{
- private $_enums=array();
-
- public function __construct() {
- $reflection=new ReflectionClass($this);
- $this->_enums=$reflection->getConstants();
- }
-
- public function current() {
- return current($this->_enums);
- }
-
- public function key() {
- return key($this->_enums);
- }
-
- public function next() {
- return next($this->_enums);
- }
-
- public function rewind() {
- reset($this->_enums);
- }
-
- public function valid() {
- return $this->current()!==false;
- }
-}
-
-/**
- * TPropertyValue class
- *
- * TPropertyValue is a utility class that provides static methods
- * to convert component property values to specific types.
- *
- * TPropertyValue is commonly used in component setter methods to ensure
- * the new property value is of specific type.
- * For example, a boolean-typed property setter method would be as follows,
- * <code>
- * function setPropertyName($value) {
- * $value=TPropertyValue::ensureBoolean($value);
- * // $value is now of boolean type
- * }
- * </code>
- *
- * Properties can be of the following types with specific type conversion rules:
- * - string: a boolean value will be converted to 'true' or 'false'.
- * - boolean: string 'true' (case-insensitive) will be converted to true,
- * string 'false' (case-insensitive) will be converted to false.
- * - integer
- * - float
- * - array: string starting with '(' and ending with ')' will be considered as
- * as an array expression and will be evaluated. Otherwise, an array
- * with the value to be ensured is returned.
- * - object
- * - enum: enumerable type, represented by an array of strings.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @package System
- * @since 3.0
- */
-class TPropertyValue
-{
- /**
- * Converts a value to boolean type.
- * Note, string 'true' (case-insensitive) will be converted to true,
- * string 'false' (case-insensitive) will be converted to false.
- * If a string represents a non-zero number, it will be treated as true.
- * @param mixed the value to be converted.
- * @return boolean
- */
- public static function ensureBoolean($value)
- {
- if (is_string($value))
- return strcasecmp($value,'true')==0 || $value!=0;
- else
- return (boolean)$value;
- }
-
- /**
- * Converts a value to string type.
- * Note, a boolean value will be converted to 'true' if it is true
- * and 'false' if it is false.
- * @param mixed the value to be converted.
- * @return string
- */
- public static function ensureString($value)
- {
- if (TJavaScript::isJsLiteral($value))
- return $value;
- if (is_bool($value))
- return $value?'true':'false';
- else
- return (string)$value;
- }
-
- /**
- * Converts a value to integer type.
- * @param mixed the value to be converted.
- * @return integer
- */
- public static function ensureInteger($value)
- {
- return (integer)$value;
- }
-
- /**
- * Converts a value to float type.
- * @param mixed the value to be converted.
- * @return float
- */
- public static function ensureFloat($value)
- {
- return (float)$value;
- }
-
- /**
- * Converts a value to array type. If the value is a string and it is
- * in the form (a,b,c) then an array consisting of each of the elements
- * will be returned. If the value is a string and it is not in this form
- * then an array consisting of just the string will be returned. If the value
- * is not a string then
- * @param mixed the value to be converted.
- * @return array
- */
- public static function ensureArray($value)
- {
- if(is_string($value))
- {
- $value = trim($value);
- $len = strlen($value);
- if ($len >= 2 && $value[0] == '(' && $value[$len-1] == ')')
- {
- eval('$array=array'.$value.';');
- return $array;
- }
- else
- return $len>0?array($value):array();
- }
- else
- return (array)$value;
- }
-
- /**
- * Converts a value to object type.
- * @param mixed the value to be converted.
- * @return object
- */
- public static function ensureObject($value)
- {
- return (object)$value;
- }
-
- /**
- * Converts a value to enum type.
- *
- * This method checks if the value is of the specified enumerable type.
- * A value is a valid enumerable value if it is equal to the name of a constant
- * in the specified enumerable type (class).
- * For more details about enumerable, see {@link TEnumerable}.
- *
- * For backward compatibility, this method also supports sanity
- * check of a string value to see if it is among the given list of strings.
- * @param mixed the value to be converted.
- * @param mixed class name of the enumerable type, or array of valid enumeration values. If this is not an array,
- * the method considers its parameters are of variable length, and the second till the last parameters are enumeration values.
- * @return string the valid enumeration value
- * @throws TInvalidDataValueException if the original value is not in the string array.
- */
- public static function ensureEnum($value,$enums)
- {
- static $types=array();
- if(func_num_args()===2 && is_string($enums))
- {
- if(!isset($types[$enums]))
- $types[$enums]=new ReflectionClass($enums);
- if($types[$enums]->hasConstant($value))
- return $value;
- else
- throw new TInvalidDataValueException(
- 'propertyvalue_enumvalue_invalid',$value,
- implode(' | ',$types[$enums]->getConstants()));
- }
- else if(!is_array($enums))
- {
- $enums=func_get_args();
- array_shift($enums);
- }
- if(in_array($value,$enums,true))
- return $value;
- else
- throw new TInvalidDataValueException('propertyvalue_enumvalue_invalid',$value,implode(' | ',$enums));
- }
-
- /**
- * Converts the value to 'null' if the given value is empty
- * @param mixed value to be converted
- * @return mixed input or NULL if input is empty
- */
- public static function ensureNullIfEmpty($value)
- {
- return empty($value)?null:$value;
- }
-}
-
-/**
- * TEventParameter class.
- * TEventParameter is the base class for all event parameter classes.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @package System
- * @since 3.0
- */
-class TEventParameter extends TComponent
-{
-}
-
-class TEventResults extends TEnumerable {
- const EVENT_RESULT_FEED_FORWARD=1;
- const EVENT_RESULT_FILTER=2;
- const EVENT_RESULT_ALL=4;
-}
-
-/**
- * TComponentReflection class.
- *
- * TComponentReflection provides functionalities to inspect the public/protected
- * properties, events and methods defined in a class.
- *
- * The following code displays the properties and events defined in {@link TDataGrid},
- * <code>
- * $reflection=new TComponentReflection('TDataGrid');
- * Prado::varDump($reflection->getProperties());
- * Prado::varDump($reflection->getEvents());
- * </code>
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @package System
- * @since 3.0
- */
-class TComponentReflection extends TComponent
-{
- private $_className;
- private $_properties=array();
- private $_events=array();
- private $_methods=array();
-
- /**
- * Constructor.
- * @param object|string the component instance or the class name
- * @throws TInvalidDataTypeException if the object is not a component
- */
- public function __construct($component)
- {
- if(is_string($component) && class_exists($component,false))
- $this->_className=$component;
- else if(is_object($component))
- $this->_className=get_class($component);
- else
- throw new TInvalidDataTypeException('componentreflection_class_invalid');
- $this->reflect();
- }
-
- private function isPropertyMethod($method)
- {
- $methodName=$method->getName();
- return $method->getNumberOfRequiredParameters()===0
- && strncasecmp($methodName,'get',3)===0
- && isset($methodName[3]);
- }
-
- private function isEventMethod($method)
- {
- $methodName=$method->getName();
- return strncasecmp($methodName,'on',2)===0
- && isset($methodName[2]);
- }
-
- private function reflect()
- {
- $class=new ReflectionClass($this->_className);
- $properties=array();
- $events=array();
- $methods=array();
- $isComponent=is_subclass_of($this->_className,'TComponent') || strcasecmp($this->_className,'TComponent')===0;
- foreach($class->getMethods() as $method)
- {
- if($method->isPublic() || $method->isProtected())
- {
- $methodName=$method->getName();
- if(!$method->isStatic() && $isComponent)
- {
- if($this->isPropertyMethod($method))
- $properties[substr($methodName,3)]=$method;
- else if($this->isEventMethod($method))
- {
- $methodName[0]='O';
- $events[$methodName]=$method;
- }
- }
- if(strncmp($methodName,'__',2)!==0)
- $methods[$methodName]=$method;
- }
- }
- $reserved=array();
- ksort($properties);
- foreach($properties as $name=>$method)
- {
- $this->_properties[$name]=array(
- 'type'=>$this->determinePropertyType($method),
- 'readonly'=>!$class->hasMethod('set'.$name),
- 'protected'=>$method->isProtected(),
- 'class'=>$method->getDeclaringClass()->getName(),
- 'comments'=>$method->getDocComment()
- );
- $reserved['get'.strtolower($name)]=1;
- $reserved['set'.strtolower($name)]=1;
- }
- ksort($events);
- foreach($events as $name=>$method)
- {
- $this->_events[$name]=array(
- 'class'=>$method->getDeclaringClass()->getName(),
- 'protected'=>$method->isProtected(),
- 'comments'=>$method->getDocComment()
- );
- $reserved[strtolower($name)]=1;
- }
- ksort($methods);
- foreach($methods as $name=>$method)
- {
- if(!isset($reserved[strtolower($name)]))
- $this->_methods[$name]=array(
- 'class'=>$method->getDeclaringClass()->getName(),
- 'protected'=>$method->isProtected(),
- 'static'=>$method->isStatic(),
- 'comments'=>$method->getDocComment()
- );
- }
- }
-
- /**
- * Determines the property type.
- * This method uses the doc comment to determine the property type.
- * @param ReflectionMethod
- * @return string the property type, '{unknown}' if type cannot be determined from comment
- */
- protected function determinePropertyType($method)
- {
- $comment=$method->getDocComment();
- if(preg_match('/@return\\s+(.*?)\\s+/',$comment,$matches))
- return $matches[1];
- else
- return '{unknown}';
- }
-
- /**
- * @return string class name of the component
- */
- public function getClassName()
- {
- return $this->_className;
- }
-
- /**
- * @return array list of component properties. Array keys are property names.
- * Each array element is of the following structure:
- * [type]=>property type,
- * [readonly]=>whether the property is read-only,
- * [protected]=>whether the method is protected or not
- * [class]=>the class where the property is inherited from,
- * [comments]=>comments associated with the property.
- */
- public function getProperties()
- {
- return $this->_properties;
- }
-
- /**
- * @return array list of component events. Array keys are event names.
- * Each array element is of the following structure:
- * [protected]=>whether the event is protected or not
- * [class]=>the class where the event is inherited from.
- * [comments]=>comments associated with the event.
- */
- public function getEvents()
- {
- return $this->_events;
- }
-
- /**
- * @return array list of public/protected methods. Array keys are method names.
- * Each array element is of the following structure:
- * [protected]=>whether the method is protected or not
- * [static]=>whether the method is static or not
- * [class]=>the class where the property is inherited from,
- * [comments]=>comments associated with the event.
- */
- public function getMethods()
- {
- return $this->_methods;
- }
-}
-
-/**
- * IBaseBehavior interface is the base behavior class from which all other
- * behaviors types are derived
- *
- * @author Brad Anderson <javalizard@mac.com>
- * @version $Id$
- * @package System
- * @since 3.2.3
- */
-interface IBaseBehavior {
- /**
- * Attaches the behavior object to the component.
- * @param CComponent the component that this behavior is to be attached to.
- */
- public function attach($component);
- /**
- * Detaches the behavior object from the component.
- * @param CComponent the component that this behavior is to be detached from.
- */
- public function detach($component);
-}
-
-/**
- * IBehavior interfaces is implemented by instance behavior classes.
- *
- * A behavior is a way to enhance a component with additional methods and
- * events that are defined in the behavior class and not available in the
- * class. Objects may signal behaviors through dynamic events.
- *
- * @author Brad Anderson <javalizard@mac.com>
- * @version $Id$
- * @package System
- * @since 3.2.3
- */
-interface IBehavior extends IBaseBehavior
-{
- /**
- * @return boolean whether this behavior is enabled
- */
- public function getEnabled();
- /**
- * @param boolean whether this behavior is enabled
- */
- public function setEnabled($value);
-}
-
-
-/**
- * IClassBehavior interface is implements behaviors across all instances of
- * a particular class
- *
- * Any calls to functions not present in the original object but to behaviors
- * derived from this class, will have inserted as the first argument parameter
- * the object containing the behavior.
- *
- * For example:
- * <code>
- * $objWithClassBehavior->MethodOfClassBehavior(1, 20);
- * </code>
- * will be acted within the class behavior like this:
- * <code>
- * public function MethodOfClassBehavior($object, $firstParam, $secondParam){
- * // $object === $objWithClassBehavior, $firstParam === 1, $secondParam === 20
- * }
- * </code>
- *
- * This also holds for 'dy' events as well. For dynamic events, method arguments would be:
- * <code>
- * public function dyMethodOfClassBehavior($object, $firstParam, $secondParam, $callchain){
- * // $object === $objWithClassBehavior, $firstParam === 1, $secondParam === 20, $callchain instanceof {@link TCallChain}
- * }
- * </code>
- *
- * @author Brad Anderson <javalizard@mac.com>
- * @version $Id$
- * @package System
- * @since 3.2.3
- */
-interface IClassBehavior extends IBaseBehavior {
-}
-
-
-/**
- * IInstanceCheck This interface allows objects to determine their own
- * 'instanceof' results when {@link TComponent::isa} is called. This is
- * important with behaviors because behaviors may want to look like
- * particular objects other than themselves.
- *
- * @author Brad Anderson <javalizard@mac.com>
- * @version $Id$
- * @package System
- * @since 3.2.3
- */
-interface IInstanceCheck {
- /**
- * The method checks $this or, if needed, the parameter $instance is of type
- * class. In the case of a Class Behavior, the instance to which the behavior
- * is attached may be important to determine if $this is an instance
- * of a particular class.
- * @param class|string the component that this behavior is checking if it is an instanceof.
- * @param object the object which the behavior is attached to. default: null
- * @return boolean|null if the this or the instance is of type class. When null, no information could be derived and
- * the default mechanisms take over.
- */
- public function isinstanceof($class,$instance=null);
-}
-
-/**
- * TJavaScriptLiteral class that encloses string literals that are not
- * supposed to be escaped by {@link TJavaScript::encode() }
- *
- * Since Prado 3.2 all the data that gets sent clientside inside a javascript statement
- * is encoded by default to avoid any kind of injection.
- * Sometimes there's the need to bypass this encoding and send raw javascript code.
- * To ensure that a string doesn't get encoded by {@link TJavaScript::encode() },
- * construct a new TJavaScriptLiteral:
- * <code>
- * // a javascript test string
- * $js="alert('hello')";
- * // the string in $raw will not be encoded when sent clientside inside a javascript block
- * $raw=new TJavaScriptLiteral($js);
- * // shortened form
- * $raw=_js($js);
- * </code>
- *
- * @package System
- * @since 3.2.0
- */
-class TJavaScriptLiteral
-{
- protected $_s;
-
- public function __construct($s)
- {
- $this->_s = $s;
- }
-
- public function __toString()
- {
- return (string)$this->_s;
- }
-
- public function toJavaScriptLiteral()
- {
- return $this->__toString();
- }
-}
-
-/**
- * TJavaScriptString class is an internal class that marks strings that will be
- * forcibly encoded when rendered inside a javascript block
- *
- * @package System
- * @since 3.2.0
- */
-class TJavaScriptString extends TJavaScriptLiteral
-{
- public function toJavaScriptLiteral()
- {
- return TJavaScript::jsonEncode((string)$this->_s,JSON_HEX_QUOT | JSON_HEX_APOS | JSON_HEX_TAG);
- }
-}
-
+} \ No newline at end of file