コード例 #1
0
ファイル: SuiteManager.php プロジェクト: nike-17/Codeception
 public function addCest($file)
 {
     $name = $this->relativeName($file);
     $this->tests[$name] = $file;
     $loaded_classes = get_declared_classes();
     require_once $file;
     $extra_loaded_classes = get_declared_classes();
     $testClasses = array_diff($extra_loaded_classes, $loaded_classes);
     foreach ($testClasses as $testClass) {
         $unit = new $testClass();
         $reflected = new \ReflectionClass($testClass);
         $methods = $reflected->getMethods(\ReflectionMethod::IS_PUBLIC);
         foreach ($methods as $method) {
             if ($method->isConstructor()) {
                 continue;
             }
             if ($method->isDestructor()) {
                 continue;
             }
             if (isset($unit->class)) {
                 $target = $unit->class;
                 $target .= $method->isStatic() ? '::' . $method->name : '.' . $method->name;
             } else {
                 $target = get_class($unit) . '::' . $method->name;
             }
             $this->suite->addTest(new \Codeception\TestCase\Cest($this->dispatcher, array('name' => $name . ':' . $target, 'class' => $unit, 'method' => $method->name, 'static' => $method->isStatic(), 'signature' => $target, 'file' => $file, 'bootstrap' => $this->settings['bootstrap'])));
         }
     }
 }
コード例 #2
0
 /**
  * Autoload
  */
 public function testAutoload()
 {
     $declared = get_declared_classes();
     $declaredCount = count($declared);
     Autoloader::autoload('Foo');
     $this->assertEquals($declaredCount, count(get_declared_classes()), 'PhpOffice\\PhpPowerpoint\\Autoloader::autoload() is trying to load ' . 'classes outside of the PhpOffice\\PhpPowerpoint namespace');
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  * @todo Same code exists in AnnotationDriver, should we re-use it somehow or not worry about it?
  */
 public function getAllClassNames()
 {
     if ($this->classNames !== null) {
         return $this->classNames;
     }
     if (!$this->paths) {
         throw MongoDBException::pathRequired();
     }
     $classes = array();
     $includedFiles = array();
     foreach ($this->paths as $path) {
         if (!is_dir($path)) {
             throw MongoDBException::fileMappingDriversRequireConfiguredDirectoryPath();
         }
         $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::LEAVES_ONLY);
         foreach ($iterator as $file) {
             if (($fileName = $file->getBasename($this->fileExtension)) == $file->getBasename()) {
                 continue;
             }
             $sourceFile = realpath($file->getPathName());
             require_once $sourceFile;
             $includedFiles[] = $sourceFile;
         }
     }
     $declared = get_declared_classes();
     foreach ($declared as $className) {
         $rc = new \ReflectionClass($className);
         $sourceFile = $rc->getFileName();
         if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) {
             $classes[] = $className;
         }
     }
     $this->classNames = $classes;
     return $classes;
 }
コード例 #4
0
ファイル: analyzer.php プロジェクト: Jakobo/snaptest
 /**
  * Analyzes the file provided and gets a list of all valid tests
  * The analyzer includes the class, scans the declared class space
  * for new classes, inspects every included class, and then for each
  * class, inspects the methods to find any that match the test criteria.
  * The resulting array of file => classes => tests is then returned.
  * 
  * @param $file the file to inspect
  * @return array
  **/
 public function analyzeFile($file)
 {
     if (!file_exists($file)) {
         throw new Snap_File_UnitTestLoader_LoadException('The test file ' . $file . ' was not found.');
     }
     // record the declated classes before include
     $classes = get_declared_classes();
     // include, and then scan for new classes
     include_once $file;
     $classes = array_diff(get_declared_classes(), $classes);
     $output = array();
     // loop through the tests and if it does not have a runTest method, continue
     // otherwise, add that class as a valid test
     $methods = array();
     foreach ($classes as $class_name) {
         // skip classes that don't have a runTests method
         if (!method_exists($class_name, 'runTests')) {
             continue;
         }
         $methods = get_class_methods($class_name);
         // loop through the methods, adding the tests
         foreach ($methods as $method) {
             if (stripos($method, 'test') !== 0) {
                 continue;
             }
             if (!isset($output[$class_name])) {
                 $output[$class_name] = array();
             }
             $output[$class_name][] = $method;
         }
     }
     return $output;
 }
