This repository has been archived by the owner on Jul 17, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e65e609
Showing
7 changed files
with
697 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Copyright (c) 2006-2012 Marco Pivetta <ocramius@gmail.com> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and | ||
to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the | ||
Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,2 @@ | ||
<?php | ||
require_once(__DIR__ . '/src/OcraDiCompiler/Module.php'); |
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,28 @@ | ||
{ | ||
"name": "ocramius/ocra-di-compiler", | ||
"description": "Zend Framework 2 Module that compiles Zend\\Di definitions to speed up ZF2 applications", | ||
"type": "library", | ||
"license": "MIT", | ||
"keywords": [ | ||
"Dependency Injection Container", | ||
"DIC", | ||
"zf2" | ||
], | ||
"homepage": "https://github.com/Ocramius/OcraDiCompiler", | ||
"authors": [ | ||
{ | ||
"name": "Marco Pivetta", | ||
"email": "ocramius@gmail.com", | ||
"homepage": "http://marco-pivetta.com/" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.3", | ||
"zendframework/zendframework": ">=2.0.0beta4" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"OcraDiCompiler": "src" | ||
} | ||
} | ||
} |
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,118 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace OcraDiCompiler; | ||
|
||
use Zend\Di\Di; | ||
use Zend\Di\ServiceLocator\DependencyInjectorProxy; | ||
use Zend\Di\ServiceLocator\GeneratorInstance; | ||
use OcraDiCompiler\Exception\InvalidArgumentException; | ||
|
||
/** | ||
* Class for handling dumping of dependency injection parameters | ||
* | ||
* @license MIT | ||
* @link http://www.doctrine-project.org/ | ||
* @author Marco Pivetta <ocramius@gmail.com> | ||
*/ | ||
class Dumper | ||
{ | ||
/** | ||
* @var Di | ||
*/ | ||
protected $di; | ||
|
||
/** | ||
* @var DependencyInjectorProxy | ||
*/ | ||
protected $proxy; | ||
|
||
/** | ||
* @param Di $di | ||
*/ | ||
public function __construct(Di $di) | ||
{ | ||
$this->di = $di; | ||
$this->proxy = new DependencyInjectorProxy($di); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getAliases() | ||
{ | ||
return $this->di->instanceManager()->getAliases(); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getInitialInstanceDefinitions() | ||
{ | ||
$im = $this->di->instanceManager(); | ||
$classes = $im->getClasses(); | ||
$aliases = array_keys($im->getAliases()); | ||
return array_unique(array_merge($classes, $aliases)); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getAllInjectedDefinitions() | ||
{ | ||
return $this->getInjectedDefinitions($this->getInitialInstanceDefinitions()); | ||
} | ||
|
||
/** | ||
* @param string|array $name name or names of the instances to get | ||
* | ||
* @return GeneratorInstance[] all definitions discovered recursively | ||
*/ | ||
public function getInjectedDefinitions($name) | ||
{ | ||
$names = (array) $name; | ||
$visited = array(); | ||
|
||
foreach ($names as $name) { | ||
//var_dump(array(__METHOD__ . ':' . __LINE__ => $name)); | ||
$this->doGetInjectedDefinitions($name, $visited); | ||
} | ||
|
||
return $visited; | ||
} | ||
|
||
/** | ||
* @param string $name of the instances to get | ||
* @param array $visited the array where discovered instance definitions will be stored | ||
*/ | ||
protected function doGetInjectedDefinitions($name, array &$visited) | ||
{ | ||
if (isset($visited[$name])) { | ||
return; | ||
} | ||
|
||
$visited[$name] = $this->proxy->get($name); | ||
|
||
foreach ($visited[$name]->getParams() as $param) { | ||
if ($param instanceof GeneratorInstance) { | ||
/* @var $param GeneratorInstance */ | ||
$this->doGetInjectedDefinitions($param->getName(), $visited); | ||
} | ||
} | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace OcraDiCompiler\Exception; | ||
|
||
use Zend\Di\Exception\ExceptionInterface; | ||
|
||
/** | ||
* Invalid argument exception used by the dumper | ||
* | ||
* @author Marco Pivetta <ocramius@gmail.com> | ||
* @license MIT | ||
*/ | ||
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface | ||
{ | ||
} |
Oops, something went wrong.