本文整理汇总了PHP中Composer\Autoload\ClassLoader类的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader类的具体用法?PHP ClassLoader怎么用?PHP ClassLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClassLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: autoload
/**
* 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);
}
}
}
}
示例2: createAppKernel
/**
* 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);
}
示例3: init
/**
* 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');
}
示例4: build
/**
* 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;
}
示例5: setUpBeforeClass
public static function setUpBeforeClass()
{
$classLoader = new ClassLoader();
$classLoader->addPsr4('App\\', __DIR__ . '/Fixtures/src/App');
$classLoader->addPsr4('Test\\', __DIR__ . '/Fixtures/src/Test');
$classLoader->register();
}
示例6: loadClass
/**
* @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);
}
示例7: getLoader
/**
* {@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');
}
示例8: register
/**
* 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'));
}
示例9: __construct
/**
* 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));
}
}
}
}
}
}
}
}
示例10: __construct
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();
}
示例11: __construct
/** {@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();
}
示例12: registerLoader
/**
* 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;
}
示例13: loadClass
/**
* 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;
}
示例14: testInitializerSkipsGenerationInProductionMode
public function testInitializerSkipsGenerationInProductionMode()
{
$this->maam->init($this->loader);
$classMap = $this->loader->getClassMap();
$this->assertArrayHasKey('someclass', $classMap);
$this->assertSame('somefile', $classMap['someclass']);
}
示例15: __destruct
public function __destruct()
{
if ($this->loader) {
$this->loader->unregister();
$this->loader = NULL;
}
}