コード例 #5
0
ファイル: Route.php プロジェクト: nikolovns/mvsFirstTry
 /**
  * @return array
  * @throws \Exception
  */
 public function getClassAnnotation()
 {
     $classAttributes = [];
     $this->getAllClasses();
     $classes = get_declared_classes();
     foreach ($classes as $class) {
         $reflection = new \ReflectionClass($class);
         $methods = $reflection->getMethods();
         foreach ($methods as $method) {
             $annotations = $method->getDocComment();
             preg_match_all('#@(.*?)\\s#', $annotations, $annotation);
             if ($annotation[1] != null) {
                 if (empty($method->name)) {
                     throw new \Exception('You have no method!');
                 }
                 $action = $method->name;
                 if (empty($annotation[1][0])) {
                     $annotation[1][0] = 'GET';
                 }
                 $type = $annotation[1][0];
                 if (empty($annotation[1][1])) {
                     $annotation[1][1] = '';
                 }
                 $route = $annotation[1][1];
                 if (empty($annotation[1][2])) {
                     $annotation[1][2] = 'UNAUTHORIZE';
                 }
                 $authorize = $annotation[1][2];
                 $classAttributes[] = ['method' => $action, 'type' => $type, 'route' => $route, 'authorize' => $authorize, 'class' => $class];
             }
         }
     }
     return $classAttributes;
 }
コード例 #6
0
ファイル: Abstract.php プロジェクト: robeendey/ce
 /**
  * load() - called by the client initialize routine to load files
  *
  */
 public function load()
 {
     $this->_retrievedFiles = $this->getRetrievedFiles();
     $this->_loadedClasses = array();
     $manifestRegistry = $this->_registry->getManifestRepository();
     $providerRegistry = $this->_registry->getProviderRepository();
     $loadedClasses = array();
     // loop through files and find the classes declared by loading the file
     foreach ($this->_retrievedFiles as $file) {
         $classesLoadedBefore = get_declared_classes();
         $oldLevel = error_reporting(E_ALL | ~E_STRICT);
         // remove strict so that other packages wont throw warnings
         // should we lint the files here? i think so
         include_once $file;
         error_reporting($oldLevel);
         // restore old error level
         $classesLoadedAfter = get_declared_classes();
         $loadedClasses = array_merge($loadedClasses, array_diff($classesLoadedAfter, $classesLoadedBefore));
     }
     // loop through the loaded classes and ensure that
     foreach ($loadedClasses as $loadedClass) {
         // reflect class to see if its something we want to load
         $reflectionClass = new ReflectionClass($loadedClass);
         if ($reflectionClass->implementsInterface('Zend_Tool_Framework_Manifest_Interface') && !$reflectionClass->isAbstract()) {
             $manifestRegistry->addManifest($reflectionClass->newInstance());
             $this->_loadedClasses[] = $loadedClass;
         }
         if ($reflectionClass->implementsInterface('Zend_Tool_Framework_Provider_Interface') && !$reflectionClass->isAbstract() && !$providerRegistry->hasProvider($reflectionClass->getName(), false)) {
             $providerRegistry->addProvider($reflectionClass->newInstance());
             $this->_loadedClasses[] = $loadedClass;
         }
     }
     return $this->_loadedClasses;
 }
コード例 #7
0
ファイル: OmniFixture.php プロジェクト: Abine/piwik
 /**
  * Constructor.
  */
 public function __construct()
 {
     $date = $this->month . '-01';
     $classes = get_declared_classes();
     sort($classes);
     foreach ($classes as $className) {
         if (is_subclass_of($className, 'Fixture') && !is_subclass_of($className, __CLASS__) && $className != __CLASS__ && $className != "Piwik_Test_Fixture_SqlDump" && $className != "Piwik\\Tests\\Fixtures\\UpdaterTestFixture" && $className != "Piwik\\Tests\\Fixtures\\UITestFixture") {
             $klassReflect = new ReflectionClass($className);
             if (!strpos($klassReflect->getFilename(), "tests/PHPUnit/Fixtures") && $className != "CustomAlerts" && $className != "Piwik\\Plugins\\Insights\\tests\\Fixtures\\SomeVisitsDifferentPathsOnTwoDays") {
                 continue;
             }
             $fixture = new $className();
             if (!property_exists($fixture, 'dateTime')) {
                 continue;
             }
             $fixture->dateTime = $this->adjustDateTime($fixture->dateTime, $date);
             $this->fixtures[$className] = $fixture;
             $date = Date::factory($date)->addDay(1)->toString();
         }
     }
     $this->now = $this->fixtures['ManySitesImportedLogsWithXssAttempts']->now;
     // make sure ManySitesImportedLogsWithXssAttempts is the first fixture
     $fixture = $this->fixtures['Piwik\\Tests\\Fixtures\\ManySitesImportedLogsWithXssAttempts'];
     unset($this->fixtures['Piwik\\Tests\\Fixtures\\ManySitesImportedLogsWithXssAttempts']);
     $this->fixtures = array_merge(array('Piwik\\Tests\\Fixtures\\ManySitesImportedLogsWithXssAttempts' => $fixture), $this->fixtures);
 }
