Skip to content

Commit

Permalink
Update renderer and containers
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Feb 5, 2018
1 parent 7cb84f5 commit 4d9644b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
12 changes: 9 additions & 3 deletions src/Container/AurynContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,19 @@ public function add($id, $concrete = null)
*/
public function get($id)
{
if ($this->has($id) === false) {
$entry = null;

$this->has($id) && $entry = $this->resolve($id);

if (is_null($entry) === true) {
$message = 'Alias (%s) is not being managed by the container';

throw new Exception\NotFoundException(sprintf($message, $id));
$message = (string) sprintf($message, $id);

throw new Exception\NotFoundException($message);
}

return $this->resolve($id);
return $entry;
}

/**
Expand Down
20 changes: 11 additions & 9 deletions src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,23 @@ public function arguments(\ReflectionFunctionAbstract $reflector, $parameters =
*/
public function get($id)
{
if ($this->has($id) === false) {
$message = 'Alias (%s) is not being managed by the container';
if ($this->has($id) === true) {
$entry = isset($this->instances[$id]) ? $this->instances[$id] : $this->resolve($id);

throw new Exception\NotFoundException(sprintf($message, $id));
}
if (is_object($entry) === false) {
$message = (string) 'Alias (%s) is not an object';

$entry = isset($this->instances[$id]) ? $this->instances[$id] : $this->resolve($id);
$message = sprintf($message, $id);

if (is_object($entry) === false) {
$message = 'Alias (%s) is not an object';
throw new Exception\ContainerException($message);
}

throw new Exception\ContainerException(sprintf($message, $id));
return $entry;
}

return $entry;
$message = 'Alias (%s) is not being managed by the container';

throw new Exception\NotFoundException(sprintf($message, $id));
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/Template/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct($paths)
*/
public function render($template, array $data = array())
{
$name = (string) str_replace('.', '/', $template);
list($file, $name) = array(null, str_replace('.', '/', $template));

foreach ((array) $this->paths as $key => $path) {
$files = (array) $this->files($path);
Expand All @@ -48,7 +48,7 @@ public function render($template, array $data = array())
$item !== null && $file = $item;
}

if (isset($file) === false) {
if (is_null($file) === true) {
$message = 'Template file "%s" not found.';

$message = sprintf($message, $name);
Expand All @@ -70,17 +70,19 @@ public function render($template, array $data = array())
*/
protected function check(array $files, $path, $source, $template)
{
$file = null;

foreach ((array) $files as $key => $value) {
$filepath = str_replace($path, $source, $value);
$filepath = (string) str_replace($path, $source, $value);

$filepath = str_replace('\\', '/', (string) $filepath);

$filepath = preg_replace('/^\d\//i', '', $filepath);
$filepath = (string) preg_replace('/^\d\//i', '', $filepath);

strtolower($filepath) === $template && $file = $value;
}

return isset($file) === true ? $file : null;
return $file;
}

/**
Expand Down

0 comments on commit 4d9644b

Please sign in to comment.