-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introducing name resolver (resolves class names)
- Loading branch information
Showing
9 changed files
with
157 additions
and
48 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Jean-François Lépine <https://twitter.com/Halleck45> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Hal\Component\OOP\Resolver; | ||
|
||
|
||
/** | ||
* Alias (and namepsace) resolver | ||
* | ||
* @author Jean-François Lépine <https://twitter.com/Halleck45> | ||
*/ | ||
class NameResolver | ||
{ | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $aliases = array(); | ||
|
||
/** | ||
* Resolve name of class | ||
* | ||
* @param string $name | ||
* @param string $currentNamespace | ||
* @return string | ||
*/ | ||
public function resolve($name, $currentNamespace = '\\') | ||
{ | ||
// already namespaced | ||
if ('\\' == $name[0]) { | ||
return $name; | ||
} | ||
|
||
// use xxx as yyy | ||
if (isset($this->aliases[$name])) { | ||
return $this->aliases[$name]; | ||
} | ||
|
||
// use xxx; | ||
foreach ($this->aliases as $alias => $nothing) { | ||
$parts = preg_split('![^\w]!', $alias); | ||
$last = $parts[sizeof($parts, COUNT_NORMAL) - 1]; | ||
if ($last === $name) { | ||
return $alias; | ||
} | ||
} | ||
|
||
return $name; | ||
} | ||
|
||
/** | ||
* Push alias | ||
* | ||
* @param StdClass $alias | ||
* @return $this | ||
*/ | ||
public function pushAlias(\StdClass $alias) { | ||
$this->aliases[$alias->alias] = $alias->name; | ||
return $this; | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Hal\Component\Config; | ||
use Symfony\Component\Config\Definition\Processor; | ||
use \Symfony\Component\Config\Definition\NodeInterface; | ||
|
||
class Bar { | ||
public function foo(array $config) { | ||
$processor = new Processor(); | ||
return $processor->process($this->tree, $config); | ||
} | ||
} |