コード例 #8
0
ファイル: class_tree.php プロジェクト: cefalo19/php-src
 /** @param base  base class to collect sub classes for
  * @param check_interfaces whether we deal with interfaces
  */
 function __construct($base, $check_interfaces = false)
 {
     foreach (get_declared_classes() as $cname) {
         $parent = get_parent_class($cname);
         if (strcasecmp($parent, $base) == 0) {
             $this->offsetSet($cname, new SubClasses($cname));
         }
         if ($check_interfaces) {
             if ($parent) {
                 $parent_imp = class_implements($parent);
             }
             foreach (class_implements($cname) as $iname) {
                 if (strcasecmp($iname, $base) == 0) {
                     if (!$parent || !in_array($iname, $parent_imp)) {
                         $this->offsetSet($cname, new SubClasses($cname));
                     }
                 }
             }
         }
     }
     if ($check_interfaces) {
         foreach (get_declared_interfaces() as $cname) {
             foreach (class_implements($cname) as $iname) {
                 if (strcasecmp($iname, $base) == 0) {
                     $this->offsetSet($cname, new SubClasses($cname, true));
                 }
             }
         }
     }
     $this->uksort('strnatcasecmp');
 }
コード例 #9
0
ファイル: Controller.php プロジェクト: bellthoven/phpburn
 /**
  * Same as loadView but loads relative to controllers name
  *
  * @param String $action
  * @param Boolean $toVar
  *
  * @return String
  */
 public function loadRelativeView($action, $toVar = false)
 {
     //Searching if Views is loaded
     if (array_search('PhpBURN_Views', get_declared_classes()) == true) {
         return PhpBURN_Views::loadView(get_class($this) . DS . $action, $this->_viewData, $toVar);
     }
 }
コード例 #10
0
ファイル: Resource.php プロジェクト: rommmka/axiscommerce
 public function __construct()
 {
     if ($this->_resources = Axis::cache()->load('axis_acl_resources')) {
         return;
     }
     foreach (Axis::app()->getModules() as $moduleName => $path) {
         if ('Axis_Admin' === $moduleName) {
             $path = $path . '/controllers';
         } else {
             $path = $path . '/controllers/Admin';
         }
         if (!is_dir($path)) {
             continue;
         }
         foreach ($this->_scanDirectory($path) as $file) {
             if (strstr($file, "Controller.php") == false) {
                 continue;
             }
             include_once $file;
         }
     }
     $resource = 'admin';
     $resources = array($resource);
     $camelCaseToDash = new Zend_Filter_Word_CamelCaseToDash();
     foreach (get_declared_classes() as $class) {
         if (!is_subclass_of($class, 'Axis_Admin_Controller_Back')) {
             continue;
         }
         list($module, $controller) = explode('Admin_', $class, 2);
         $module = rtrim($module, '_');
         if (empty($module)) {
             $module = 'Axis_Core';
         } elseif ('Axis' === $module) {
             $module = 'Axis_Admin';
         }
         $module = strtolower($camelCaseToDash->filter($module));
         list($namespace, $module) = explode('_', $module, 2);
         $resource .= '/' . $namespace;
         $resources[$resource] = $resource;
         $resource .= '/' . $module;
         $resources[$resource] = $resource;
         $controller = substr($controller, 0, strpos($controller, "Controller"));
         $controller = strtolower($camelCaseToDash->filter($controller));
         $resource .= '/' . $controller;
         $resources[$resource] = $resource;
         foreach (get_class_methods($class) as $action) {
             if (false == strstr($action, "Action")) {
                 continue;
             }
             $action = substr($action, 0, strpos($action, 'Action'));
             $action = strtolower($camelCaseToDash->filter($action));
             //                $resources[$namespace][$module][$controller][] = $action;
             $resources[$resource . '/' . $action] = $resource . '/' . $action;
         }
         $resource = 'admin';
     }
     asort($resources);
     Axis::cache()->save($resources, 'axis_acl_resources', array('modules'));
     $this->_resources = $resources;
 }
