Skip to content

Commit 817d35d

Browse files
committed
Pass the fields namespace as argument to MethodsDispatcher
1 parent 7427b91 commit 817d35d

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/Former/FormerServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function bindFormer(Container $app)
157157
});
158158

159159
$app->singleton('former', function ($app) {
160-
return new Former($app, new MethodDispatcher($app));
160+
return new Former($app, new MethodDispatcher($app, Former::FIELDSPACE));
161161
});
162162

163163
Helpers::setApp($app);

src/Former/MethodDispatcher.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,22 @@ class MethodDispatcher
1818
*/
1919
protected $app;
2020

21+
/**
22+
* Where fields classes are stored
23+
*
24+
* @var string
25+
*/
26+
protected $fields;
27+
2128
/**
2229
* Build a new Dispatcher
2330
*
2431
* @param Container $app
2532
*/
26-
public function __construct(Container $app)
33+
public function __construct(Container $app, $fields)
2734
{
28-
$this->app = $app;
35+
$this->app = $app;
36+
$this->fields = $fields;
2937
}
3038

3139
/**
@@ -154,7 +162,7 @@ public function toActions($method, $parameters)
154162
public function toFields($method, $parameters)
155163
{
156164
// Listing parameters
157-
$class = Former::FIELDSPACE.static::getClassFromMethod($method);
165+
$class = $this->fields.$this->getClassFromMethod($method);
158166
$field = new $class(
159167
$this->app,
160168
$method,
@@ -180,11 +188,11 @@ public function toFields($method, $parameters)
180188
*
181189
* @return string The correct class
182190
*/
183-
protected static function getClassFromMethod($method)
191+
protected function getClassFromMethod($method)
184192
{
185193
// If the field's name directly match a class, call it
186194
$class = Str::singular(Str::title($method));
187-
if (class_exists(Former::FIELDSPACE.$class)) {
195+
if (class_exists($this->fields.$class)) {
188196
return $class;
189197
}
190198

src/Former/Traits/Field.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ protected function currentFramework()
8484
public function __construct(Container $app, $type, $name, $label, $value, $attributes)
8585
{
8686
// Set base parameters
87-
$this->app = $app;
88-
$this->attributes = (array) $attributes;
89-
$this->type = $type;
90-
$this->value = $value;
91-
$this->form = $this->app->bound('former.form') ? $this->app['former.form'] : null;
87+
$this->app = $app;
88+
$this->type = $type;
89+
$this->value = $value;
90+
$this->setAttributes($attributes);
91+
$this->form = $this->app->bound('former.form') ? $this->app['former.form'] : null;
9292

9393
// Compute and translate label
9494
$this->automaticLabels($name, $label);

0 commit comments

Comments
 (0)