Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Anahkiasen committed Aug 3, 2014
1 parent bd923f7 commit 2324fa9
Show file tree
Hide file tree
Showing 61 changed files with 10,817 additions and 10,587 deletions.
24 changes: 12 additions & 12 deletions src/Former/Facades/Former.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
*/
class Former extends Facade
{
/**
* Get the registered component.
*
* @return object
*/
protected static function getFacadeAccessor()
{
if (!static::$app) {
static::$app = FormerServiceProvider::make();
}
/**
* Get the registered component.
*
* @return object
*/
protected static function getFacadeAccessor()
{
if (!static::$app) {
static::$app = FormerServiceProvider::make();
}

return 'former';
}
return 'former';
}
}
211 changes: 106 additions & 105 deletions src/Former/Form/Actions.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Former\Form;

use Former\Former;
use Former\Traits\FormerObject;
use Illuminate\Container\Container;
use Illuminate\Support\Str;
Expand All @@ -12,108 +11,110 @@
*/
class Actions extends FormerObject
{
/**
* The Container
*
* @var Container
*/
protected $app;

/**
* The Actions element
*
* @var string
*/
protected $element = 'div';

////////////////////////////////////////////////////////////////////
/////////////////////////// CORE METHODS ///////////////////////////
////////////////////////////////////////////////////////////////////

/**
* Constructs a new Actions block
*
* @param Container $app
* @param array $value The block content
*/
public function __construct(Container $app, $value)
{
$this->app = $app;
$this->value = $value;

// Add specific actions classes to the actions block
$this->addClass($this->app['former.framework']->getActionClasses());
}

/**
* Get the content of the Actions block
*
* @return string
*/
public function getContent()
{
$content = array_map(function ($content) {
return method_exists($content, '__toString') ? (string) $content : $content;
}, $this->value);

return $this->app['former.framework']->wrapActions( implode(' ', $content) );
}

/**
* Dynamically append actions to the block
*
* @param string $method The method
* @param array $parameters Its parameters
*
* @return Actions
*/
public function __call($method, $parameters)
{
// Dynamically add buttons to an actions block
if ($this->isButtonMethod($method)) {
$text = array_get($parameters, 0);
$link = array_get($parameters, 1);
$attributes = array_get($parameters, 2);
if (!$attributes and is_array($link)) $attributes = $link;
return $this->createButtonOfType($method, $text, $link, $attributes);
}

return parent::__call($method, $parameters);
}

////////////////////////////////////////////////////////////////////
////////////////////////////// HELPERS /////////////////////////////
////////////////////////////////////////////////////////////////////

/**
* Create a new Button and add it to the actions
*
* @param string $type The button type
* @param string $name Its name
* @param string $link A link to point to
* @param array $attributes Its attributes
*
* @return Actions
*/
private function createButtonOfType($type, $name, $link, $attributes)
{
$this->value[] = $this->app['former']->$type($name, $link, $attributes)->__toString();

return $this;
}

/**
* Check if a given method calls a button or not
*
* @param string $method The method to check
*
* @return boolean
*/
private function isButtonMethod($method)
{
$buttons = array('button', 'submit', 'link', 'reset');

return (bool) Str::contains($method, $buttons);
}

/**
* The Container
*
* @var Container
*/
protected $app;

/**
* The Actions element
*
* @var string
*/
protected $element = 'div';

////////////////////////////////////////////////////////////////////
/////////////////////////// CORE METHODS ///////////////////////////
////////////////////////////////////////////////////////////////////

/**
* Constructs a new Actions block
*
* @param Container $app
* @param array $value The block content
*/
public function __construct(Container $app, $value)
{
$this->app = $app;
$this->value = $value;

// Add specific actions classes to the actions block
$this->addClass($this->app['former.framework']->getActionClasses());
}

/**
* Get the content of the Actions block
*
* @return string
*/
public function getContent()
{
$content = array_map(function ($content) {
return method_exists($content, '__toString') ? (string) $content : $content;
}, $this->value);

return $this->app['former.framework']->wrapActions(implode(' ', $content));
}

/**
* Dynamically append actions to the block
*
* @param string $method The method
* @param array $parameters Its parameters
*
* @return Actions
*/
public function __call($method, $parameters)
{
// Dynamically add buttons to an actions block
if ($this->isButtonMethod($method)) {
$text = array_get($parameters, 0);
$link = array_get($parameters, 1);
$attributes = array_get($parameters, 2);
if (!$attributes and is_array($link)) {
$attributes = $link;
}

return $this->createButtonOfType($method, $text, $link, $attributes);
}

return parent::__call($method, $parameters);
}

////////////////////////////////////////////////////////////////////
////////////////////////////// HELPERS /////////////////////////////
////////////////////////////////////////////////////////////////////

/**
* Create a new Button and add it to the actions
*
* @param string $type The button type
* @param string $name Its name
* @param string $link A link to point to
* @param array $attributes Its attributes
*
* @return Actions
*/
private function createButtonOfType($type, $name, $link, $attributes)
{
$this->value[] = $this->app['former']->$type($name, $link, $attributes)->__toString();

return $this;
}

/**
* Check if a given method calls a button or not
*
* @param string $method The method to check
*
* @return boolean
*/
private function isButtonMethod($method)
{
$buttons = array('button', 'submit', 'link', 'reset');

return (bool) Str::contains($method, $buttons);
}
}
Loading

0 comments on commit 2324fa9

Please sign in to comment.