コード例 #11
0
 /**
  * @param   string  $name
  * @return  mixed
  */
 public function locateController($name)
 {
     // case $name is a real class name
     if (is_object($name) || class_exists($name)) {
         return $name;
     }
     // case $name is a short name
     $mask = FrontController::getInstance()->getOption('controller_name_finder');
     $full_name = sprintf($mask, Helper::getPropertyName($name));
     if (class_exists($full_name)) {
         return $full_name;
     }
     // a user defined locator
     $locator = FrontController::getInstance()->getOption('controller_locator');
     if (!is_null($locator) && is_callable($locator)) {
         $result = call_user_func($locator, $name);
         if (!empty($result) && class_exists($result)) {
             return $result;
         }
     }
     // loop over all defined classes
     $n_length = strlen($name);
     $fn_length = strlen($full_name);
     foreach (get_declared_classes() as $classname) {
         if (substr($classname, -$n_length) == $name || substr($classname, -$fn_length) == $full_name) {
             return $classname;
         }
     }
     return null;
 }
コード例 #12
0
ファイル: AnnotationDriver.php プロジェクト: leedavis81/drest
 /**
  * Get all the metadata class names known to this driver.
  * @throws DrestException
  * @return array          $classes
  */
 public function getAllClassNames()
 {
     if (empty($this->classNames)) {
         if (empty($this->paths)) {
             throw DrestException::pathToConfigFilesRequired();
         }
         $classes = [];
         $included = [];
         foreach ($this->paths as $path) {
             $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY);
             foreach ($iterator as $file) {
                 /* @var \SplFileInfo $file */
                 if (!in_array($file->getExtension(), $this->extensions)) {
                     continue;
                 }
                 $path = $file->getRealPath();
                 if (!empty($path)) {
                     require_once $path;
                 }
                 // Register the files we've included here
                 $included[] = $path;
             }
         }
         foreach (get_declared_classes() as $className) {
             $reflClass = new \ReflectionClass($className);
             $sourceFile = $reflClass->getFileName();
             if (in_array($sourceFile, $included) && $this->isDrestResource($className)) {
                 $classes[] = $className;
             }
         }
         $this->classNames = $classes;
     }
     return $this->classNames;
 }
コード例 #13
0
ファイル: TestsRunner.php プロジェクト: jamm/tester
 public function runInFolder($folder, $prefix = '', $suffix = '', $beforeEach = null, $afterEach = null)
 {
     if (!$folder) {
         trigger_error('No folder specified', E_USER_WARNING);
         return false;
     }
     $tests = array();
     $classes_before = get_declared_classes();
     if (!$this->includeFolder($folder, $prefix, $suffix)) {
         return false;
     }
     $classes_after = get_declared_classes();
     $classes = array_diff($classes_after, $classes_before);
     if (!empty($classes)) {
         foreach ($classes as $class) {
             try {
                 /** @var ClassTest $Test */
                 $Test = new $class();
             } catch (\Exception $E) {
                 continue;
             }
             if ($Test instanceof ClassTest && get_class($Test) !== 'Jamm\\Tester\\ClassTest') {
                 if ($beforeEach && is_callable($beforeEach)) {
                     $beforeEach($Test);
                 }
                 $Test->RunTests();
                 $tests = array_merge($tests, $Test->getTests());
                 if ($afterEach && is_callable($afterEach)) {
                     $afterEach($Test);
                 }
             }
         }
     }
     return $tests;
 }
コード例 #14
0
ファイル: class.Documentor.php プロジェクト: arno06/Achilles
 public function parsePackage($pPath, $pPackage, $pOrigin = true)
 {
     $classes = array();
     $excluded_ext = '/\\.(tpl|tpl\\.php|ttf)$/';
     $r = Folder::read($pPath, false);
     foreach ($r as $name => $folder) {
         if (is_file($folder['path'])) {
             $file = $folder['path'];
             if (preg_match($excluded_ext, $file, $matches)) {
                 continue;
             }
             include_once $file;
             continue;
         }
         $this->parsePackage($folder['path'], $pPackage . '\\' . $name, false);
     }
     if ($pOrigin) {
         $declared_classes = get_declared_classes();
         foreach ($declared_classes as $classe) {
             if (preg_match('/^' . $pPackage . '/', $classe, $matches)) {
                 $details = $this->parseClass($classe);
                 $classes[$classe] = $details;
             }
         }
     }
     $this->packages = array_merge($this->packages, $classes);
 }
