Ejemplo n.º 1
0
 /**
  * Doctrine\ORM\EntityRepository.__call()と同じ動きで自前のfindBy関数を動かす
  *
  * @see Doctrine\ORM\EntityRepository::__call()
  */
 public function __call($method, $arguments)
 {
     $by = null;
     switch (true) {
         case 0 === strpos($method, 'findCountBy'):
             $by = substr($method, 11);
             $method = 'findCountBy';
             break;
     }
     // $by があれば、上記に定義した独自関数だったとする
     if (!is_null($by)) {
         $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
         if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) {
             switch (count($arguments)) {
                 case 1:
                     return $this->{$method}(array($fieldName => $arguments[0]));
                 case 2:
                     return $this->{$method}(array($fieldName => $arguments[0]), $arguments[1]);
                 case 3:
                     return $this->{$method}(array($fieldName => $arguments[0]), $arguments[1], $arguments[2]);
                 case 4:
                     return $this->{$method}(array($fieldName => $arguments[0]), $arguments[1], $arguments[2], $arguments[3]);
                 default:
                     // Do nothing
             }
         }
     }
     return parent::__call($method, $arguments);
 }
Ejemplo n.º 2
0
 public function __call($method, $args)
 {
     $result = $this->callTreeUtilMethods($method, $args);
     if (null !== $result) {
         return $result;
     }
     return parent::__call($method, $args);
 }
 /**
  * {@inheritdoc}
  */
 public function __call($method, $arguments)
 {
     if (0 === strpos($method, 'find')) {
         if (method_exists($this, $builder = 'build' . substr($method, 4))) {
             $qb = call_user_func_array(array($this, $builder), $arguments);
             if (0 === strpos(substr($method, 4), 'One')) {
                 return $qb->getQuery()->getOneOrNullResult();
             }
             return $qb->getQuery()->getResult();
         }
     }
     return parent::__call($method, $arguments);
 }
Ejemplo n.º 4
0
	/**
	 * Call to undefined method
	 *
	 * @param string  method name
	 * @param array   arguments
	 * @return mixed
	 * @throws \Nette\MemberAccessException
	 */
	public function __call($name, $args)
	{
		try {
			return parent::__call($name, $args);
		} catch (\BadMethodCallException $e) {
			return ObjectMixin::call($this, $name, $args);
		}
	}
Ejemplo n.º 5
0
 /**
  * Call to undefined method.
  *
  * @param string $name
  * @param array $args
  *
  * @throws \Nette\MemberAccessException
  * @return mixed
  */
 public function __call($name, $args)
 {
     if (strpos($name, 'findBy') === 0 || strpos($name, 'findOneBy') === 0) {
         return parent::__call($name, $args);
     }
     return ObjectMixin::call($this, $name, $args);
 }