Exemple #1
0
 /**
  * Parse and return class dependencies
  *
  * @param string $path
  * @return array
  */
 protected function parseClassDependencies($path)
 {
     $session = ReflectionSession::createDefaultSession(new PearNamingResolver(array($path)));
     $query = $session->createDirectoryQuery();
     $query->exclude('((?<!\\.php|\\.inc|\\.class)$)i');
     $classes = array();
     foreach ($query->find($path) as $class) {
         if (strpos($class->getFileName(), 'tests/') !== false) {
             continue;
         }
         $fullName = $class->getNamespaceName() . '\\' . $class->getName();
         $classSpec = array('file' => str_replace($path, '', $class->getFileName()), 'abstract' => $class->isAbstract(), 'interface' => $class->isInterface(), 'extends' => array(), 'uses' => array());
         if ($parent = $class->getParentClass()) {
             $classSpec['extends'][] = $parent->getNamespaceName() . '\\' . $parent->getName();
         }
         foreach ($class->getInterfaces() as $interface) {
             $classSpec['extends'][] = $interface->getNamespaceName() . '\\' . $interface->getName();
         }
         foreach ($class->getMethods() as $method) {
             foreach ($method->getParameters() as $parameter) {
                 if ($usedClass = $parameter->getClass()) {
                     $classSpec['uses'][] = $usedClass->getNamespaceName() . '\\' . $usedClass->getName();
                 }
             }
         }
         $classSpec['uses'] = array_unique($classSpec['uses']);
         $classes[$fullName] = $classSpec;
     }
     file_put_contents($this->resultDir . '/classes.php', "<?php\n\nreturn " . var_export($classes, true) . ";\n\n");
     return $classes;
 }
 /**
  * Returns a previous registered <b>\ReflectionClass</b> instance that
  * matches the given class name. Or throws a reflection exception when no
  * matching class exists.
  *
  * @param string $className Full qualified name of the request class.
  *
  * @return \ReflectionClass
  * @throws \ReflectionException When no matching class or interface for the
  *         given name exists.
  */
 public function getClass($className)
 {
     if ($this->_classCache->has($className)) {
         return $this->_classCache->restore($className);
     }
     return $this->_session->getClass($className);
 }
Exemple #3
0
 * 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.
 *
 * @category  PHP
 * @package   pdepend\reflection\examples
 * @author    Manuel Pichler <*****@*****.**>
 * @copyright 2009-2010 Manuel Pichler. All rights reserved.
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @version   SVN: $Id$
 * @link      http://pdepend.org/
 */
use pdepend\reflection\Autoloader;
use pdepend\reflection\ReflectionSession;
if (count($argv) < 2) {
    echo 'Usage parse_directory.php <directory>', PHP_EOL;
    exit(23);
}
if (is_dir($argv[1]) === false) {
    echo 'No valid directory given: ', $argv[1], PHP_EOL;
    exit(23);
}
include_once __DIR__ . '/../../source/pdepend/reflection/Autoloader.php';
spl_autoload_register(array(new Autoloader(), 'autoload'));
$session = new ReflectionSession();
$query = $session->createDirectoryQuery();
foreach ($query->find($argv[1]) as $class) {
    echo '- ', $class->getName(), PHP_EOL, '    ', $class->getFileName(), PHP_EOL;
}
Exemple #4
0
 *
 * 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.
 *
 * @category  PHP
 * @package   pdepend\reflection\examples
 * @author    Manuel Pichler <*****@*****.**>
 * @copyright 2009-2010 Manuel Pichler. All rights reserved.
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @version   SVN: $Id$
 * @link      http://pdepend.org/
 */
use pdepend\reflection\Autoloader;
use pdepend\reflection\ReflectionSession;
use pdepend\reflection\factories\StaticReflectionClassFactory;
use pdepend\reflection\resolvers\PearNamingResolver;
include_once __DIR__ . '/../../source/pdepend/reflection/Autoloader.php';
spl_autoload_register(array(new Autoloader(), 'autoload'));
$session = ReflectionSession::createStaticSession(new PearNamingResolver());
$class = $session->getClass('PEAR_Frontend');
echo '- ', $class->getName(), PHP_EOL, '    ', $class->getFileName(), PHP_EOL;
 /**
  * testSessionWithFileQueryCreatesExpectedNullClassInstances
  *
  * @return void
  * @covers \stdClass
  * @group reflection
  * @group reflection::integration
  * @group integrationtest
  */
 public function testSessionWithFileQueryCreatesExpectedNullClassInstances()
 {
     $path = $this->getPathnameForClass('ClassWithNullAndPreParsedInterface');
     $session = new ReflectionSession();
     $session->addClassFactory(new NullReflectionClassFactory());
     $query = $session->createFileQuery();
     $class = $query->find($path)->current();
     $interfaces = $class->getInterfaces();
     $this->assertFalse($interfaces[0]->isUserDefined());
 }
Exemple #6
0
 * 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.
 *
 * @category  PHP
 * @package   pdepend\reflection\examples
 * @author    Manuel Pichler <*****@*****.**>
 * @copyright 2009-2010 Manuel Pichler. All rights reserved.
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @version   SVN: $Id$
 * @link      http://pdepend.org/
 */
use pdepend\reflection\Autoloader;
use pdepend\reflection\ReflectionSession;
if (count($argv) < 2) {
    echo 'Usage parse_file.php <file>', PHP_EOL;
    exit(23);
}
if (is_file($argv[1]) === false) {
    echo 'No valid file given: ', $argv[1], PHP_EOL;
    exit(23);
}
include_once __DIR__ . '/../../source/pdepend/reflection/Autoloader.php';
spl_autoload_register(array(new Autoloader(), 'autoload'));
$session = new ReflectionSession();
$query = $session->createFileQuery();
foreach ($query->find($argv[1]) as $class) {
    echo '- ', $class->getName(), PHP_EOL, '    ', $class->getFileName(), PHP_EOL;
}
Exemple #7
0
 /**
  * testDirectoryQueryResolvesReferenceToParentClass
  *
  * @return void
  * @covers \stdClass
  * @group reflection
  * @group reflection::regression
  * @group regressiontest
  */
 public function testDirectoryQueryResolvesReferenceToParentClass()
 {
     $path = dirname($this->getPathnameForClass('Bug006_2'));
     $session = new ReflectionSession();
     $query = $session->createDirectoryQuery();
     foreach ($query->find($path) as $class) {
         if ($class->getName() === 'Bug006_2') {
             $this->assertType('\\ReflectionClass', $class->getParentClass());
         }
     }
 }
 /**
  * This factory method creates a reflection session instance that is a simple
  * wrapper around PHP's internal reflection api. It does not rely on any
  * parsing or suggestions and can only create reflection class instances for
  * existing classes and/or interfaces.
  *
  * @return \pdepend\reflection\ReflectionSession
  */
 public static function createInternalSession()
 {
     $session = new ReflectionSession();
     $session->addClassFactory(new factories\InternalReflectionClassFactory());
     return $session;
 }
Exemple #9
0
 /**
  * Analyzes the given files
  *
  * @return void
  */
 public function analyze()
 {
     $staticReflection = ReflectionSession::createStaticSession(new \pdepend\reflection\resolvers\NullNamingResolver());
     $fileSetQuery = $staticReflection->createFileSetQuery();
     $topLevelItems = $fileSetQuery->find($this->files);
     foreach ($topLevelItems as $item) {
         // analyze item
     }
 }