コード例 #15
0
ファイル: Dump.php プロジェクト: vinnivinsachi/Vincent-DR
 /**
  * Processes the request.
  *
  * @param  object   HTML_QuickForm_Page  the current form-page
  * @param  string   Current action name, as one Action object can serve multiple actions
  * @since  2.1.0
  * @access public
  */
 function perform(&$page, $actionName)
 {
     $page->isFormBuilt() or $page->buildForm();
     $page->handle('display');
     $sess =& $page->controller->container();
     $opt = $page->getSubmitValue('dumpOption');
     switch ($opt) {
         case '1':
             // Progress2 dump info
             $arr = $page->controller->_progress->toArray();
             varDump($arr);
             break;
         case '2':
             // Forms values container
             varDump($sess);
             break;
         case '3':
             // Included files
             $includes = get_included_files();
             varDump($includes);
             break;
         case '4':
             // declared classes
             $classes = get_declared_classes();
             varDump($classes);
             break;
         case '5':
             // declared actions
             $actions = $page->controller->_actions;
             varDump($actions);
             break;
     }
 }
コード例 #16
0
 /** @function load() loads the events into the system
  * @return void
  */
 public function load()
 {
     global $Init;
     foreach ($Init->EventPaths as $subscriberDirectory) {
         if (file_exists($subscriberDirectory)) {
             $subscriberIterator = new DirectoryIterator($subscriberDirectory);
             foreach ($subscriberIterator as $fileInfo) {
                 $file = !$fileInfo->isDot() && $fileInfo->isFile() && substr($fileInfo->getFilename(), -10) == '.event.php' ? file($fileInfo->getPathname()) : null;
                 $PluginName = preg_match('#plugins#i', $subscriberDirectory) ? basename(substr($subscriberDirectory, 0, -7)) : null;
                 if (in_array($PluginName, (array) $_SESSION['PluginsInstalled'])) {
                     $className = substr($fileInfo->getFilename(), -10) == '.event.php' ? substr($fileInfo->getFilename(), 0, -10) : null;
                 } else {
                     if ($file && !preg_match('#plugins#', $fileInfo->getPathname())) {
                         $key = '$active';
                         foreach ($file as $lineNumber => $line) {
                             if (strpos($line, $key) !== false) {
                                 break;
                             }
                         }
                         if (preg_match('#true#i', $file[$lineNumber])) {
                             $className = substr($fileInfo->getFileName(), -10) == '.event.php' ? substr($fileInfo->getFilename(), 0, -10) : null;
                         }
                     }
                 }
                 if ($className && !in_array($className, get_declared_classes())) {
                     $this->getClass($className);
                 }
             }
         }
     }
 }
コード例 #17
0
ファイル: RoboFile.php プロジェクト: sliver/Robo
 /**
  * generate docs
  */
 public function docs()
 {
     $docs = [];
     foreach (get_declared_classes() as $task) {
         if (!preg_match('~Robo\\\\Task.*?Task$~', $task)) {
             continue;
         }
         $docs[basename((new ReflectionClass($task))->getFileName(), '.php')][] = $task;
     }
     ksort($docs);
     $taskGenerator = $this->taskGenDoc('docs/tasks.md')->filterClasses(function (\ReflectionClass $r) {
         return !$r->isAbstract() or $r->isTrait();
     })->prepend("# Tasks");
     foreach ($docs as $file => $classes) {
         $taskGenerator->docClass("Robo\\Task\\{$file}");
         foreach ($classes as $task) {
             $taskGenerator->docClass($task);
         }
     }
     $taskGenerator->filterMethods(function (\ReflectionMethod $m) {
         if ($m->isConstructor() or $m->isDestructor() or $m->isStatic()) {
             return false;
         }
         return !in_array($m->name, ['run', '', '__call', 'getCommand']) and $m->isPublic();
         // methods are not documented
     })->processClassSignature(function ($c) {
         return "## " . preg_replace('~Task$~', '', $c->getShortName()) . "\n";
     })->processClassDocBlock(function ($c, $doc) {
         return preg_replace('~@method .*?\\wTask (.*?)\\)~', '* `$1)` ', $doc);
     })->processMethodSignature(function (\ReflectionMethod $m, $text) {
         return str_replace('#### *public* ', '* `', $text) . '`';
     })->processMethodDocBlock(function (\ReflectionMethod $m, $text) {
         return $text ? ' ' . strtok($text, "\n") : '';
     })->run();
 }
コード例 #18
0
 protected function minifyYii($entryScript)
 {
     try {
         ob_start();
         $this->runRequest($entryScript);
         $_SERVER['REQUEST_URI'] = '/index.php';
         $this->runRequest($entryScript, array('r' => 'post'));
         ob_end_clean();
     } catch (CException $e) {
         echo $e;
         die;
     }
     $classes = array_merge(get_declared_classes(), get_declared_interfaces());
     $results = array();
     foreach ($classes as $class) {
         $c = new ReflectionClass($class);
         if (strpos($c->getFileName(), YII_PATH) === 0 && strpos($c->getFileName(), YII_PATH . DIRECTORY_SEPARATOR . 'console') !== 0) {
             $results[$class] = $c->getFileName();
         }
     }
     $results = $this->sortByInheritance($results);
     $content = '';
     foreach ($results as $fileName => $class) {
         $content .= "\n" . file_get_contents($fileName);
     }
     return $content;
 }
