/**
* Calls a method.
* Do not call this method directly. This is a PHP magic method that we override
* to allow behaviors, dynamic events (intra-object/behavior events),
* undefined dynamic and global events, and
* to allow using the following syntax to call a property setter or getter.
* <code>
* $this->getPropertyName($value); // if there's a $this->getjsPropertyName() method
* $this->setPropertyName($value); // if there's a $this->setjsPropertyName() method
* </code>
*
* Additional object behaviors override class behaviors.
* dynamic and global events do not fail even if they aren't implemented.
* Any intra-object/behavior dynamic events that are not implemented by the behavior
* return the first function paramater or null when no parameters are specified.
*
* @param string method name that doesn't exist and is being called on the object
* @param mixed method parameters
* @throws TInvalidOperationException If the property is not defined or read-only or
* method is undefined
* @return mixed result of the method call, or false if 'fx' or 'dy' function but
* is not found in the class, otherwise it runs
*/
public function __call($method, $args)
{
$getset = substr($method, 0, 3);
if ($getset == 'get' || $getset == 'set') {
$propname = substr($method, 3);
$jsmethod = $getset . 'js' . $propname;
if (method_exists($this, $jsmethod)) {
if (count($args) > 0) {
if ($args[0] && !$args[0] instanceof TJavaScriptString) {
$args[0] = new TJavaScriptString($args[0]);
}
}
return call_user_func_array(array($this, $jsmethod), $args);
}
if ($getset == 'set' && method_exists($this, 'getjs' . $propname)) {
throw new TInvalidOperationException('component_property_readonly', get_class($this), $method);
}
}
if ($this->_m !== null && $this->_behaviorsenabled) {
if (strncasecmp($method, 'dy', 2) === 0) {
$callchain = new TCallChain($method);
foreach ($this->_m->toArray() as $behavior) {
if ((!$behavior instanceof IBehavior || $behavior->getEnabled()) && (method_exists($behavior, $method) || $behavior instanceof IDynamicMethods)) {
$behavior_args = $args;
if ($behavior instanceof IClassBehavior) {
array_unshift($behavior_args, $this);
}
$callchain->addCall(array($behavior, $method), $behavior_args);
}
}
if ($callchain->getCount() > 0) {
return call_user_func_array(array($callchain, 'call'), $args);
}
} else {
foreach ($this->_m->toArray() as $behavior) {
if ((!$behavior instanceof IBehavior || $behavior->getEnabled()) && method_exists($behavior, $method)) {
if ($behavior instanceof IClassBehavior) {
array_unshift($args, $this);
}
return call_user_func_array(array($behavior, $method), $args);
}
}
}
}
if (strncasecmp($method, 'dy', 2) === 0 || strncasecmp($method, 'fx', 2) === 0) {
if ($this instanceof IDynamicMethods) {
return $this->__dycall($method, $args);
}
return isset($args[0]) ? $args[0] : null;
}
// don't thrown an exception for __magicMethods() or any other weird methods natively implemented by php
if (!method_exists($this, $method)) {
throw new TApplicationException('component_method_undefined', get_class($this), $method);
}
}