/** * @param Scaffold $scaffold * @throws LogicException */ public function apply(Scaffold $scaffold) { $src = $scaffold->getInput('src'); $scaffold->excludeInput('src'); $class = null; $arg = null; if (is_object($src)) { if (is_a($src, '\\Illuminate\\Database\\Eloquent\\Builder')) { $class = '\\Nayjest\\Grids\\EloquentDataProvider'; $arg = $src; } elseif (is_a($src, '\\Doctrine\\DBAL\\Query\\QueryBuilder')) { $class = '\\Nayjest\\Grids\\DbalDataProvider'; $arg = $src; } } elseif (is_string($src)) { // model name if (class_exists($src, true) && is_subclass_of($src, '\\Illuminate\\Database\\Eloquent\\Model')) { $class = '\\Nayjest\\Grids\\EloquentDataProvider'; $model = new $src(); $arg = $model->newQuery(); } } if ($class !== null && $arg !== null) { $provider = new $class($arg); $scaffold->input['data_provider'] = $provider; } else { throw new LogicException('Invalid Data Provider Configuration'); } }
/** * {@inheritdoc} */ public function apply(Scaffold $scaffold) { if (!$this->overwrite && $scaffold->getInput($this->input_name)) { return; } $scaffold->input[$this->input_name] = $this->value; }
public function test() { $s1 = new Scaffold(null, []); $i = new Remove('field'); # must be no exceptions $i->apply($s1); $s2 = new Scaffold(null, ['field' => 1]); $this->assertEquals(1, $s2->getInput('field')); $i->apply($s2); $this->assertEquals(null, $s2->getInput('field')); }
public function apply(Scaffold $scaffold) { $value = $scaffold->getInput($this->input_name); if (null !== $value) { if ($this->is_exclusive) { $scaffold->excludeInput($this->input_name); } $this->applyInternal($value, $scaffold); } elseif (null !== $this->default) { $this->applyInternal($this->default, $scaffold); } }
/** * {@inheritdoc} */ public function apply(Scaffold $scaffold) { if (array_key_exists($this->input_name, $scaffold->input)) { $scaffold->excludeInput($this->input_name); } }