Ejemplo n.º 1
0
 /**
  * Registers all object's events to matching methods
  * 
  * @param vBuilder\Object $object 
  */
 public function register(Nette\Object $object)
 {
     $rc = $object->getReflection();
     $rc2 = $this->getReflection();
     $publicProperties = $rc->getProperties(\ReflectionProperty::IS_PUBLIC);
     foreach ($publicProperties as $property) {
         $eventName = $property->getName();
         if (!preg_match('#^on[A-Z]#', $eventName)) {
             continue;
         }
         if ($rc2->hasMethod($eventName)) {
             array_push($object->{$eventName}, array($this, $eventName));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Register TextInputCustomLabel
  * @param  string $control_name string
  * @return void
  */
 public static function register($control_name = 'addTextCustomLabel')
 {
     Nette\Object::extensionMethod('Nette\\Forms\\Container::' . $control_name, function ($form, $name, $label = NULL, array $items = NULL) {
         $control = new self($label, $items);
         return $form[$name] = $control;
     });
 }
Ejemplo n.º 3
0
 public function __call($name, $args = [])
 {
     if (method_exists($this->acl, $name)) {
         return call_user_func_array([$this->acl, $name], $args);
     }
     return parent::__call($name, $args);
 }
Ejemplo n.º 4
0
 /**
  * Allows calling $column->icon() instead of $column->setIcon (Same for title, class, ...)
  * @param  string $name
  * @param  array  $args
  * @return mixed
  */
 public function __call($name, $args)
 {
     $method_setter = 'set' . ucfirst($name);
     if (method_exists($this, $method_setter)) {
         return Nette\Utils\Callback::invokeArgs([$this, $method_setter], $args);
     }
     parent::__call($name, $args);
 }
Ejemplo n.º 5
0
 /**
  * @param  string
  * @return string|NULL
  */
 public function &__get($name)
 {
     if (strtolower($name) === 'info') {
         return $this->info;
     } elseif (array_key_exists($name, $this->info)) {
         return $this->info[$name];
     }
     return parent::__get($name);
 }
Ejemplo n.º 6
0
 public function &__get($name)
 {
     $service = $this->getService($name, false);
     if ($service) {
         return $service;
     }
     $object = parent::__get($name);
     return $object;
 }
 public static function register($controlName = 'addMultiSelectFileChoicer')
 {
     if (!is_string($controlName)) {
         throw new Exception(sprintf('Control name must be string, %s given', gettype($controlName)));
     }
     Nette\Object::extensionMethod('Nette\\Forms\\Container::' . $controlName, function ($form, $name, IManager $mediaManager, $namespace, $label = null, $withPrimary = true) {
         return $form[$name] = new \vojtabiberle\MediaStorage\Bridges\Nette\Forms\Controls\MultiSelectFileChoicer($mediaManager, $namespace, $label, $withPrimary);
     });
 }
Ejemplo n.º 8
0
 public function &__get($name)
 {
     $val = \strtoupper($name);
     if (\defined(self::INFO . $val)) {
         $a = $this->getInfo(constant(self::INFO . $val));
         return $a;
     }
     return parent::__get($name);
 }
Ejemplo n.º 9
0
 /**
  * @param string $name
  * @return bool
  */
 public function __isset($name)
 {
     $isset = parent::__isset($name);
     if ($isset) {
         return TRUE;
     }
     $data = $this->getData();
     return isset($data[$name]);
 }
Ejemplo n.º 10
0
 /**
  * Returns user data value.
  * @param string property name
  * @return mixed
  */
 public function &__get($key)
 {
     if (parent::__isset($key)) {
         return parent::__get($key);
     } else {
         $data = $this->data->toArray();
         return $data[$key];
     }
 }
Ejemplo n.º 11
0
 /**
  * Register NotTranslatableSelectBox
  * @param  string $control_name string
  * @return void
  */
 public static function register($control_name = 'addNotTranslatableSelect')
 {
     Nette\Object::extensionMethod('Nette\\Forms\\Container::' . $control_name, function ($form, $name, $label = NULL, array $items = NULL, $size = NULL) {
         $control = new self($label, $items);
         if ($size > 1) {
             $control->setAttribute('size', (int) $size);
         }
         return $form[$name] = $control;
     });
 }
Ejemplo n.º 12
0
 public function __call($methodName, $args)
 {
     if (preg_match('|.*getModel([a-zA-Z0-9]+).*|', $methodName, $mtch)) {
         if (class_exists('Model\\' . $mtch[1] . 'Model')) {
             return $this->modelLoader->loadModel($mtch[1] . 'Model');
         }
     } else {
         return parent::__call($methodName, $args);
     }
 }
Ejemplo n.º 13
0
 /**
  * @param string $name
  * @param array $args
  * @return mixed
  */
 public function __call($name, $args)
 {
     $function = 'newrelic_' . self::convertCamelCaseToUnderscore($name);
     if (!extension_loaded('newrelic')) {
         return FALSE;
     }
     if (!function_exists($function)) {
         return parent::__call($name, $args);
     }
     return call_user_func_array($function, $args);
 }
Ejemplo n.º 14
0
 public function __call($name, $args)
 {
     if (preg_match('~^create(Select|Update|Delete|Insert)$~', $name, $m)) {
         #query object factory
         $class = "Flunorette\\Queries\\{$m[1]}Query";
         $queryContext = new QueryContext(reset($args), $this);
         return new $class($queryContext);
     }
     return parent::__call($name, $args);
 }
Ejemplo n.º 15
0
 /**
  * Call to undefined method.
  *
  * @param  string  method name
  * @param  array   arguments
  * @return mixed
  * @throws Nette\MemberAccessException
  */
 public function __call($name, $args)
 {
     $function = 'image' . $name;
     if (function_exists($function)) {
         foreach ($args as $key => $value) {
             if ($value instanceof self) {
                 $args[$key] = $value->getImageResource();
             } elseif (is_array($value) && isset($value['red'])) {
                 // rgb
                 $args[$key] = imagecolorallocatealpha($this->image, $value['red'], $value['green'], $value['blue'], $value['alpha']);
             }
         }
         array_unshift($args, $this->image);
         $res = call_user_func_array($function, $args);
         return is_resource($res) && get_resource_type($res) === 'gd' ? $this->setImageResource($res) : $res;
     }
     return parent::__call($name, $args);
 }
Ejemplo n.º 16
0
 /**
  * @param string $controlName
  * @throws ImageStorageException
  */
 public static function register($controlName = 'addMultiImageUpload')
 {
     if (!is_string($controlName)) {
         throw new ImageStorageException(sprintf('Control name must be a string, %s given', gettype($controlName)));
     }
     Object::extensionMethod(Container::class . '::' . $controlName, function ($form, $name, $label = NULL, $namespace = NULL) {
         $control = new self($label);
         $control->setNamespace($namespace);
         return $form[$name] = $control;
     });
 }
 /**
  * Is property defined?
  * @param  string  property name
  * @return bool
  */
 public function __isset($key)
 {
     return isset($this->data[$key]) || parent::__isset($key);
 }
Ejemplo n.º 18
0
 public function __unset($name)
 {
     if (parent::__isset($name)) {
         parent::__unset($name);
     } else {
         unset($this->data->{$name});
     }
 }
Ejemplo n.º 19
0
 /**
  * Call a template run-time helper. Do not call directly.
  * @param  string  helper name
  * @param  array   arguments
  * @return mixed
  */
 public function __call($name, $args)
 {
     $lname = strtolower($name);
     if (!isset($this->helpers[$lname])) {
         foreach ($this->helperLoaders as $loader) {
             $helper = Callback::invoke($loader, $lname);
             if ($helper) {
                 $this->registerHelper($lname, $helper);
                 return Callback::invokeArgs($this->helpers[$lname], $args);
             }
         }
         return parent::__call($name, $args);
     }
     return Callback::invokeArgs($this->helpers[$lname], $args);
 }
Ejemplo n.º 20
0
 public function __call($method, $args)
 {
     if (isset($this->proxyMethods[strtolower($method)])) {
         if (FindByParserHelper::parse($method, $args)) {
             return call_user_func([$this, $method], $args);
         }
         $result = call_user_func_array([$this->mapper, $method], $args);
         if (!($result instanceof ICollection || $result instanceof IEntity || $result === NULL)) {
             $result = $this->mapper->toCollection($result);
         }
         return $result;
     } else {
         return parent::__call($method, $args);
     }
 }
Ejemplo n.º 21
0
 /**
  * @param string $name
  * @param array $args
  * @return mixed
  * @throws IOException
  */
 public function __call($name, $args)
 {
     if (isset(self::$fileArg[$name])) {
         $dir = $this->dir;
         $args[self::$fileArg[$name]] = is_array($args[self::$fileArg[$name]]) ? array_map(function ($arg) use($dir) {
             return $dir . DIRECTORY_SEPARATOR . $arg;
         }, $args[self::$fileArg[$name]]) : $this->dir . DIRECTORY_SEPARATOR . $args[self::$fileArg[$name]];
         try {
             call_user_func_array(array($this->io, $name), $args);
             return $this;
         } catch (SfException $e) {
             throw new IOException($e->getMessage(), 0, $e);
         }
     }
     return parent::__call($name, $args);
 }
Ejemplo n.º 22
0
 public function &__get($name)
 {
     if ($this->entity) {
         try {
             $value = $this->entity->{$name};
             return $value;
         } catch (MemberAccessException $e) {
         }
     }
     return parent::__get($name);
 }
Ejemplo n.º 23
0
 /**
  * @param  string $name
  * @param  array $args
  * @return mixed
  */
 public function __call($name, $args)
 {
     if (strncmp($name, 'getBy', 5) === 0 && strlen($name) > 5) {
         $selection = $this->getTable()->limit(1);
         $properties = explode('And', substr($name, 5));
         if (count($properties) !== count($args)) {
             throw new Exception\InvalidArgumentException('Wrong number of argument passed to ' . $name . ' method - ' . count($properties) . ' expected, ' . count($args) . ' given.');
         }
         $ref = Reflection\EntityType::from($class = $this->getEntityClass());
         foreach ($properties as $key => $property) {
             $property = lcfirst($property);
             $prop = $ref->getEntityProperty($property);
             if ($prop === NULL) {
                 throw new Exception\InvalidArgumentException("Property '\${$property}' not found in entity '{$class}'.");
             }
             $selection->where($prop->getColumn(), $args[$key]);
         }
         return $this->createEntityFromSelection($selection);
     } elseif (strncmp($name, 'findBy', 6) === 0 && strlen($name) > 6) {
         $selection = $this->getTable();
         $properties = explode('And', substr($name, 6));
         if (count($properties) !== count($args)) {
             throw new Exception\InvalidArgumentException('Wrong number of argument passed to ' . $name . ' method - ' . count($properties) . ' expected, ' . count($args) . ' given.');
         }
         $criteria = [];
         $ref = Reflection\EntityType::from($class = $this->getEntityClass());
         foreach ($properties as $key => $property) {
             $property = lcfirst($property);
             $prop = $ref->getEntityProperty($property);
             if ($prop === NULL) {
                 throw new Exception\InvalidArgumentException("Property '\${$property}' not found in entity '{$class}'.");
             }
             $criteria[$prop->getColumn()] = $args[$key];
         }
         return $this->findBy($criteria);
     }
     return parent::__call($name, $args);
 }
Ejemplo n.º 24
0
 /**
  * Method overload for findBy...
  *
  * @param string $name
  * @param array $args
  * @return mixed
  * @throws InvalidArgumentException
  */
 public function __call($name, $args)
 {
     if (strncmp($name, 'findBy', 6) === 0 && strlen($name) > 6) {
         $entity = $args[0];
         unset($args[0]);
         return callback($this->getRepository($entity), $name)->invokeArgs($args);
     } else {
         return parent::__call($name, $args);
     }
 }
Ejemplo n.º 25
0
 /**
  * Performs calling "magic" methods from annotations.
  *
  * For example, annotation `method SomePage clickFoo()` defines a magic
  * method that calls `$this->foo->click()` and returns an object of type
  * `SomePage`. If `$this` is instance of that type, it will return `$this`.
  * Otherwise it instantiates a new object.
  *
  * Either way it calls the method {@see self::checkState()} afterwise on the
  * return object.
  *
  * The annotation may contain more return types, separated by vertical bar.
  * First that match is returned back.
  *
  * Another magic method is fillShortcut - if it is defined such a shortcut,
  * it will translate to `$this->shortcut->value($input)`, but it returns
  * `$this`.
  *
  * @param string $name Name of called method.
  * @param array $args
  * @return mixed
  */
 public function __call($name, $args)
 {
     if (!isset($this->methods)) {
         foreach ($this->getThisClasses() as $className) {
             $annotations = Utils::getClassAnnotations($className);
             $methodAnnotations = isset($annotations['method']) ? $annotations['method'] : array();
             foreach ($methodAnnotations as $methodAnnotation) {
                 if (preg_match('~^(?<type>[^\\s]+)\\s+(?<methodName>[^\\s(]+)~', $methodAnnotation, $matches)) {
                     $returnType = $matches['type'];
                     $fullMethodName = $matches['methodName'];
                     if (preg_match('~^(?<elementMethod>[[:lower:]]+)(?<elementShortcut>.*)~', $fullMethodName, $matches)) {
                         $elementMethod = $matches['elementMethod'];
                         $elementShortcut = isset($this->{$matches['elementShortcut']}) ? $matches['elementShortcut'] : lcfirst($matches['elementShortcut']);
                         if (isset($this->{$elementShortcut})) {
                             $this->methods[$fullMethodName] = array($elementShortcut, $elementMethod, $returnType, $className);
                         }
                     }
                 }
             }
         }
     }
     if (isset($this->methods[$name])) {
         $elementShortcut = $this->methods[$name][0];
         $elementMethod = $this->methods[$name][1];
         callback($this->{$elementShortcut}, $elementMethod)->invokeArgs($args);
         $this->session->waitForDocument();
         return $this->getNextPageFromList(explode('|', $this->methods[$name][2]), $this->methods[$name][3]);
     } elseif (substr($name, 0, 4) === 'fill' && (isset($this->{$shortcut = substr($name, 4)}) || isset($this->{$shortcut = lcfirst(substr($name, 4))}))) {
         callback($this->{$shortcut}, 'value')->invokeArgs($args);
         return $this;
     } else {
         return parent::__call($name, $args);
     }
 }
Ejemplo n.º 26
0
 /**
  * Allowing to emit static events through public variable
  *
  * @param string name
  * @param array of args
  * @return mixed
  */
 public static function __callStatic($name, $args)
 {
     $class = new Nette\Reflection\ClassType(get_called_class());
     $properties = $class->getStaticProperties();
     if (isset($properties[$name])) {
         if (is_array($list = $properties[$name]) || $list instanceof \Traversable) {
             foreach ($list as $handler) {
                 callback($handler)->invokeArgs($args);
             }
         }
         return NULL;
     }
     return parent::__callStatic($name, $args);
 }
Ejemplo n.º 27
0
	/**
	 * Call a template run-time helper. Do not call directly.
	 * @param  string  helper name
	 * @param  array   arguments
	 * @return mixed
	 */
	public function __call($name, $args)
	{
		$lname = strtolower($name);
		if (!isset($this->helpers[$lname])) {
			foreach ($this->helperLoaders as $loader) {
				$helper = $loader/*5.2*->invoke*/($lname);
				if ($helper) {
					$this->registerHelper($lname, $helper);
					return $this->helpers[$lname]->invokeArgs($args);
				}
			}
			return parent::__call($name, $args);
		}

		return $this->helpers[$lname]->invokeArgs($args);
	}
Ejemplo n.º 28
0
 /**
  * Magic function for getters / setters
  *
  * @param string variable name
  * @return mixed data
  *
  * @throws Nette\MemberAccessException if field doesn't exists or name is empty
  * @throws Nette\InvalidStateException if field with given key is not cached (and getter is called)
  */
 public function __call($name, $args)
 {
     $setMode = Nette\Utils\Strings::startsWith($name, "set");
     $getMode = Nette\Utils\Strings::startsWith($name, "get");
     $hasMode = Nette\Utils\Strings::startsWith($name, "has");
     if (($setMode || $getMode || $hasMode) && count($args) > 0) {
         if (mb_strlen($name) > 3) {
             // Musim data bacha na MB kodovani
             $fieldName = \mb_substr($name, 3);
             $fieldName = \mb_strtolower(\mb_substr($fieldName, 0, 1), 'UTF-8') . \mb_substr($fieldName, 1);
         } else {
             $fieldName = array_shift($args);
         }
         // Pokud jde o definovane pole
         if ($this->eMetadata->hasField($fieldName)) {
             if (!isset($this->data)) {
                 $this->loadData();
             }
             $ptr =& $this->data->table;
             foreach ($this->eMetadata->getIdFields() as $idField) {
                 if (count($args) == 0) {
                     throw new Nette\InvalidArgumentException("Missing primary key '{$idField}'");
                 }
                 $key = array_shift($args);
                 if (!isset($ptr[$key])) {
                     if ($setMode) {
                         $ptr[$key] = array();
                     } elseif ($hasMode) {
                         return false;
                     } else {
                         throw new Nette\InvalidStateException("Key '{$key}' not cached for '{$this->eClass}'");
                     }
                 }
                 $ptr =& $ptr[$key];
             }
             if ($getMode) {
                 return $ptr->{$fieldName};
             } elseif ($hasMode) {
                 return true;
             } else {
                 if (is_array($ptr)) {
                     $ptr = new \StdClass();
                 }
                 $ptr->{$fieldName} = count($args) ? array_shift($args) : NULL;
                 $this->cache->save('data', $this->data);
                 return;
             }
         }
     }
     parent::__call($name, $args);
 }
Ejemplo n.º 29
0
 /**
  * Magic unset from $this->data
  * @param string $name
  * @throws \Exception|\Nette\MemberAccessException
  */
 public function __unset($name)
 {
     try {
         parent::__unset($name);
     } catch (MemberAccessException $e) {
         if (isset($this->data[$name])) {
             unset($this->data[$name]);
             return;
         }
         throw $e;
     }
 }
Ejemplo n.º 30
0
 /**
  * Getter proměnných.
  * @param mixed $name
  * @return mixed
  */
 public function &__get($name)
 {
     return parent::__get($name);
 }