Adds MacroableTrait to FormBuilder and HtmlBuilder

This commit is contained in:
Nicholas Ruunu committed 2014-02-27 11:45:39 +01:00
1 parent 50d7f44895
commit c0f9116999
2 files changed
+6 -76

No files matched your search

+3 -38
View File
@@ -2,9 +2,12 @@
use Illuminate\Routing\UrlGenerator; use Illuminate\Routing\UrlGenerator;
use Illuminate\Session\Store as Session; use Illuminate\Session\Store as Session;
use Illuminate\Support\Traits\MacroableTrait;
class FormBuilder { class FormBuilder {
use MacroableTrait;
/** /**
* The HTML builder instance. * The HTML builder instance.
* *
@@ -47,13 +50,6 @@ class FormBuilder {
*/ */
protected $labels = array(); protected $labels = array();
/**
* The registered form builder macros.
*
* @var array
*/
protected $macros = array();
/** /**
* The reserved form open attributes. * The reserved form open attributes.
* *
@@ -730,18 +726,6 @@ class FormBuilder {
return '<button'.$this->html->attributes($options).'>'.$value.'</button>'; return '<button'.$this->html->attributes($options).'>'.$value.'</button>';
} }
/**
* Register a custom form macro.
*
* @param string $name
* @param callable $macro
* @return void
*/
public function macro($name, $macro)
{
$this->macros[$name] = $macro;
}
/** /**
* Parse the form action method. * Parse the form action method.
* *
@@ -984,23 +968,4 @@ class FormBuilder {
return $this; return $this;
} }
/**
* Dynamically handle calls to the form builder.
*
* @param string $method
* @param array $parameters
* @return mixed
*
* @throws \BadMethodCallException
*/
public function __call($method, $parameters)
{
if (isset($this->macros[$method]))
{
return call_user_func_array($this->macros[$method], $parameters);
}
throw new \BadMethodCallException("Method {$method} does not exist.");
}
} }
+3 -38
View File
@@ -1,9 +1,12 @@
<?php namespace Illuminate\Html; <?php namespace Illuminate\Html;
use Illuminate\Routing\UrlGenerator; use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\Traits\MacroableTrait;
class HtmlBuilder { class HtmlBuilder {
use MacroableTrait;
/** /**
* The URL generator instance. * The URL generator instance.
* *
@@ -11,13 +14,6 @@ class HtmlBuilder {
*/ */
protected $url; protected $url;
/**
* The registered html macros.
*
* @var array
*/
protected $macros;
/** /**
* Create a new HTML builder instance. * Create a new HTML builder instance.
* *
@@ -29,18 +25,6 @@ class HtmlBuilder {
$this->url = $url; $this->url = $url;
} }
/**
* Register a custom HTML macro.
*
* @param string $name
* @param callable $macro
* @return void
*/
public function macro($name, $macro)
{
$this->macros[$name] = $macro;
}
/** /**
* Convert an HTML string to entities. * Convert an HTML string to entities.
* *
@@ -389,23 +373,4 @@ class HtmlBuilder {
return $safe; return $safe;
} }
/**
* Dynamically handle calls to the html class.
*
* @param string $method
* @param array $parameters
* @return mixed
*
* @throws \BadMethodCallException
*/
public function __call($method, $parameters)
{
if (isset($this->macros[$method]))
{
return call_user_func_array($this->macros[$method], $parameters);
}
throw new \BadMethodCallException("Method {$method} does not exist.");
}
} }