コード例 #19
0
ファイル: functions.php プロジェクト: shabbyrobe/amiss
function determine_classes($file)
{
    $c = get_declared_classes();
    require_once $file;
    $diff = array_diff(get_declared_classes(), $c);
    return $diff;
}
コード例 #20
0
ファイル: coursewizardsteps.php プロジェクト: ratbird/hope
 /**
  * Shows a dialog for creating or editing a course wizard step.
  * @param string $id ID of step to edit, or null if new step
  */
 public function edit_action($id = '')
 {
     if ($id) {
         $title = _('Schritt bearbeiten');
         $this->step = CourseWizardStepRegistry::find($id);
     } else {
         $title = _('Schritt hinzufügen');
         $this->step = new CourseWizardStepRegistry();
         $this->step->name = '';
         $this->step->classname = '';
         $this->step->number = 0;
         $this->step->enabled = false;
         $this->availableClasses = array();
         foreach (get_declared_classes() as $className) {
             if (is_a($className, "CourseWizardStep", true) && $className !== "CourseWizardStep") {
                 $collection = new SimpleCollection(CourseWizardStepRegistry::findBySQL("1 ORDER BY `number`"));
                 if (!in_array($className, $collection->pluck("classname"))) {
                     $this->availableClasses[] = $className;
                 }
             }
         }
     }
     if (Request::isXhr()) {
         $this->response->add_header('X-Title', $title);
     }
 }
コード例 #21
0
ファイル: Coverage.php プロジェクト: EHER/chegamos
 /**
  * Analyzes code coverage results collected from XDebug, and performs coverage density analysis.
  *
  * @param object $report The report instance running this filter and aggregating results
  * @param array $classes A list of classes to analyze coverage on. By default, gets all
  *              defined subclasses of lithium\test\Unit which are currently in memory.
  * @return array|void Returns an array indexed by file and line, showing the number of
  *                    instances each line was called.
  */
 public static function analyze($report, array $classes = array())
 {
     $data = static::collect($report->results['filters'][__CLASS__]);
     $classes = $classes ?: array_filter(get_declared_classes(), function ($class) use($data) {
         $unit = 'lithium\\test\\Unit';
         return !is_subclass_of($class, $unit) || array_key_exists($class, $data);
     });
     $classes = array_values(array_intersect((array) $classes, array_keys($data)));
     $densities = $result = array();
     foreach ($classes as $class) {
         $classMap = array($class => Libraries::path($class));
         $densities += static::_density($data[$class], $classMap);
     }
     $executableLines = array();
     if (!empty($classes)) {
         $executableLines = array_combine($classes, array_map(function ($cls) {
             return Inspector::executable($cls, array('public' => false));
         }, $classes));
     }
     foreach ($densities as $class => $density) {
         $executable = $executableLines[$class];
         $covered = array_intersect(array_keys($density), $executable);
         $uncovered = array_diff($executable, $covered);
         $percentage = round(count($covered) / (count($executable) ?: 1), 4) * 100;
         $result[$class] = compact('class', 'executable', 'covered', 'uncovered', 'percentage');
     }
     $result = static::collectLines($result);
     return $result;
 }
コード例 #22
0
ファイル: Handler.php プロジェクト: LeeGlendenning/formulize
 /**
  * Add the events defined in filename
  *
  * @param string $filename
  */
 public function addPreloadEvents($filename, $module = false)
 {
     if ($module) {
         $filepath = ICMS_ROOT_PATH . "/modules/{$module}/preload/{$filename}.php";
     } else {
         $filepath = ICMS_PRELOAD_PATH . "/{$filename}.php";
     }
     include_once $filepath;
     $classname = $this->getClassName($filename);
     if (in_array($classname, get_declared_classes())) {
         $preloadItem = new $classname();
         $class_methods = get_class_methods($classname);
         foreach ($class_methods as $method) {
             if (strpos($method, 'event') === 0) {
                 $preload_event = strtolower(str_replace('event', '', $method));
                 $callback = array($preloadItem, $method);
                 icms_Event::attach('icms', $preload_event, $callback);
                 /*
                 					$preload_event_weight_define_name = strtoupper($classname) . '_' . strtoupper($preload_event);
                 					if (defined($preload_event_weight_define_name)) {
                 						$preload_event_weight = constant($preload_event_weight_define_name);
                 						$this->_preloadEventsArray[$preload_event][$preload_event_weight] = $preload_event_array;
                 					} else {
                 						$this->_preloadEventsArray[$preload_event][] = $preload_event_array;
                 					}*/
             }
         }
     }
 }
