/** * Get an array of loaded file names in order of loading. * * @return array */ public function getFilenames() { $files = array(); foreach ($this->classList->getClasses() as $class) { // Push interfaces before classes if not already loaded try { $r = new \ReflectionClass($class); foreach ($r->getInterfaces() as $inf) { $name = $inf->getFileName(); if ($name && !in_array($name, $files)) { $files[] = $name; } } if (!in_array($r->getFileName(), $files)) { $files[] = $r->getFileName(); } } catch (\ReflectionException $e) { // We ignore all exceptions related to reflection, // because in some cases class can't exists. This // can be if you use in your code constructions like // // if (class_exists('SomeClass')) { // <-- here will trigger autoload // class SomeSuperClass extends SomeClass { // } // } // // We ignore all problems with classes, interfaces and // traits. } } return $files; }
/** * @return string $classFileDirectory */ protected function getDirectory() : string { if (is_null($this->directory)) { $this->directory = dirname($this->reflection->getFileName()); } return $this->directory; }
/** * * Ejemplo: * * */ function create($className) { $myArray = explode("/", $className); $reflector = new ReflectionClass(get_class($this)); //si el tamano del array es dos se debe incluir un modelo en otro subsistema //si el tamano del array es uno se incluye un modelo del mismo subsistema // sino se de lanzar una excepcion if (sizeof($myArray) == 1) { $includeDir = dirname($reflector->getFileName()) . "/../modelo/"; $fileName = $myArray[0] . '.php'; include_once $includeDir . $fileName; eval('$modelObj = new $myArray[0]($this->objParam);'); } else { if (sizeof($myArray) == 2) { $includeDir = dirname($reflector->getFileName()) . "/../../" . $myArray[0] . "/modelo/"; $fileName = $myArray[1] . '.php'; include_once $includeDir . $fileName; eval('$modelObj = new $myArray[1]($this->objParam);'); } else { if (sizeof($myArray) == 3) { $includeDir = dirname($reflector->getFileName()) . "/../../../" . $myArray[1] . "/modelo/"; $fileName = $myArray[2] . '.php'; include_once $includeDir . $fileName; eval('$modelObj = new $myArray[2]($this->objParam);'); } else { throw new Exception(__METHOD__ . ': No se pudo incluir el modelo ' . $className); } } } //var_dump($this->objParam->getParametro("codigo_tipo_documento")); exit; return $modelObj; }
public function testGenerator() { /** @var OpsWay\Test2\Solid\I $generator */ $generator = OpsWay\Test2\Solid\Factory::create('d'); $generator->generate(); $this->assertFileExists($file = __DIR__ . '/../../test/D/IReader.php'); include $file; $this->assertTrue(interface_exists('IReader'), 'interface IReader not exists'); $this->assertFileExists($file = __DIR__ . '/../../test/D/CsvReader.php'); include $file; $this->assertTrue(class_exists('CsvReader'), 'class CsvReader not exists'); $this->assertTrue(method_exists('CsvReader', 'read'), 'Method read not exists in CsvReader'); $this->assertFileExists($file = __DIR__ . '/../../test/D/App.php'); include $file; $this->assertTrue(class_exists('App'), 'class App not exists'); $this->assertContains('private $reader', file_get_contents($file)); $this->assertFileExists($file = __DIR__ . '/../../test/D/run.php'); $this->assertContains('$app = new App();', file_get_contents($file)); $this->assertContains('print_r($app->parse());', file_get_contents($file)); $app = new ReflectionClass('App'); $this->assertGreaterThan(0, count($app->getMethods()), 'Too less methods in ' . $app->getName()); $construct = $app->getMethod('__construct'); $this->assertNotFalse($construct->getName()); $construct = $app->getMethod('parse'); $this->assertNotFalse($construct->getName()); $this->assertEquals(0, count($construct->getParameters()), 'Too less arguments in ' . $construct->getName()); $this->assertContains('$reader = new CsvReader();', file_get_contents($app->getFileName())); $this->assertContains('return $reader->read();', file_get_contents($app->getFileName())); $this->checkRead(new App()); }
protected static function registerValidatorAnnotations($force = false) { if (!$force && self::$registered) { return; } $refl = new \ReflectionClass(Validation::class); if ($refl->getFileName() === false) { // We can't setup the auto loading without knowing the path return; } $filePath = str_replace('\\', '/', $refl->getFileName()); // Detect PSR-0 loading $psr0Path = '/Symfony/Component/Validator/Validation.php'; if (substr($filePath, -strlen($psr0Path)) === $psr0Path) { AnnotationRegistry::registerAutoloadNamespace('Symfony\\Component\\Validator\\Constraints', substr($filePath, 0, -strlen($psr0Path))); self::$registered = true; return; } // Custom PSR-4 loader $constraintsDir = dirname($filePath) . '/Constraints/'; AnnotationRegistry::registerLoader(function ($class) use($constraintsDir) { $ns = 'Symfony\\Component\\Validator\\Constraints\\'; if (strpos($class, $ns) !== 0) { return; } $filePath = $constraintsDir . str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen($ns))) . '.php'; if (file_exists($filePath)) { include $filePath; return true; } }); self::$registered = true; }
public function testCompileBuilderNeedsRedefine() { $builder = $this->getBuilder(); // The builder should need redefine as the file hasn't been generated yet $builder->ttl(3600); $this->assertTrue($builder->needsRedefine()); // -1 disables ttl checking (never needs redefine) $builder->ttl(-1); $this->assertFalse($builder->needsRedefine()); // 0 disables ttl checking (always needs redefine) $builder->ttl(0); $this->assertTrue($builder->needsRedefine()); // Build the container $container = $builder->build(); // Set a TTL and check if it needs redefine $builder->ttl(3600); $this->assertFalse($builder->needsRedefine()); // Touch the file, it should need redefine $r = new \ReflectionClass($container); $builder->ttl(1200); $orig = filemtime($r->getFileName()); touch($r->getFileName(), $orig - 3600); $this->assertTrue($builder->needsRedefine()); touch($r->getFileName(), $orig); // Precompiled never needs redefine $builder->precompiled(true); $this->assertFalse($builder->needsRedefine()); // Dynamic always requires redefine $builder2 = new ContainerBuilder(); $this->assertTrue($builder2->needsRedefine()); }
public function afterExample(ExampleEvent $event) { $exception = $event->getException(); if (null !== $exception && $exception instanceof MethodNotFoundException) { if (null === ($ioTemp = $this->io->cutTemp())) { if ("\n" !== $this->io->getLastWrittenMessage()) { $this->io->writeln(); } } $shortcut = get_class($exception->getSubject()) . '::' . $exception->getMethod(); if (in_array($shortcut, $this->proposedMethods)) { return; } $this->proposedMethods[] = $shortcut; if ($this->io->askConfirmation('Do you want me to create this method for you?')) { $class = new \ReflectionClass($exception->getSubject()); $method = $exception->getMethod(); $content = file_get_contents($class->getFileName()); $content = preg_replace('/}[ \\n]*$/', $this->getMethodContentFor($method) . "\n}\n", $content); file_put_contents($class->getFileName(), $content); $this->io->writeln(sprintf("\n<info>Method <value>%s::%s()</value> has been created.</info>", $class->getName(), $method), 6); } $this->io->writeln(); if (null !== $ioTemp) { $this->io->writeTemp($ioTemp); } } }
public function getConfigTreeBuilder() { $c = $this->container; $tb = new TreeBuilder(); $tb->root('jms_translation')->fixXmlConfig('config')->children()->arrayNode('locales')->prototype('scalar')->end()->end()->scalarNode('source_language')->defaultValue('en')->end()->arrayNode('configs')->useAttributeAsKey('name')->prototype('array')->fixXmlConfig('dir', 'dirs')->fixXmlConfig('excluded_dir')->fixXmlConfig('excluded_name')->fixXmlConfig('ignore_domain')->fixXmlConfig('external_translations_dir')->fixXmlConfig('domain')->fixXmlConfig('extractor')->children()->arrayNode('extractors')->prototype('scalar')->end()->end()->arrayNode('dirs')->requiresAtLeastOneElement()->prototype('scalar')->validate()->always(function ($v) use($c) { $v = str_replace(DIRECTORY_SEPARATOR, '/', $v); if ('@' === $v[0]) { if (false === ($pos = strpos($v, '/'))) { $bundleName = substr($v, 1); } else { $bundleName = substr($v, 1, $pos - 2); } $bundles = $c->getParameter('kernel.bundles'); if (!isset($bundles[$bundleName])) { throw new \Exception(sprintf('The bundle "%s" does not exist. Available bundles: %s', $bundleName, array_keys($bundles))); } $ref = new \ReflectionClass($bundles[$bundleName]); $v = false === $pos ? dirname($ref->getFileName()) : dirname($ref->getFileName()) . substr($v, $pos); } if (!is_dir($v)) { throw new \Exception(sprintf('The directory "%s" does not exist.', $v)); } return $v; })->end()->end()->end()->arrayNode('excluded_dirs')->prototype('scalar')->end()->end()->arrayNode('excluded_names')->prototype('scalar')->end()->end()->arrayNode('external_translations_dirs')->prototype('scalar')->end()->end()->scalarNode('output_format')->end()->scalarNode('default_output_format')->end()->arrayNode('ignored_domains')->prototype('scalar')->end()->end()->arrayNode('domains')->prototype('scalar')->end()->end()->scalarNode('output_dir')->isRequired()->cannotBeEmpty()->end()->scalarNode('keep')->defaultValue(false)->end()->arrayNode('output_options')->children()->arrayNode('xlf')->children()->scalarNode('add_date')->end()->scalarNode('add_filerefs')->end()->end()->end()->end()->end()->end()->end()->end()->end()->end(); return $tb; }
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; }
/** * Loads a list of classes and caches them in one big file. * * @param array $classes An array of classes to load * @param string $cacheDir A cache directory * @param string $name The cache name prefix * @param Boolean $autoReload Whether to flush the cache when the cache is stale or not * @param Boolean $adaptive Whether to remove already declared classes or not * * @throws \InvalidArgumentException When class can't be loaded */ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive = false) { // each $name can only be loaded once per PHP process if (isset(self::$loaded[$name])) { return; } self::$loaded[$name] = true; $classes = array_unique($classes); if ($adaptive) { // don't include already declared classes $classes = array_diff($classes, get_declared_classes(), get_declared_interfaces()); // the cache is different depending on which classes are already declared $name = $name . '-' . substr(md5(implode('|', $classes)), 0, 5); } $cache = $cacheDir . '/' . $name . '.php'; // auto-reload $reload = false; if ($autoReload) { $metadata = $cacheDir . '/' . $name . '.meta'; if (!file_exists($metadata) || !file_exists($cache)) { $reload = true; } else { $time = filemtime($cache); $meta = unserialize(file_get_contents($metadata)); if ($meta[1] != $classes) { $reload = true; } else { foreach ($meta[0] as $resource) { if (!file_exists($resource) || filemtime($resource) > $time) { $reload = true; break; } } } } } if (!$reload && file_exists($cache)) { require_once $cache; return; } $files = array(); $content = ''; foreach ($classes as $class) { if (!class_exists($class) && !interface_exists($class)) { throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class)); } $r = new \ReflectionClass($class); $files[] = $r->getFileName(); $content .= preg_replace(array('/^\\s*<\\?php/', '/\\?>\\s*$/'), '', file_get_contents($r->getFileName())); } // cache the core classes if (!is_dir(dirname($cache))) { mkdir(dirname($cache), 0777, true); } self::writeCacheFile($cache, Kernel::stripComments('<?php ' . $content)); if ($autoReload) { // save the resources self::writeCacheFile($metadata, serialize(array($files, $classes))); } }
/** * Get arguments of parent __construct call * * @param \ReflectionClass $class * @param array $classArguments * @return array|null */ public function getParentCall(\ReflectionClass $class, array $classArguments) { /** Skip native PHP types */ if (!$class->getFileName()) { return null; } $trimFunction = function (&$value) { $value = trim($value, PHP_EOL . ' $'); }; $method = $class->getMethod('__construct'); $start = $method->getStartLine(); $end = $method->getEndLine(); $length = $end - $start; $source = file($class->getFileName()); $content = implode('', array_slice($source, $start, $length)); $pattern = '/parent::__construct\\(([ ' . PHP_EOL . ']*[$]{1}[a-zA-Z0-9_]*,)*[ ' . PHP_EOL . ']*' . '([$]{1}[a-zA-Z0-9_]*){1}[' . PHP_EOL . ' ]*\\);/'; if (!preg_match($pattern, $content, $matches)) { return null; } $arguments = $matches[0]; if (!trim($arguments)) { return null; } $arguments = substr(trim($arguments), 20, -2); $arguments = explode(',', $arguments); array_walk($arguments, $trimFunction); $output = array(); foreach ($arguments as $argumentPosition => $argumentName) { $type = isset($classArguments[$argumentName]) ? $classArguments[$argumentName]['type'] : null; $output[$argumentPosition] = array('name' => $argumentName, 'position' => $argumentPosition, 'type' => $type); } return $output; }
public function __construct($options) { $this->options = $options; $reflect = new \ReflectionClass($this); $this->path = dirname($reflect->getFileName()); $this->assetsPath = '/' . str_replace(DS, '/', str_replace(\T4\ROOT_PATH, '', dirname($reflect->getFileName()))); }
/** * Set the 'basepath' and the 'namespace' for the extension. We can't use * __DIR__, because that would give us the base path for BaseExtension.php * (the file you're looking at), rather than the base path for the actual, * derived, extension class. * * @see http://stackoverflow.com/questions/11117637/getting-current-working-directory-of-an-extended-class-in-php */ private function setBasepath() { $reflection = new \ReflectionClass($this); $basepath = dirname($reflection->getFileName()); $this->basepath = $this->app['pathmanager']->create($basepath); $this->namespace = basename(dirname($reflection->getFileName())); }
/** * Defines the base template details object * * Templates should extend this object and customise to their own needs * * @param none * @return stdClass * **/ protected static function _details() { $_d = new stdClass(); $_d->iam = get_called_class(); $_reflect = new ReflectionClass($_d->iam); // The human friendly name of this template $_d->label = 'Widget'; // A brief description of the template, optional $_d->description = ''; // Any additional fields to request // TODO: use the form builder library $_d->additional_fields = array(); // Empty manual_config object $_d->manual_config = ''; // An icon/preview to render $_d->img = new stdClass(); $_d->img->icon = ''; // Try to detect the icon $_extensions = array('png', 'jpg', 'jpeg', 'gif'); $_path = $_reflect->getFileName(); $_path = dirname($_path); foreach ($_extensions as $ext) { $_icon = $_path . '/icon.' . $ext; if (is_file($_icon)) { $_url = ''; if (preg_match('#^' . preg_quote(NAILS_PATH, '#') . '#', $_icon)) { // Nails asset $_d->img->icon = preg_replace('#^' . preg_quote(NAILS_PATH, '#') . '#', NAILS_URL, $_icon); } elseif (preg_match('#^' . preg_quote(FCPATH . APPPATH, '#') . '#', $_icon)) { if (page_is_secure()) { $_d->img->icon = preg_replace('#^' . preg_quote(FCPATH . APPPATH, '#') . '#', SECURE_BASE_URL . APPPATH . '', $_icon); } else { $_d->img->icon = preg_replace('#^' . preg_quote(FCPATH . APPPATH, '#') . '#', BASE_URL . APPPATH . '', $_icon); } } break; } } // an array of the widget-able areas $_d->widget_areas = array(); // -------------------------------------------------------------------------- // Automatically calculated properties $_d->slug = ''; // -------------------------------------------------------------------------- // Work out slug - this should uniquely identify a type of template $_d->slug = $_reflect->getFileName(); $_d->slug = pathinfo($_d->slug); $_d->slug = explode('/', $_d->slug['dirname']); $_d->slug = array_pop($_d->slug); // -------------------------------------------------------------------------- // Define any assets need to be loaded by the template $_d->assets_editor = array(); $_d->assets_render = array(); // -------------------------------------------------------------------------- // Path $_d->path = dirname($_reflect->getFileName()) . '/'; // -------------------------------------------------------------------------- // Return the D return $_d; }
/** * Register different capsules that we can use * @param array $capsules */ public function registerCapsules($capsules = array()) { $cachePath = Config::get('base_path') . 'storage/cache/'; if (is_file($cachePath . 'reactor.cache.php')) { require_once $cachePath . 'reactor.cache.php'; $cached = true; } else { $cached = false; $toCache = ''; } foreach ($capsules as $capsule) { //todo: load anything we need to, configs, etc $this->_capsules[] = $capsule; if (!$cached) { $reflector = new \ReflectionClass(get_class($capsule)); $capsuleDir = !is_dir(dirname($reflector->getFileName()) . '/config/') ? $this->getConfigDirectory(dirname($reflector->getFileName())) : dirname($reflector->getFileName()) . '/config/'; $capsuleArray = Virge::dirToArray($capsuleDir); //crawl the config directory if it exists $files = $capsuleArray ? $capsuleArray['file'] : array(); foreach ($files as $file) { $toCache .= str_replace(array("<?php", "?>"), '', file_get_contents($capsuleDir . $file)) . "\n"; require_once $capsuleDir . $file; } } } foreach ($capsules as $capsule) { $capsule->registerCapsule(); } if (!$cached && Config::get('app', 'cache_reactor') === true) { //save cache file_put_contents($cachePath . 'reactor.cache.php', "<?php\n" . $this->sanitizeCache($toCache)); } }
/** * @return array */ public static function provide() { $reflect = new \ReflectionClass(new MockA()); $openFile = fopen($reflect->getFileName(), 'rb'); $closedFile = fopen($reflect->getFileName(), 'rb'); fclose($closedFile); return [[$openFile, true], [$closedFile, false], [null, false], [0, false], [true, false], [false, false], [new MockA(), false], [new ToStringMock('a'), false]]; }
public function getVersion() { $rc = new \ReflectionClass($this); if (preg_match('/^(\\d+)/', basename($rc->getFileName()), $matches)) { return (int) ltrim($matches[1], 0); } throw new RuntimeError(sprintf('Could not get version from "%"', basename($rc->getFileName()))); }
/** * Gets the name of the file the class is defined in. * @return String */ public function getFileName() { $f = $this->reflection->getFileName(); if (!is_readable($f)) { return NULL; } return $f; }
public function appendContent($class, $content) { $reflection = new ReflectionClass($class); $lastLine = $reflection->getEndLine() - 1; $file = file($reflection->getFileName()); $beginning = array_slice($file, 0, $lastLine); $end = array_slice($file, $lastLine); unset($file); return (bool) file_put_contents($reflection->getFileName(), implode('', $beginning) . PHP_EOL . $content . PHP_EOL . implode('', $end)); }
public function setTargetClass($targetClass) { $this->targetClass = $targetClass; $this->reflection = new \ReflectionClass($targetClass); $this->methods = $this->reflection->getMethods(\ReflectionMethod::IS_PUBLIC); $fileName = $this->reflection->getFileName(); if (file_exists($fileName)) { $this->contents = file_get_contents($fileName); } return $this; }
protected function addDependency(array &$loadPaths, \ReflectionClass $dep) { if ($dep->getFileName() !== false) { $loadPaths[$dep->getName()] = $dep->getFileName(); } if ($dep->getParentClass() instanceof \ReflectionClass) { $this->addDependency($loadPaths, $dep->getParentClass()); } foreach ($dep->getInterfaces() as $interface) { $this->addDependency($loadPaths, $interface); } }
/** * @param ContainerBuilder $container * @return mixed */ private function autodetectDirectories(ContainerBuilder $container) { $bundles = $container->getParameter('kernel.bundles'); $directories = []; foreach ($bundles as $name => $class) { $ref = new \ReflectionClass($class); $directory = dirname($ref->getFileName()) . '/Resources/config/factrine'; if (file_exists($directory)) { $directories[$ref->getNamespaceName()] = dirname($ref->getFileName()) . '/Resources/config/factrine'; } } $container->getDefinition('factrine.config_provider.config_loader')->replaceArgument(0, $directories); }
/** * @param $property_name * @param $name * @return \Symforce\CoreBundle\Annotation\SymforceAbstractAnnotation|array * @throws \Exception */ public function getPropertyValue($property_name, $name, $fetch_values = false) { if (!$this->reflection->hasProperty($property_name)) { throw new \Exception(sprintf("class property(%s->%s) not exists in file: %s ", $this->name, $property_name, $this->reflection->getFileName())); } if (!isset($this->properties_annotations[$property_name][$name])) { throw new \Exception(); } if ($fetch_values) { $this->properties_annotations[$property_name][$name]->values; } return $this->properties_annotations[$property_name][$name]->value; }
/** * @param BundleInterface $bundle * * @return array */ protected function getSkeletonDirs(BundleInterface $bundle = null) { $skeletonDirs = array(); if (isset($bundle) && is_dir($dir = $bundle->getPath() . '/Resources/SgDatatablesBundle/views/Skeleton')) { $skeletonDirs[] = $dir; } if (is_dir($dir = $this->getContainer()->get('kernel')->getRootdir() . '/Resources/SgDatatablesBundle/views/Skeleton')) { $skeletonDirs[] = $dir; } $reflClass = new \ReflectionClass(get_class($this)); $skeletonDirs[] = dirname($reflClass->getFileName()) . '/../Resources/views/Skeleton'; $skeletonDirs[] = dirname($reflClass->getFileName()) . '/../Resources'; return $skeletonDirs; }
public function __construct() { $ref = new \ReflectionClass($this); $this->path = str_replace(basename($ref->getFileName()), '', $ref->getFileName()); $this->namespace = $ref->getNamespaceName(); $this->baseDir = basename(str_replace(basename($ref->getFileName()), '', $ref->getFileName())); $this->dispatcher = Service::get(Service::DISPATCHER); $this->view = Service::get(Service::VIEW); $this->assets = Service::get(Service::ASSETS); $this->loader = Service::get(Service::LOADER); $this->configDirs = $this->loader->getConfigDirs('../'); $this->manifest = Manifest\Reader::load($this->path . 'Manifest.xml'); $this->onConstruct(); }
/** * @param array $testClassSuperTypes * @param \Exception $e * @param \ReflectionClass $class * @return array */ public static function findFileAndLineOfFailureOrError(array $testClassSuperTypes, \Exception $e, \ReflectionClass $class) { if (in_array($class->getName(), $testClassSuperTypes)) { return; } if ($e->getFile() == $class->getFileName()) { return array($e->getFile(), $e->getLine()); } foreach ($e->getTrace() as $trace) { if (array_key_exists('file', $trace) && $trace['file'] == $class->getFileName()) { return array($trace['file'], $trace['line']); } } return self::findFileAndLineOfFailureOrError($testClassSuperTypes, $e, $class->getParentClass()); }
public static function load($classes, $cacheDir, $name, $autoReload) { $cache = $cacheDir . '/' . $name . '.php'; // auto-reload $reload = false; if ($autoReload) { $metadata = $cacheDir . '/' . $name . '.meta'; if (!file_exists($metadata) || !file_exists($cache)) { $reload = true; } else { $time = filemtime($cache); $meta = unserialize(file_get_contents($metadata)); if ($meta[1] != $classes) { $reload = true; } else { foreach ($meta[0] as $resource) { if (!file_exists($resource) || filemtime($resource) > $time) { $reload = true; break; } } } } } if (!$reload && file_exists($cache)) { require_once $cache; return; } $files = array(); $content = ''; foreach ($classes as $class) { if (!class_exists($class) && !interface_exists($class)) { throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class)); } $r = new \ReflectionClass($class); $files[] = $r->getFileName(); $content .= preg_replace(array('/^\\s*<\\?php/', '/\\?>\\s*$/'), '', file_get_contents($r->getFileName())); } // cache the core classes if (!is_dir(dirname($cache))) { mkdir(dirname($cache), 0777, true); } self::writeCacheFile($cache, Kernel::stripComments('<?php ' . $content)); if ($autoReload) { // save the resources self::writeCacheFile($metadata, serialize(array($files, $classes))); } }
/** * {@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)); }
function __construct() { global $adb, $log, $current_user; echo "<table width=80% align=center border=1>"; $reflector = new ReflectionClass(get_class($this)); $fname = basename($reflector->getFileName(), '.php'); $cburs = $adb->pquery('select * from vtiger_cbupdater where filename=? and classname=?', array($fname, get_class($this))); if ($cburs and $adb->num_rows($cburs) > 0) { // it exists, we load it $cbu = $adb->fetch_array($cburs); $this->cbupdid = $cbu['cbupdaterid']; $this->cbupd_no = $cbu['cbupd_no']; $this->author = $cbu['author']; $this->filename = $cbu['filename']; $this->classname = $cbu['classname']; $this->execstate = $cbu['execstate']; $this->systemupdate = $cbu['systemupdate'] == '1' ? true : false; $this->perspective = (isset($cbu['perspective']) and $cbu['perspective'] == '1') ? true : false; $this->blocked = (isset($cbu['blocked']) and $cbu['blocked'] == '1') ? true : false; $this->execdate = $cbu['execdate']; $this->updError = false; } else { // it doesn't exist, we fail because it MUST exist $this->sendError(); } }
/** * {@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; }