private function registerLoader()
 {
     $package = $this->composer->getPackage();
     $generator = $this->composer->getAutoloadGenerator();
     $packages = $this->composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
     $packageMap = $generator->buildPackageMap($this->composer->getInstallationManager(), $package, $packages);
     $map = $generator->parseAutoloads($packageMap, $package);
     $this->loader = $generator->createLoader($map);
     $this->loader->register();
 }
示例#2
0
文件: Bundles.php 项目: radphp/core
 /**
  * Load bundle
  *
  * @param BundleInterface $bundle
  *
  * @throws MissingBundleException
  */
 public static function load(BundleInterface $bundle)
 {
     if (is_dir($bundle->getPath())) {
         self::$bundlesLoaded[$bundle->getName()] = ['namespace' => $bundle->getNamespace(), 'path' => $bundle->getPath()];
         if (!self::$classLoader) {
             self::$classLoader = new ClassLoader();
         }
         self::$classLoader->addPsr4($bundle->getNamespace(), $bundle->getPath());
         self::$classLoader->register();
     } else {
         throw new MissingBundleException(sprintf('Bundle "%s" could not be found.', $bundle->getName()));
     }
 }
示例#3
0
 /**
  * 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);
             }
         }
     }
 }
示例#4
0
文件: EtcTest.php 项目: radphp/radphp
 public static function setUpBeforeClass()
 {
     $classLoader = new ClassLoader();
     $classLoader->addPsr4('App\\', __DIR__ . '/Fixtures/src/App');
     $classLoader->addPsr4('Test\\', __DIR__ . '/Fixtures/src/Test');
     $classLoader->register();
 }
示例#5
0
 /** {@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;
 }
示例#7
0
 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();
 }
示例#8
0
 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();
 }
示例#10
0
 public static function initialize(ClassLoader $autoloader = null)
 {
     if (null === self::$autoloader) {
         if (null === $autoloader) {
             $autoloader = new ClassLoader();
             $autoloader->register();
         }
         return self::$autoloader = $autoloader;
     }
     throw new \RuntimeException('Already initialized');
 }
示例#11
0
 /** {@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();
 }
示例#12
0
 public function registerClassMaps($classMap)
 {
     if (!$classMap) {
         return;
     }
     if (!is_array($classMap)) {
         $classMap = [$classMap];
     }
     $loader = new ClassLoader();
     $loader->addClassMap($classMap);
     $loader->register(true);
 }
示例#13
0
 function __construct(array $testSuites = [])
 {
     $this->container = new Container();
     $this->dispatcher = new Dispatcher();
     $this->parameters = new ArrayCache();
     $this->filesystem = new Filesystem();
     $this->configs = new Config();
     $this->classLoader = new ClassLoader();
     $this->report = new Report();
     $this->testSuites = $testSuites;
     $this->initialize();
     $this->classLoader->register();
     static::$instance = $this;
 }
 /**
  * Installs this class loader on the SPL autoload stack.
  *
  * @param bool $throw   If register should throw an exception or not
  * @param bool $prepend If register should prepend
  *
  * @return void
  */
 public function register($throw = true, $prepend = false)
 {
     // register the class loader instance
     parent::register($prepend);
     // require the files registered with composer (e. g. Swift Mailer)
     foreach ($this->directories as $directory) {
         if (file_exists($directory . '/composer/autoload_files.php')) {
             $includeFiles = (require $directory . '/composer/autoload_files.php');
             foreach ($includeFiles as $file) {
                 require_once $file;
             }
         }
     }
 }
示例#15
0
 /**
  * Scan plugin folder and load plugins
  *
  * @access public
  */
 public function scan()
 {
     if (file_exists(PLUGINS_DIR)) {
         $loader = new ClassLoader();
         $loader->addPsr4('Kanboard\\Plugin\\', PLUGINS_DIR);
         $loader->register();
         $dir = new DirectoryIterator(PLUGINS_DIR);
         foreach ($dir as $fileInfo) {
             if ($fileInfo->isDir() && substr($fileInfo->getFilename(), 0, 1) !== '.') {
                 $pluginName = $fileInfo->getFilename();
                 $this->loadSchema($pluginName);
                 $this->initializePlugin($this->loadPlugin($pluginName));
             }
         }
     }
 }
 public function testFactoryViewGeneration()
 {
     $app = $this->createApplication();
     ProjectUtil::runCommand(self::$projectFolder, 'datamodel:generate', ['--configclass' => 'Blend\\Tests\\DataModelBuilder\\Command\\CustomizedModelConfig'], $app);
     $loader = new ClassLoader();
     $loader->addPsr4("DALTest\\", self::$projectFolder . '/src/');
     $loader->register();
     try {
         $classRef = new \ReflectionClass('DALTest\\Database\\Common\\Factory\\SysSampleViewFactory');
         $this->assertTrue($classRef->hasMethod('getBySecretKey'));
         $this->assertTrue($classRef->hasMethod('getManyByField1AndGenerateSeries'));
         $this->assertEquals(1, $classRef->getMethod('getBySecretKey')->getNumberOfParameters());
         $this->assertEquals(2, $classRef->getMethod('getManyByField1AndGenerateSeries')->getNumberOfParameters());
     } catch (\Exception $ex) {
         $this->fail($ex->getMessage());
     }
 }
