Skip to content

Commit

Permalink
Replace dependency injection (#108)
Browse files Browse the repository at this point in the history
* Remove HTML generators

* Do not use dependency injection
  • Loading branch information
jaesung2061 authored and kaidesu committed Sep 26, 2018
1 parent a8d588b commit e60eab1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 37 deletions.
26 changes: 9 additions & 17 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace Caffeinated\Menus;

use BadMethodCallException;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\Str;

class Builder
Expand Down Expand Up @@ -37,23 +36,16 @@ class Builder
*/
protected $lastId;

/**
* @var Illuminate\Routing\UrlGenerator
*/
protected $url;

/**
* Create a new Builder instance.
*
* @param string $name
* @param array $config
* @param Illuminate\Routing\UrlGenerator $url
* @param string $name
* @param array $config
*/
public function __construct($name, $config, UrlGenerator $url)
public function __construct($name, $config)
{
$this->name = $name;
$this->config = $config;
$this->url = $url;
$this->items = new Collection;
}

Expand Down Expand Up @@ -314,14 +306,14 @@ protected function getUrl($options)
return $url[0];
}

return $this->url->to($prefix.$url[0], array_slice($url, 1), $secure);
return url()->to($prefix.$url[0], array_slice($url, 1), $secure);
}

if (self::isAbsolute($url)) {
return $url;
}

return $this->url->to($prefix.$url, array(), $secure);
return url()->to($prefix.$url, array(), $secure);
}

/**
Expand All @@ -334,10 +326,10 @@ protected function getUrl($options)
protected function getRoute($route)
{
if (is_array($route)) {
return $this->url->route($route[0], array_slice($route, 1));
return url()->route($route[0], array_slice($route, 1));
}

return $this->url->route($route);
return url()->route($route);
}

/**
Expand All @@ -350,10 +342,10 @@ protected function getRoute($route)
protected function getAction($action)
{
if (is_array($action)) {
return $this->url->action($action[0], array_slice($action, 1));
return url()->action($action[0], array_slice($action, 1));
}

return $this->url->action($action);
return url()->action($action);
}

/**
Expand Down
22 changes: 3 additions & 19 deletions src/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
namespace Caffeinated\Menus;

use Illuminate\Config\Repository;
use Illuminate\Routing\UrlGenerator;
use Illuminate\View\Factory;

class Menu
{
Expand All @@ -17,28 +15,14 @@ class Menu
*/
protected $config;

/**
* @var \Illuminate\Routing\UrlGenerator
*/
protected $url;

/**
* @var \Illuminate\View\Factory
*/
protected $view;

/**
* Constructor.
*
* @param \Illuminate\Config\Repository $config
* @param \Illuminate\View\Factory $view
* @param \Illuminate\Routing\UrlGenerator $url
*/
public function __construct(Repository $config, Factory $view, UrlGenerator $url)
public function __construct(Repository $config)
{
$this->config = $config;
$this->view = $view;
$this->url = $url;
$this->collection = new Collection;
}

Expand All @@ -52,13 +36,13 @@ public function __construct(Repository $config, Factory $view, UrlGenerator $url
public function make($name, $callback)
{
if (is_callable($callback)) {
$menu = new Builder($name, $this->loadConfig($name), $this->url);
$menu = new Builder($name, $this->loadConfig($name));

call_user_func($callback, $menu);

$this->collection->put($name, $menu);

$this->view->share('menu_'.$name, $menu);
view()->share('menu_'.$name, $menu);

return $menu;
}
Expand Down
2 changes: 1 addition & 1 deletion src/MenusServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function registerServices()
{
// Bind our Menu class to the IoC container
$this->app->singleton('menu', function($app) {
return new Menu($app['config'], $app['view'], $app['url']);
return new Menu($app['config']);
});
}
}

0 comments on commit e60eab1

Please sign in to comment.