Example #1
0
 /**
  * Add a plugin to a form.
  *
  * @param  string  $name
  * @param  array  $config
  * @return \Helmut\Forms\Plugin
  */
 public function addPlugin($name, $config = [])
 {
     $class = Str::studly($name);
     $class = '\\Plugins\\' . ucwords($class) . '\\' . ucwords($class);
     foreach ($this->namespaces as $namespace) {
         $plugin = $namespace . $class;
         if (class_exists($plugin)) {
             $this->plugins[$name] = new $plugin($config);
             $this->plugins[$name]->event($this, 'load');
             return $this->plugins[$name];
         }
     }
 }
Example #2
0
 /**
  * Gives this class the ability to set and get any of the
  * properties of the instances that inherit from this class
  * using shorthand notation. Call label() instead of
  * setLabel() for example.
  *
  * Also it allows you to specify validations in the same dynamic
  * manner like required() or between(1, 10).
  *
  * @param string  $method
  * @param array  $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     if (!method_exists($this, $method)) {
         $method = Str::studly($method);
         $name = 'set' . $method;
         if (method_exists($this, $name)) {
             return call_user_func_array([$this, $name], $parameters);
         }
         $name = 'validate' . $method;
         if (method_exists($this, $name)) {
             $arguments = Reflect::getParameters($this, $name);
             $parameters = array_pad($parameters, count($arguments), null);
             $this->validations[$name] = array_combine($arguments, $parameters);
             return $this;
         }
     }
 }
Example #3
0
 /**
  * Trigger an event callback. This allows
  * you to hook into events from within the plugin.
  * - onLoad
  * - onDefine
  * - onRender
  * - onSubmitted
  * - onCompleted
  * - onValidate
  * - onValidated
  * - onValid
  * - onInvalid
  *
  * @param  \Helmut\Forms\Form  $form
  * @param  string  $name
  * @param  array  $params
  * @return mixed
  */
 public function event($form, $name, $params = [])
 {
     $name = Str::studly($name);
     if (method_exists($this, 'on' . $name)) {
         return call_user_func_array(array($this, 'on' . $name), [$form, $params]);
     }
 }