/** * Loads the given class or interface. * * @param string $class The name of the class * * @return boolean|null True if loaded, null otherwise * * @since 3.4 */ public function loadClass($class) { if ($result = $this->loader->loadClass($class)) { JLoader::applyAliasFor($class); } return $result; }
/** * Autoloads all registered extension files with an instance of the app. * * @return void **/ public function autoload($app) { $loader = new ClassLoader(); $mapfile = $this->basefolder . '/vendor/composer/autoload_psr4.php'; if (is_readable($mapfile)) { $map = (require $mapfile); foreach ($map as $namespace => $path) { $loader->setPsr4($namespace, $path); } $mapfile = $this->basefolder . '/vendor/composer/autoload_classmap.php'; if (is_readable($mapfile)) { $map = (require $mapfile); $loader->addClassMap($map); } $loader->register(); } $filepath = $this->basefolder . '/vendor/composer/autoload_files.php'; if (is_readable($filepath)) { $files = (include $filepath); foreach ($files as $file) { try { if (is_readable($file)) { require $file; } } catch (\Exception $e) { $this->logInitFailure('Error importing extension class', $file, $e, Logger::ERROR); } } } }
/** * Creates RAD app kernel, which you can use to manage your app. * * Loads intl, swift and then requires/initializes/returns custom * app kernel. * * @param ClassLoader $loader Composer class loader * @param string $environment Environment name * @param Boolean $debug Debug mode? * * @return RadAppKernel */ public static function createAppKernel(ClassLoader $loader, $environment, $debug) { require_once __DIR__ . '/RadAppKernel.php'; if (null === self::$projectRootDir) { self::$projectRootDir = realpath(__DIR__ . '/../../../../../../..'); } $autoloadIntl = function ($rootDir) use($loader) { if (!function_exists('intl_get_error_code')) { require_once $rootDir . '/vendor/symfony/symfony/src/' . 'Symfony/Component/Locale/Resources/stubs/functions.php'; $loader->add(null, $rootDir . '/vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs'); } }; $autoloadSwift = function ($rootDir) use($loader) { require_once $rootDir . '/vendor/swiftmailer/swiftmailer/lib/classes/Swift.php'; \Swift::registerAutoload($rootDir . '/vendor/swiftmailer/swiftmailer/lib/swift_init.php'); }; $loader->add(null, self::$projectRootDir . '/src'); if (file_exists($custom = self::$projectRootDir . '/config/autoload.php')) { require $custom; } else { $autoloadIntl(self::$projectRootDir); $autoloadSwift(self::$projectRootDir); } return new \RadAppKernel($environment, $debug); }
/** * Initializes Maam by generating new class files for all PHP files in the supplied sourcePath * and adds the new classmap to Composer's loader. * * @param ClassLoader $loader Composer's class loader. * @throws RuntimeException * @return void */ public function init(ClassLoader $loader) { if ($this->getMode() === self::MODE_DEVELOPMENT) { $this->runGeneratorCommand(); } $loader->addClassMap(require $this->getGenerationPath() . '/classmap.php'); }
/** * Builds internal request handling objects. * * @return $this */ public function build() { if ($this->cache) { $loader = new ClassLoader(); if ($this->apc) { $apcLoader = new ApcClassLoader(sha1('ReactServer'), $loader); $loader->unregister(); $apcLoader->register(true); } } require_once $this->root_dir . '/AppKernel.php'; define('KERNEL_ROOT', $this->root_dir); $kernel = new ReactKernel($this->env, $this->env === 'dev' ? true : false); $this->loop = Factory::create(); // TODO make config for this part if (class_exists('\\Doctrine\\DBAL\\Driver\\PingableConnection')) { $this->loop->addPeriodicTimer(15, function () use($kernel) { foreach ($kernel->getContainer()->get('doctrine')->getConnections() as $connection) { if ($connection instanceof \Doctrine\DBAL\Driver\PingableConnection) { $connection->ping(); } } }); } $this->socket = new SocketServer($this->loop); $http = new HttpServer($this->socket, $this->loop); $http->on('request', $this->handleRequest($kernel)); return $this; }
public static function setUpBeforeClass() { $classLoader = new ClassLoader(); $classLoader->addPsr4('App\\', __DIR__ . '/Fixtures/src/App'); $classLoader->addPsr4('Test\\', __DIR__ . '/Fixtures/src/Test'); $classLoader->register(); }
public function testInitializerSkipsGenerationInProductionMode() { $this->maam->init($this->loader); $classMap = $this->loader->getClassMap(); $this->assertArrayHasKey('someclass', $classMap); $this->assertSame('somefile', $classMap['someclass']); }
public function __destruct() { if ($this->loader) { $this->loader->unregister(); $this->loader = NULL; } }
/** * Returns a path to the file for given class name * * @param string $className Name of the class * * @return string|false Path to the file with given class or false if not found */ public function locateClass($className) { $filePath = $this->loader->findFile($className); if (!empty($filePath)) { $filePath = PathResolver::realpath($filePath); } return $filePath; }
/** * @param string $class * @param \Donquixote\HastyReflectionCommon\Canvas\ClassLoaderCanvas\ClassLoaderCanvasInterface $canvas */ function loadClass($class, ClassLoaderCanvasInterface $canvas) { $file = $this->composerClassLoader->findFile($class); if (FALSE === $file) { return; } $canvas->includeOnce($file); }
/** * {@inheritDoc} */ public function getLoader() { $loader = new ClassLoader(); foreach ($this->information as $prefix => $paths) { $loader->add($prefix, array_map(array($this, 'prependPathWithBaseDir'), (array) $paths)); } return array($loader, 'loadClass'); }
/** * Get a fully qualified path based on a class name * * @param string $class The class name * @param string $basepath The base path * @return string|false Returns canonicalized absolute pathname or FALSE of the class could not be found. */ public function locate($class, $basepath = null) { $path = false; if ($this->_loader) { $path = $this->_loader->findFile($class); } return $path; }
/** * Get a fully qualified path based on a class name * * @param string $class The class name * @return string|false Returns canonicalized absolute pathname or FALSE of the class could not be found. */ public function locate($class) { $path = false; if (self::$__loader) { $path = self::$__loader->findFile($class); } return $path; }
/** * Register's the annotation driver for the passed configuration. * * @param \AppserverIo\Appserver\Core\Api\Node\AnnotationRegistryNodeInterface $annotationRegistry The configuration node * * @return void */ public function register(AnnotationRegistryNodeInterface $annotationRegistry) { // initialize the composer class loader $classLoader = new ClassLoader(); $classLoader->addPsr4($annotationRegistry->getNamespace(), $annotationRegistry->getDirectoriesAsArray()); // register the class loader to load annotations AnnotationRegistry::registerLoader(array($classLoader, 'loadClass')); }
/** * Construct * * @param ClassLoader $loader Loader * * @throws Exception */ public function __construct(ClassLoader $loader) { if (empty($loader->getClassMap())) { throw new Exception('You are required to run: composer dump-autoload -o', Http::STATUS_CODE_404); } if (session_status() == PHP_SESSION_NONE) { session_start(); } $this->directoryClassLoader($loader, self::getAppDir() . DS . 'modules'); $this->setModules(Loader::load($loader)); $this->directoryClassLoader($loader, self::getAppDir() . DS . 'libraries'); $routing = array(); foreach ($this->getModules() as $mod) { // Get routing from menus if (method_exists($mod, 'menus')) { $menus = array(); foreach ($mod->menus() as $name => $menu) { foreach ($menu as $key => $value) { $routing['GET'] = array_merge_recursive($value->getRoutesRecursive(), $routing); if ($value instanceof Menu) { $menus[$name][$key] = $value->toArray(); } } } $this->menus = array_replace_recursive($menus, $this->menus); } // Get additional routing if (method_exists($mod, 'routes')) { foreach ($mod->routes() as $method => $route) { foreach ($route as $key => $value) { if (key_exists(strtoupper($method), $routing) && key_exists($value, $routing[strtoupper($method)])) { $routing[strtoupper($method)][$value] = array_merge_recursive($routing[strtoupper($method)][$value], array($key)); } else { $routing[strtoupper($method)][$value] = array($key); } } } } self::callGlobalEvent($mod, 'bootstrap'); } // Add extra routes to module routing foreach ($routing as $method => $routes) { foreach ($routes as $action => $route) { if (!empty($route)) { foreach ($this->getModules() as $module) { foreach ($module->getRoutes() as &$urls) { if ($urls->getRequestMethod() === $method) { if (in_array($action, $urls->getUrls())) { $urls->setUrls(array_merge($urls->getUrls(), $route)); } } } } } } } }
public function __construct() { parent::__construct('fancy_research_links'); $this->directory = WT_MODULES_DIR . $this->getName(); // register the namespace $loader = new ClassLoader(); $loader->addPsr4('JustCarmen\\WebtreesAddOns\\FancyResearchLinks\\', WT_MODULES_DIR . $this->getName() . '/app'); $loader->register(); }
/** * Find file(s) defining given class. * * @param string $class Fully qualified name. * * @return string[] Paths. */ public function getPathsForClass($class) { if ($class !== '' && $class[0] === '\\') { $class = substr($class, 1); } $file = $this->classLoader->findFile($class); // TODO: ensure it's an absolute path. return is_string($file) ? [str_replace('//', '/', $file)] : []; }
/** * {@inheritdoc} */ public function load($module) { if (isset($module['autoload'])) { foreach ($module['autoload'] as $namespace => $path) { $this->loader->addPsr4($namespace, $this->resolvePath($module, $path)); } } return $module; }
/** {@inheritdoc} */ public function __construct() { parent::__construct(); $this->directory = WT_MODULES_DIR . $this->getName(); // register the namespaces $loader = new ClassLoader(); $loader->addPsr4('JustCarmen\\WebtreesAddOns\\FancyTreeviewPdf\\', $this->directory . '/app'); $loader->register(); }
/** * Register classloader for extension * * @return \Composer\Autoload\ClassLoader */ protected function registerLoader() { $classpath = __DIR__; $nsprefix = __NAMESPACE__ . '\\'; $loader = new ClassLoader(); $loader->addPsr4($nsprefix, $classpath); $loader->register(); return $loader; }
/** * @param string $class * * @return bool */ public function loadClass($class) { if (strpos(ltrim($class, '\\'), __NAMESPACE__) === 0) { return $this->composer->loadClass($class); } elseif ($file = $this->composer->findFile($class)) { \Composer\Autoload\includeFile('php://filter/read=influence.reader/resource=' . $file); return true; } return false; }
public function __construct() { parent::__construct('modulename'); $this->directory = WT_MODULES_DIR . $this->getName(); $this->action = Filter::get('mod_action'); // register the namespaces $loader = new ClassLoader(); $loader->addPsr4('vendor\\WebtreesModules\\modulename\\', $this->directory); $loader->register(); }
protected function setUp() { $filesystem = new Filesystem(); $filesystem->remove(__DIR__ . '/Fixtures/tmp'); $filesystem->mirror(__DIR__ . '/Fixtures/template', __DIR__ . '/Fixtures/tmp'); $loader = new ClassLoader(); $loader->addPsr4('Fixtures\\Maba\\Bundle\\', __DIR__ . '/Fixtures/tmp/src'); $loader->addPsr4('Fixtures\\Maba\\', __DIR__ . '/Fixtures/tmp/app'); $loader->register(true); static::bootKernel(); }
/** * @param Identifier $identifier * @return LocatedSource */ public function __invoke(Identifier $identifier) { if ($identifier->getType()->getName() !== IdentifierType::IDENTIFIER_CLASS) { throw new \LogicException(__CLASS__ . ' can only be used to locate classes'); } $filename = $this->classLoader->findFile($identifier->getName()); if (!$filename) { throw new \UnexpectedValueException(sprintf('Could not locate file to load "%s"', $identifier->getName())); } return new LocatedSource(file_get_contents($filename), $filename); }
/** * @param Identifier $identifier * @return LocatedSource|null */ public function __invoke(Identifier $identifier) { if ($identifier->getType()->getName() !== IdentifierType::IDENTIFIER_CLASS) { return null; } $filename = $this->classLoader->findFile($identifier->getName()); if (!$filename) { return null; } return new LocatedSource(file_get_contents($filename), $filename); }
public function registerClassMaps($classMap) { if (!$classMap) { return; } if (!is_array($classMap)) { $classMap = [$classMap]; } $loader = new ClassLoader(); $loader->addClassMap($classMap); $loader->register(true); }
public function decorate(ClassLoader $classLoader) { $standards = $this->standardFinder->getStandards(); foreach ($standards as $stadardName => $standardRuleset) { if ($this->isDefaultStandard($stadardName)) { continue; } $standardNamespace = $this->detectStandardNamespaceFromStandardName($stadardName); $standardDir = dirname($standardRuleset); $classLoader->addPsr4($standardNamespace . '\\', $standardDir . DIRECTORY_SEPARATOR . $standardNamespace); } }
/** {@inheritdoc} */ public function __construct() { parent::__construct('fancy_treeview'); $this->tree = $this->tree(); $this->tree_id = $this->tree->getTreeId(); $this->directory = WT_MODULES_DIR . $this->getName(); $this->action = Filter::get('mod_action'); // register the namespaces $loader = new ClassLoader(); $loader->addPsr4('JustCarmen\\WebtreesAddOns\\FancyTreeview\\', $this->directory . '/src'); $loader->register(); }
/** * @param Container $container * @param ClassLoader $classLoader */ public function init(Container $container, ClassLoader $classLoader) { foreach (self::$extensions as $extension) { if ($this->validate($extension)) { $classLoader->addPsr4($extension->getNamespace() . '\\', $extension->getPath()); $configuration = $this->getConfigurationFromExtension($extension); if ($configuration) { $container->configurations->add($configuration); } } } }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function findFile($className) { /** * Composer remembers that files don't exist even after they are generated. This clears the entry for * $className so we can check the filesystem again for class existence. */ if ($className[0] === '\\') { $className = substr($className, 1); } $this->autoloader->addClassMap([$className => null]); return $this->autoloader->findFile($className); }