示例#17
0
 /**
  * @covers ::findFile
  */
 public function testFindFile()
 {
     $finder = new ClassFinder();
     // The full path is returned therefore only tests with
     // assertStringEndsWith() so the test is portable.
     $this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
     $class = 'Not\\A\\Class';
     $this->assertNull($finder->findFile($class));
     // Register an autoloader that can find this class.
     $loader = new ClassLoader();
     $loader->addClassMap([$class => __FILE__]);
     $loader->register();
     $this->assertEquals(__FILE__, $finder->findFile($class));
     // This shouldn't prevent us from finding the original file.
     $this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
     // Clean up the additional autoloader after the test.
     $loader->unregister();
 }
示例#18
0
 public function register()
 {
     $app = $this->app;
     foreach ($app['contenttypes'] as $contentType) {
         $key = $contentType->getKey();
         $model = $this->getModel($contentType);
         $repository = $this->getRepository($contentType);
         $package = $this->getPackage();
         $vendor = $package->getVendor();
         $lowerVendor = strtolower($vendor);
         $name = $package->getName();
         $lowerName = strtolower($name);
         $loader = new ClassLoader();
         $loader->add($vendor . '\\' . $name . '\\', $app['paths']['base'] . '/vendor/' . $lowerVendor . '/' . $lowerName . '/src');
         $loader->register();
         $this->registerModel($key, $model);
         $this->registerRepository($key, $repository);
     }
 }
示例#19
0
 public static function run(ClassLoader $autoloader)
 {
     // Converts warnings to exceptions
     ErrorHandler::register();
     $config = self::loadConfig();
     if (isset($config['extension_autoloader']) && $config['extension_autoloader']) {
         $autoloadFile = $config['extension_autoloader'];
         if (!file_exists($autoloadFile)) {
             throw new \InvalidArgumentException(sprintf('Could not find extension autoload file "%s"', $autoloadFile));
         }
         $autoloader->unregister();
         include $autoloadFile;
         $autoloader->register(true);
     }
     $extensions = $config['extensions'];
     $extensions[] = 'PhpBench\\Extension\\CoreExtension';
     unset($config['extensions']);
     $container = new Container($extensions, $config);
     $container->init();
     $container->get('console.application')->run();
 }
示例#20
0
 /**
  * Go
  *
  * Goes through all of the registered modules and attempts
  * to activate them. Performs checks to ensure that modules
  * that declare dependencies that have not been satisfied
  * will not be activated.
  *
  * Registers any directories with the class loader
  *
  * @return void
  */
 public function go()
 {
     $this->handlePreRegistered();
     $toActivate = $this->registeredModules->all();
     // This 'while' loop runs continuously allowing for modules
     // to be checked multiple times which allows for dependencies.
     while (count($toActivate) > 0) {
         foreach ($toActivate as $name => $module) {
             $canActivate = true;
             $dependencies = $module->dependencies();
             // If we've got dependencies, check them all to make sure all have been activated
             // before activating this particular module.
             if (!empty($dependencies)) {
                 foreach ($dependencies as $dependency) {
                     // First off, if this dependency hasn't even been register, we can never
                     // activate this module, so let's skip it and not try again.
                     if (!$this->registeredModules->has($dependency)) {
                         $canActivate = false;
                         $this->dispatcher->fire(self::EVENT_ACTIVATION_FAILED . ' ' . $name, $module);
                         unset($toActivate[$name]);
                         continue;
                     }
                     // At this point, the dependency has been registered but not activated,
                     // so let's skip this module and come back to it.
                     if (!$this->activeModules->has($dependency)) {
                         $canActivate = false;
                     }
                 }
             }
             // Now let's activate this sucka! Also, we remove it from the list
             // so we don't try to activate it again.
             if ($canActivate) {
                 $this->activeModules->put($name, $module->activate());
                 $this->dispatcher->fire(self::EVENT_ACTIVE . " {$name}", $module);
                 unset($toActivate[$name]);
             }
         }
     }
     $this->classLoader->register();
 }
示例#21
0
<?php

namespace tests;

use Composer\Autoload\ClassLoader;
require_once dirname(__DIR__) . '/vendor/autoload.php';
$loader = new ClassLoader();
$loader->add('tests', dirname(__DIR__));
$loader->register();
示例#22
0
 /**
  * Register the Lexicon engine implementation.
  *
  * @param  \Illuminate\View\Engines\EngineResolver $resolver
  * @return void
  */
 public function registerLexiconEngine(EngineResolver $resolver)
 {
     $container = $this->getContainer();
     $container->bindShared('anomaly.lexicon.compiler', function () use($container) {
         $compiler = new LexiconCompiler($this->getFilesystem(), $this->getStoragePath());
         $compiler->setParserResolver($container['Anomaly\\Lexicon\\Parser\\ParserResolver'])->setLexicon($this->getLexicon());
         return $compiler;
     });
     $container->bind('Anomaly\\Lexicon\\Contract\\Compiler\\CompilerInterface', 'anomaly.lexicon.compiler');
     $resolver->register($this->lexiconEngineBinding, function () use($container) {
         /** @var ClassLoader $loader */
         $loader = new ClassLoader();
         $loader->addPsr4($this->getLexicon()->getCompiledViewNamespace() . '\\', $this->getStoragePath());
         $loader->register();
         return new Engine($container['anomaly.lexicon.compiler'], $this->getFilesystem());
     });
 }
示例#23
0
<?php

namespace mindplay\test;

use Composer\Autoload\ClassLoader;
use mindplay\test\lib\xTestRunner;
define('FULL_PATH', realpath(__DIR__ . '/..'));
$vendor_path = FULL_PATH . '/vendor';
if (!is_dir($vendor_path)) {
    echo 'Install dependencies first' . PHP_EOL;
    exit(1);
}
require_once $vendor_path . '/autoload.php';
$auto_loader = new ClassLoader();
$auto_loader->addPsr4("mindplay\\test\\", FULL_PATH . '/test');
$auto_loader->addPsr4("mindplay\\test\\Sample\\", FULL_PATH . '/test/suite/Sample');
$auto_loader->register();
$runner = new xTestRunner(dirname(__DIR__) . '/src/annotations', xTestRunner::createResultPrinter());
exit($runner->run(__DIR__ . '/suite', '.test.php') ? 0 : 1);
示例#24
0
#!/usr/bin/php
<?php 
use Composer\Autoload\ClassLoader;
use LGnap\Console\AnsibleParser;
use Symfony\Component\Console\Application;
require_once 'vendor/autoload.php';
// you don't need the class loader if you get this lib through composer. The line above did already the work
$classLoader = new ClassLoader();
$classLoader->register();
$classLoader->addPsr4('LGnap\\', __DIR__ . DIRECTORY_SEPARATOR . 'src');
// Launch the console bloc
$application = new Application();
$application->add(new AnsibleParser());
$application->run();
<?php

use Composer\Autoload\ClassLoader;
use VersionPress\Storages\Mirror;
use VersionPress\Storages\StorageFactory;
use VersionPress\Tests\Utils\HookMock;
$opts = ['from:', 'to:'];
$args = getopt('', $opts);
if (count($args) < count($opts)) {
    die("Please specify all arguments\n");
}
require_once __DIR__ . '/../../vendor/autoload.php';
\Tracy\Debugger::enable(\Tracy\Debugger::DEVELOPMENT, __DIR__);
$classloader = new ClassLoader();
$classloader->addPsr4('VersionPress\\', __DIR__ . '/../../src');
$classloader->register();
HookMock::setUp(HookMock::TRUE_HOOKS);
// @codingStandardsIgnoreLine
class FooChangeInfo extends \VersionPress\ChangeInfos\TrackedChangeInfo
{
    private $files;
    public function __construct($files)
    {
        $this->files = $files;
    }
    public function getChangeDescription()
    {
        return join("\n", $this->files);
    }
    public function getScope()
    {
 private function addGeneratedEntityClassLoader($class, $path)
 {
     // Prevent class not found bug on newly generated entity class
     $classLoader = new ClassLoader();
     $classLoader->addClassMap(array($class => $path));
     $classLoader->setClassMapAuthoritative(true);
     $classLoader->register(true);
 }
示例#27
0
 /**
  * Creates and registers an ClassLoder for a given project
  * @param type $projectFolder
  * @return type
  */
 public static function initProjectClassLoader($projectFolder, $ns = null)
 {
     if ($ns === null) {
         $path = explode(DIRECTORY_SEPARATOR, $projectFolder);
         $ns = end($path);
     }
     $loader = new ClassLoader();
     $loader->addPsr4($ns . '\\', $projectFolder . '/src/');
     $loader->register(true);
     return ["{$ns}\\{$ns}Application", $loader];
 }
 /**
  * Handle the command.
  *
  * @param ClassLoader $loader
  * @param Application $application
  */
 public function handle(ClassLoader $loader, Application $application)
 {
     $loader->addPsr4('Anomaly\\Streams\\Platform\\Model\\', $application->getStoragePath('models'));
     $loader->register();
 }
示例#29
0
文件: App.php 项目: kirinami/silex
 /**
  * @param array $options
  */
 public function settings(array $options)
 {
     // root
     $root =& $options['root'];
     if (!isset($root)) {
         throw new \RuntimeException(sprintf('Required "%s" property', "root"));
     }
     // env
     $environment =& $options['environment'];
     if (!isset($environment)) {
         throw new \RuntimeException(sprintf('Required "%s" property', "environment"));
     }
     // debug
     $debug =& $options['debug'];
     if (!isset($debug)) {
         throw new \RuntimeException(sprintf('Required "%s" property', "debug"));
     }
     // autoload
     $autoload =& $options['autoload'];
     $autoload = array_merge($autoload ?: [], ["configs", "translate"]);
     foreach ($autoload as $value) {
         if (!isset($options[$value])) {
             continue;
         }
         if (is_array($options[$value])) {
             array_walk_recursive($options[$value], function (&$option) use($root) {
                 if (pathinfo($option, PATHINFO_EXTENSION) == true) {
                     $option = Yaml::parse(file_get_contents("{$root}/{$option}"));
                 }
             });
         } else {
             if (pathinfo($options[$value], PATHINFO_EXTENSION) == true) {
                 $options[$value] = Yaml::parse(file_get_contents("{$root}/{$options[$value]}"));
             }
         }
     }
     // configs
     $configs =& $options['configs'];
     if (isset($configs)) {
         if (isset($configs['paths'])) {
             $loader = new ClassLoader();
             foreach ($configs['paths'] as $name => $path) {
                 if ($name == "assets") {
                     $this->register(new AssetServiceProvider(), ['assets.version' => time(), 'assets.version_format' => "%s?version=%s", 'assets.base_path' => $path]);
                 }
                 $path = "{$root}/{$path}";
                 if ($name == "views") {
                     $this->register(new TwigServiceProvider(), ['twig.path' => $path]);
                 }
                 $loader->addPsr4(ucfirst($name) . "\\", $path);
             }
             $loader->register();
         }
         if (isset($configs['mailer'])) {
             $this->register(new SwiftmailerServiceProvider(), ['swiftmailer.options' => ['host' => $configs['mailer'][$environment]['host'], 'port' => $configs['mailer'][$environment]['port'], 'username' => $configs['mailer'][$environment]['username'], 'password' => $configs['mailer'][$environment]['password']]]);
         }
         if (isset($configs['database'])) {
             $this->register(new DoctrineServiceProvider(), ['db.options' => ['host' => $configs['database'][$environment]['host'], 'dbname' => $configs['database'][$environment]['dbname'], 'user' => $configs['database'][$environment]['username'], 'password' => $configs['database'][$environment]['password'], 'charset' => $configs['database'][$environment]['charset']]]);
             Service::getInstance()->setDatabase($this['db']);
         }
     }
     // routes
     $routes =& $options['routes'];
     if (isset($routes)) {
         $router = new Router();
         $routes = $router->load("{$root}/{$routes}")->all();
         foreach ($routes as $name => $route) {
             $match = $this->match($route['pattern'], $route['controller']);
             $match->method($route['method']);
             $match->bind($name);
             if (isset($route['when'])) {
                 $match->when((string) $route['when']);
             }
             if (isset($route['values'])) {
                 foreach ($route['values'] as $key => $value) {
                     $match->value($key, $value);
                 }
             }
             if (isset($route['asserts'])) {
                 foreach ($route['asserts'] as $key => $value) {
                     $match->assert($key, $value);
                 }
             }
         }
     }
     // translate
     $translate =& $options['translate'];
     if (isset($translate)) {
         $this->register(new LocaleServiceProvider());
         $this->register(new TranslationServiceProvider(), ['locale' => $translate['locale'], 'locale_fallbacks' => $translate['fallbacks']]);
         $this->extend("translator", function (Translator $translator) use($translate) {
             foreach ($translate['resources'] as $lang => $resource) {
                 $translator->addResource("array", $resource, $lang);
             }
             return $translator;
         });
     }
     // logger
     $logger =& $options['logger'];
     if (isset($logger)) {
         $this->register(new MonologServiceProvider(), ['monolog.logfile' => "{$root}/{$logger}"]);
     }
     // other
     $this->register(new SessionServiceProvider());
     $this->register(new ValidatorServiceProvider());
     $this->register(new SerializerServiceProvider());
     $this->register(new CsrfServiceProvider());
     $this['settings'] = $options;
     $this['debug'] = $debug;
 }
示例#30
0
 /**
  * Register the loader.
  */
 public function register()
 {
     $this->loader->register();
 }