__call() public method

Handle dynamic method calls into the model.
public __call ( string $method, array $parameters ) : mixed
$method string
$parameters array
return mixed
Example #1
0
 /**
  * Handle polyglot dynamic method calls for locale relations.
  *
  * @param  string $method
  * @param  array  $parameters
  *
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     // If the model supports the locale, load it
     if (in_array($method, $this->getAvailable())) {
         return $this->hasOne($this->getLangClass())->whereLang($method);
     }
     return parent::__call($method, $parameters);
 }
 /**
  * Handle dynamic method calls into the method.
  *
  * @param string $method
  * @param array  $parameters
  *
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     // Unset method
     if ($method == 'unset') {
         return call_user_func_array([$this, 'drop'], $parameters);
     }
     return parent::__call($method, $parameters);
 }
Example #3
0
 public function __call($method, $parameters)
 {
     $className = class_basename($this);
     $config = implode('.', ['relationship', $className, $method]);
     if (Config::has($config)) {
         $function = Config::get($config);
         return $function($this);
     }
     return parent::__call($method, $parameters);
 }
Example #4
0
 /**
  * Handle dynamic method calls into the model.
  *
  * @param  string $method
  * @param  array  $parameters
  *
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     $relations = config('medialibrary.relations.attachment');
     if (array_has($relations, $method)) {
         return $this->morphedByMany($relations[$method], 'attachable', 'medialibrary_attachable');
     }
     if (starts_with($method, 'getUrl') && ends_with($method, 'Attribute') && $method !== 'getUrlAttribute') {
         return $this->getUrlAttribute(array_get($parameters, '0'));
     }
     return parent::__call($method, $parameters);
 }
Example #5
0
 public function __call($method, $parameters)
 {
     #i: Convert array to dot notation
     $config = implode('.', ['asgard.block.config.relations', $method]);
     #i: Relation method resolver
     if (config()->has($config)) {
         $function = config()->get($config);
         return $function($this);
     }
     #i: No relation found, return the call to parent (Eloquent) to handle it.
     return parent::__call($method, $parameters);
 }
Example #6
0
 public function __call($method, $args)
 {
     preg_match('"([a-z]+)[A-Z$]"', $method, $match);
     $prefix = @$match[1];
     if ($prefix == 'pick' || $prefix == 'paginate') {
         $picker = $this->pick(substr($method, strlen($prefix)), @$args[0] ?: 10);
         if ($prefix == 'paginate') {
             $picker = $picker->paginate();
         }
         return $picker;
     }
     return parent::__call($method, $args);
 }
Example #7
0
 /**
  *
  * @param type $name
  * @param type $args
  * @return type
  */
 public function __call($name, $args)
 {
     foreach ($this->items as $item) {
         switch ($item->behavior) {
             case 'relationship':
                 if ($name === $item->relationship->method) {
                     return $this->relationshipDefaultModel($item);
                 }
                 break;
         }
     }
     return parent::__call($name, $args);
 }
Example #8
0
 /**
  * Handle dynamic method calls into the method.
  *
  * @param  string  $method
  * @param  array   $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     if (substr($method, 0, 6) == "hasMtm") {
         $modelName = substr($method, 6);
         if (isset($parameters[1])) {
             array_push($parameters, $modelName);
         } else {
             array_push($parameters, null);
             array_push($parameters, $modelName);
         }
         return call_user_func_array(array($this, "hasMtm"), $parameters);
     }
     return parent::__call($method, $parameters);
 }
Example #9
0
 /**
  * Handle dynamic method calls into the method.
  * Overrided from {@link Eloquent} to implement recognition of the {@link $relationsData} array.
  *
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     if ($this->autohash_attributes) {
         foreach ($this->attributes_schema as $key => $value) {
             $method_name = 'set' . studly_case($key) . 'Attribute';
             if ($value == 'hashed' && $method_name == $method) {
                 $this->hashed_originals[$key] = $parameters[0];
                 $this->attributes[$key] = Hash::make($parameters[0]);
                 return;
             }
         }
     }
     if ($this->autoserialize_attributes) {
         foreach ($this->attributes_schema as $key => $value) {
             $method_name = 'set' . studly_case($key) . 'Attribute';
             if ($value == 'array' && $method_name == $method) {
                 $this->attributes[$key] = serialize((array) $parameters[0]);
                 return;
             }
             if ($value == 'object' && $method_name == $method) {
                 $this->attributes[$key] = serialize((object) $parameters[0]);
                 return;
             }
             $method_name = 'get' . studly_case($key) . 'Attribute';
             if ($value == 'array' && $method_name == $method || $value == 'object' && $method_name == $method) {
                 return unserialize($parameters[0]);
             }
         }
     }
     return parent::__call($method, $parameters);
 }
Example #10
0
 /**
  * Magic method allowing the use of associatedXXXX() to access relation object
  *
  * @param string $method
  * @param array $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     $proxy_methods = ['/^associated(.*)$/' => 'getAssociatedObject', '/^addAssociated(.*)$/' => 'addAssociatedObject', '/^countAssociated(.*)$/' => 'countAssociatedObject'];
     // Test each methods above to see if any match the name passed as parameter
     foreach ($proxy_methods as $regex => $method_name) {
         if (preg_match($regex, $method, $method_parameters)) {
             $parameters = array_merge(array_map('lcfirst', array_slice($method_parameters, 1)), $parameters);
             return call_user_func_array([$this, $method_name], $parameters);
         }
     }
     return parent::__call($method, $parameters);
 }
Example #11
0
 /**
  * @inheritdoc
  */
 public function __call($method, $arguments)
 {
     if ($relation = $this->getCustomRelation($method)) {
         return $relation;
     }
     return parent::__call($method, $arguments);
 }