コード例 #23
0
ファイル: TypeScanner.php プロジェクト: spotframework/spot
 public function scan($namespace)
 {
     $namespace = trim($namespace, "\\") . "\\";
     $paths = [];
     foreach (spl_autoload_functions() as $loader) {
         if (is_array($loader) && count($loader) === 2) {
             if ($loader[0] instanceof ComposerLoader) {
                 foreach ($loader[0]->getPrefixes() as $prefix => $loaderPaths) {
                     if (strpos($prefix . "\\", $namespace) === 0) {
                         $paths = array_merge($paths, $loaderPaths);
                     } else {
                         if (strpos($namespace, $prefix . "\\") === 0) {
                             $paths = array_merge($paths, array_map(function ($path) use($namespace, $prefix) {
                                 return $path . "/" . str_replace("\\", "/", $namespace);
                             }, $loaderPaths));
                         }
                     }
                 }
             }
         }
     }
     array_map([$this->phpLoader, "load"], $paths);
     return array_filter(array_merge(get_declared_classes(), get_declared_interfaces()), function ($name) use($namespace) {
         return stripos($name, $namespace) === 0;
     });
 }
コード例 #24
0
ファイル: Loader.php プロジェクト: Noor54/SymfonyEcommerce
 /**
  * Find fixtures classes in a given directory and load them.
  *
  * @param string $dir Directory to find fixture classes in.
  * @return array $fixtures Array of loaded fixture object instances
  */
 public function loadFromDirectory($dir)
 {
     if (!is_dir($dir)) {
         throw new \InvalidArgumentException(sprintf('"%s" does not exist', $dir));
     }
     $fixtures = array();
     $includedFiles = array();
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY);
     foreach ($iterator as $file) {
         if (($fileName = $file->getBasename($this->fileExtension)) == $file->getBasename()) {
             continue;
         }
         $sourceFile = realpath($file->getPathName());
         require_once $sourceFile;
         $includedFiles[] = $sourceFile;
     }
     $declared = get_declared_classes();
     foreach ($declared as $className) {
         $reflClass = new \ReflectionClass($className);
         $sourceFile = $reflClass->getFileName();
         if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) {
             $fixture = new $className();
             $fixtures[] = $fixture;
             $this->addFixture($fixture);
         }
     }
     return $fixtures;
 }
コード例 #25
0
ファイル: Thread.php プロジェクト: icicleio/concurrent
 /**
  * Runs the thread code and the initialized function.
  *
  * @codeCoverageIgnore Only executed in thread.
  */
 public function run()
 {
     /* First thing we need to do is re-initialize the class autoloader. If
      * we don't do this first, any object of a class that was loaded after
      * the thread started will just be garbage data and unserializable
      * values (like resources) will be lost. This happens even with
      * thread-safe objects.
      */
     foreach (get_declared_classes() as $className) {
         if (strpos($className, 'ComposerAutoloaderInit') === 0) {
             // Calling getLoader() will register the class loader for us
             $className::getLoader();
             break;
         }
     }
     Loop\loop($loop = Loop\create(false));
     // Disable signals in thread.
     // At this point, the thread environment has been prepared so begin using the thread.
     try {
         $channel = new ChannelledStream(new DuplexPipe($this->socket, false));
     } catch (\Throwable $exception) {
         return;
         // Parent has destroyed Thread object, so just exit.
     }
     $coroutine = new Coroutine($this->execute($channel));
     $coroutine->done();
     $timer = $loop->timer(self::KILL_CHECK_FREQUENCY, true, function () use($loop) {
         if ($this->killed) {
             $loop->stop();
         }
     });
     $timer->unreference();
     $loop->run();
 }
コード例 #26
0
ファイル: Application.php プロジェクト: ankalagon/ladybug
 /**
  * Builds the container.
  * @param array $parameters
  */
 public function build($parameters = array())
 {
     // sort array by key to generate the container name
     ksort($parameters);
     // needed for new packages installed
     $composerClass = array_filter(get_declared_classes(), function ($item) {
         if (0 === strpos($item, 'ComposerAutoloaderInit')) {
             return true;
         }
     });
     $composerClass = array_pop($composerClass);
     // generate hash
     $parametersHash = md5(serialize($parameters) . $composerClass);
     $containerClass = 'Container' . $parametersHash;
     $isDebug = true;
     $file = sprintf('%s/ladybug_cache/%s.php', sys_get_temp_dir(), $parametersHash);
     $containerConfigCache = new ConfigCache($file, $isDebug);
     if (!$containerConfigCache->isFresh()) {
         $this->initializeContainer();
         $this->loadServices();
         $this->loadThemes();
         $this->loadPlugins();
         $this->setParameters($parameters);
         $this->container->compile();
         $dumper = new PhpDumper($this->container);
         $containerConfigCache->write($dumper->dump(array('class' => $containerClass)), $this->container->getResources());
     } else {
         require_once $file;
         $this->container = new $containerClass();
     }
 }
