Created
October 26, 2016 00:08
-
-
Save Simplesmente/3ab6440129c89dd1d24008579c467f75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace MeuFramework\Container; | |
use ArrayAccess; | |
/** | |
* @author André Teles | |
*/ | |
class Container implements ArrayAccess | |
{ | |
protected $items = []; | |
protected $cache = []; | |
public function offsetSet($offset, $value) | |
{ | |
$this->items[$offset] = $value; | |
} | |
/** | |
* @return Callble | |
* @param string $offset | |
*/ | |
public function offsetGet($offset) | |
{ | |
if( !$this->has($offset) ){ | |
return false; | |
} | |
$item = $this->items[$offset]($this); | |
return $item; | |
} | |
/** | |
* @return void | |
* @param string $offset | |
*/ | |
public function offsetUnset($offset) | |
{ | |
if( $this->has($offset) ){ | |
unset($this->items[$offset]); | |
} | |
} | |
/** | |
* @return void | |
* @param string $offset | |
*/ | |
public function offsetExists($offset) | |
{ | |
return isset( $this->items[$offset] ); | |
} | |
private function has(string $offset):bool | |
{ | |
return $this->offsetExists($offset); | |
} | |
public function __get( string $property) | |
{ | |
return $this->offsetGet($property); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment