Created
October 19, 2011 13:33
-
-
Save nerdsrescueme/1298286 to your computer and use it in GitHub Desktop.
Dot Notation Interpreter
This file contains 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 | |
/** | |
* Design namespace. This namespace is meant for abstract concepts and in most | |
* cases simply just interfaces that in someway structures the general design | |
* used in the core components. | |
* | |
* @package Atom | |
* @subpackage Library | |
*/ | |
namespace Atom\Design; | |
/** | |
* Dot Notation Interpreter Class | |
* | |
* This class handles Atom's "dot notation" support within many of its classes. | |
* It follows the interpreter design pattern. | |
* | |
* @package Atom | |
* @subpackage Library | |
*/ | |
class Dot { | |
/** | |
* Interpret the given dot notation | |
* | |
* @param string Key given in dot notation | |
* @return array Parsed pieces of given key | |
*/ | |
public function interpret($key) | |
{ | |
$package = (strpos($key, '::') !== false) ? substr($key, 0, strpos($key, ':')) : 'application'; | |
if($package !== 'application') | |
{ | |
$key = substr($key, strpos($key, ':') + 2); | |
} | |
$segments = explode('.', $key); | |
return array( | |
'package' => $package, | |
'first' => $segments[0], | |
'segments' => $segments, | |
'key' => $key, | |
'full' => $input, | |
); | |
} | |
/** | |
* Magic method, enables this class to be called as a function | |
*/ | |
public function __invoke($key) | |
{ | |
return $this->interpret($key); | |
} | |
} | |
/* End of file: dot.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment