Skip to content

Commit

Permalink
Create an interface for Config component #6
Browse files Browse the repository at this point in the history
  • Loading branch information
jedrzejchalubek committed Jul 24, 2017
1 parent 1f45315 commit 8b651ee
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 20 deletions.
9 changes: 4 additions & 5 deletions src/Gin/Asset/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

namespace Tonik\Gin\Asset;

use Tonik\Gin\Foundation\Config;
use Tonik\Gin\Contract\ConfigInterface;
use Tonik\Gin\Foundation\Exception\FileNotFoundException;
use Tonik\Gin\Foundation\Theme;

class Asset
{
/**
* Theme config instance.
*
* @var \Tonik\Gin\Foundation\Config
* @var \Tonik\Gin\Foundation\ConfigInterface
*/
protected $config;

Expand All @@ -25,9 +24,9 @@ class Asset
/**
* Construct asset.
*
* @param \Tonik\Gin\Foundation\Config $config
* @param \Tonik\Gin\Foundation\ConfigInterface $config
*/
public function __construct(Config $config)
public function __construct(ConfigInterface $config)
{
$this->config = $config;
}
Expand Down
42 changes: 42 additions & 0 deletions src/Gin/Contract/ConfigInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Tonik\Gin\Contract;

interface ConfigInterface
{
/**
* Get all of the configuration items for the application.
*
* @return array
*/
public function all();

/**
* Get the specified configuration value.
*
* @param string $key
* @param mixed $default
*
* @return mixed
*/
public function get($key, $default);

/**
* Set a given configuration value.
*
* @param array|string $key
* @param mixed $value
*
* @return void
*/
public function set($key, $value);

/**
* Determine if the given configuration value exists.
*
* @param string $key
*
* @return bool
*/
public function has($key);
}
8 changes: 4 additions & 4 deletions src/Gin/Foundation/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

namespace Tonik\Gin\Foundation;

use Tonik\Gin\Contract\ConfigInterface;
use Tonik\Gin\Foundation\Exception\FileNotFoundException;
use Tonik\Gin\Foundation\Theme;

class Autoloader
{
/**
* Theme config instance.
*
* @var array
* @var \Tonik\Gin\Contract\ConfigInterface
*/
protected $config;

/**
* Construct autoloader.
*
* @param \Tonik\Gin\Foundation\Theme $theme
* @param \Tonik\Gin\Contract\ConfigInterface $config
*/
public function __construct($config)
public function __construct(ConfigInterface $config)
{
$this->config = $config;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Gin/Foundation/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Tonik\Gin\Foundation;

use ArrayAccess;
use Tonik\Gin\Contract\ConfigInterface;

class Config implements ArrayAccess
class Config implements ConfigInterface, ArrayAccess
{
/**
* All of the configuration items.
Expand Down
6 changes: 3 additions & 3 deletions src/Gin/Foundation/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Tonik\Gin\Foundation;

use Closure;
use ArrayAccess;
use Closure;
use Tonik\Gin\Foundation\Exception\BindingResolutionException;

class Theme extends Singleton implements ArrayAccess
Expand Down Expand Up @@ -92,7 +92,7 @@ public function get($key, array $parameters = [])
if (isset($this->services[$key])) {
// Resolve service jf we don't have
// a deposit for this service.
if (! isset($this->deposit[$key])) {
if ( ! isset($this->deposit[$key])) {
$this->deposit[$key] = $this->resolve($this->services[$key], $parameters);
}

Expand Down Expand Up @@ -148,7 +148,7 @@ public function offsetGet($key)
*/
public function offsetSet($key, $service)
{
if (! is_callable($service)) {
if ( ! is_callable($service)) {
throw new BindingResolutionException("Service definition [{$service}] is not an instance of Closure");
}

Expand Down
13 changes: 6 additions & 7 deletions src/Gin/Template/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

namespace Tonik\Gin\Template;

use Tonik\Gin\Foundation\Config;
use Tonik\Gin\Contract\ConfigInterface;
use Tonik\Gin\Foundation\Exception\FileNotFoundException;
use Tonik\Gin\Foundation\Theme;

class Template
{
/**
* Theme config instance.
*
* @var array
* @var \Tonik\Gin\Contract\ConfigInterface
*/
protected $config;

Expand All @@ -25,9 +24,9 @@ class Template
/**
* Construct template.
*
* @param \Tonik\Gin\Foundation\Config $config
* @param \Tonik\Gin\Contract\ConfigInterface $config
*/
public function __construct(Config $config)
public function __construct(ConfigInterface $config)
{
$this->config = $config;
}
Expand Down Expand Up @@ -149,13 +148,13 @@ public function isNamed()
{
// If file is not array, then template
// is not named for sure.
if (! is_array($this->file)) {
if ( ! is_array($this->file)) {
return false;
}

// Return false if template is named,
// but name is bool or null.
if (isset($this->file[1]) && is_bool($this->file[1]) || is_null($this->file[1])) {
if (isset($this->file[1]) && is_bool($this->file[1]) || null === $this->file[1]) {
return false;
}

Expand Down

0 comments on commit 8b651ee

Please sign in to comment.