コード例 #27
0
ファイル: Loader.php プロジェクト: peg-org/peg-src
 /**
  * Scans a given path for valid plugin files and load them if possible.
  * This method should be called after everything else in the application
  * has been properly initialized.
  * @param string $path
  */
 public function Start($path)
 {
     if (!is_dir($path)) {
         return;
     }
     $path = rtrim($path, "/\\") . "/";
     $elements = scandir($path);
     foreach ($elements as $file_name) {
         if (is_file($path . $file_name)) {
             $file_parts = explode(".", $file_name, 2);
             if (count($file_parts) < 2) {
                 continue;
             }
             $class_name = $file_parts[0];
             $class_name_ns = "Peg\\Lib\\Plugins\\{$class_name}";
             $file_extension = $file_parts[1];
             if ($file_extension == "php") {
                 include $path . $file_name;
                 if (in_array($class_name_ns, get_declared_classes())) {
                     $this->plugins[$class_name] = new $class_name_ns();
                     $this->plugins[$class_name]->name = $class_name;
                     $this->plugins[$class_name]->path = $path . $file_name;
                     $this->plugins[$class_name]->OnInit();
                 }
             }
         }
     }
 }
コード例 #28
0
ファイル: ClassLoaderTest.php プロジェクト: tguyard/flexihash
 public function testClassLoaderLoadsFlexihashClass()
 {
     // this test is fragile when run in a grouptest/testsuite environment
     $this->assertFalse(in_array('Flexihash\\Exception', get_declared_classes()), 'Exception should not be declared yet');
     $e = new Exception();
     $this->assertTrue(in_array('Flexihash\\Exception', get_declared_classes()), 'Exception should be declared after autoload');
 }
コード例 #29
0
 /**
  * {@inheritdoc}
  */
 public function create() : ResourceNameCollection
 {
     $classes = [];
     $includedFiles = [];
     if ($this->decorated) {
         foreach ($this->decorated->create() as $resourceClass) {
             $classes[$resourceClass] = true;
         }
     }
     foreach ($this->paths as $path) {
         $iterator = new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY), '/^.+\\.php$/i', \RecursiveRegexIterator::GET_MATCH);
         foreach ($iterator as $file) {
             $sourceFile = $file[0];
             if (!preg_match('(^phar:)i', $sourceFile)) {
                 $sourceFile = realpath($sourceFile);
             }
             require_once $sourceFile;
             $includedFiles[$sourceFile] = true;
         }
     }
     $declared = get_declared_classes();
     foreach ($declared as $className) {
         $reflectionClass = new \ReflectionClass($className);
         $sourceFile = $reflectionClass->getFileName();
         if (isset($includedFiles[$sourceFile]) && $this->reader->getClassAnnotation($reflectionClass, ApiResource::class)) {
             $classes[$className] = true;
         }
     }
     return new ResourceNameCollection(array_keys($classes));
 }
コード例 #30
0
 /**
  * Gets the list of class names in the given directory.
  *
  * @param string $directory
  *
  * @return array
  */
 private function getClasses($directory)
 {
     $classes = [];
     $directoryList = [];
     $includedFiles = [];
     $finder = new Finder();
     try {
         $finder->in($directory)->files()->name('*.php');
     } catch (\InvalidArgumentException $e) {
         return [[], []];
     }
     foreach ($finder as $file) {
         $directoryList[$file->getPath()] = true;
         $sourceFile = $file->getRealpath();
         if (!preg_match('(^phar:)i', $sourceFile)) {
             $sourceFile = realpath($sourceFile);
         }
         require_once $sourceFile;
         $includedFiles[$sourceFile] = true;
     }
     $declared = get_declared_classes();
     foreach ($declared as $className) {
         $reflectionClass = new \ReflectionClass($className);
         $sourceFile = $reflectionClass->getFileName();
         if ($reflectionClass->isAbstract()) {
             continue;
         }
         if (isset($includedFiles[$sourceFile])) {
             $classes[$className] = true;
         }
     }
     return [array_keys($classes), $directoryList];
 }