Example #12
0
 /**
  * Check for and execute custom relationships.
  *
  * @param string $name
  * @param array $arguments
  * @return mixed
  */
 public function __call($name, $arguments)
 {
     if (isset(static::$relationships[$name])) {
         array_unshift($arguments, $this);
         return call_user_func_array(static::$relationships[$name], $arguments);
     }
     return parent::__call($name, $arguments);
 }
Example #13
0
 /**
  * Using extensions
  *
  * @param string $method
  * @param array $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     // Check method language
     if (in_array($method, static::$availableLanguages) && isset($parameters[0])) {
         return $this->getAttributeByLanguage($parameters[0], $method);
     }
     // Check extension methods
     if ($this->usesMethod($method)) {
         return $this->useMethod($method, $parameters);
     }
     // Check get attribute method
     if (substr($method, 0, 3) === 'get') {
         return $this->getAttribute(Str::snake(substr($method, 3, -strlen('attribute'))));
     }
     return parent::__call($method, $parameters);
 }
Example #14
0
 public function __call($method, $parameters)
 {
     $d = $this->getRelational($method);
     if ($d !== false) {
         return $d;
     }
     return parent::__call($method, $parameters);
 }
Example #15
0
 /**
  * Handle dynamic method calls into the method.
  * Overrided from {@link Eloquent} to implement recognition of the {@link $relationsData} array.
  *
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     if (array_key_exists($method, static::$relationsData)) {
         return $this->handleRelationalArray($method);
     }
     return parent::__call($method, $parameters);
 }
 /**
  * Handle dynamic method calls into the model.
  *
  * @param  string $method
  * @param  array  $parameters
  *
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     if (in_array($method, $this->relationsFields) and $relation = $this->getFieldRelation($method)) {
         return $relation;
     }
     return parent::__call($method, $parameters);
 }
Example #17
0
 /**
  * Handle dynamic method calls into the method.
  *
  * @param  string $method
  * @param  array $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     if ($attribute = $this->resolveAttribute($method)) {
         return $attribute;
     }
     if ($relationship = $this->resolveRelationship($method)) {
         return $relationship;
     }
     return parent::__call($method, $parameters);
 }
Example #18
0
 public function __call($method, $args = [])
 {
     $name = removeEndStr($method, static::$displayValueSuffix);
     if (ne_string($name) && in_array($name, static::getDisplayValueFields(), 1)) {
         return $this->displayValueMethod($name, $args);
     }
     if (in_array($method, static::getMethodsAsAttributeNames(), true)) {
         return call_user_func_array([$this, $method], $args);
     }
     return parent::__call($method, $args);
 }
Example #19
0
 /**
  * A little hack to reconnect to the database if we're in console mode and trying to find a deployment.
  * Should fix the error sending STMT_PREPARE problem that causes deployments to sit "pending" forever.
  * @return mixed
  */
 public function findOrFail()
 {
     if (App::runningInConsole()) {
         DB::reconnect();
     }
     return parent::__call('findOrFail', func_get_args());
 }
Example #20
0
 /**
  * @param string $method
  * @param array $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     // We will check if the method has video relation and create relationship dynamically
     if ($method == 'videos' && $this->allowsVideo()) {
         return $this->morphMany(Video::class, 'video', 'resource_model', 'resource_id')->orderBy('order', 'ASC');
     }
     return parent::__call($method, $parameters);
 }
Example #21
0
 /**
  * Dynamically pass missing methods to the permissions.
  *
  * @param  string  $method
  * @param  array  $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     $methods = ['hasAccess', 'hasAnyAccess'];
     if (in_array($method, $methods)) {
         $permissions = $this->getPermissionsInstance();
         return call_user_func_array([$permissions, $method], $parameters);
     }
     return parent::__call($method, $parameters);
 }
Example #22
0
 /**
  * Return relations
  *
  * @param string $name
  * @param array $arguments
  *
  * @return mixed
  */
 public function __call($name, $arguments) {
     if (isset($this->relations_rules[$name])){
         return $this->getRelationObject($name);
     }else {
         return parent::__call($name, $arguments);
     }
 }
 public function __call($method, $parameters)
 {
     if ($this->hasHook($hook = snake_case($method))) {
         return $this->call($hook, $parameters);
     }
     return parent::__call($method, $parameters);
 }
Example #24
0
 /**
  * Handle dynamic method calls into the model.
  *
  * @param  string $method
  * @param  array  $parameters
  *
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     if (method_exists($this->toWidget(), $method)) {
         return call_user_func_array([$this->toWidget(), $method], $parameters);
     }
     return parent::__call($method, $parameters);
 }