/** * @param array $cache_types * The autoloader modes that are enabled, e.g. * array('apc' => 'apc', 'xcache' => 'xcache') * @param bool $cache_lazy * Whether the "lazy" mode is enabled. */ protected function xautoloadTestWithCacheTypes($cache_types, $cache_lazy) { // @FIXME // // @FIXME // // The correct configuration object could not be determined. You'll need to // // rewrite this call manually. // variable_set(XAUTOLOAD_VARNAME_CACHE_TYPES, $cache_types); $this->pass("Set cache types: " . var_export($cache_types, TRUE)); // @FIXME // // @FIXME // // The correct configuration object could not be determined. You'll need to // // rewrite this call manually. // variable_set(XAUTOLOAD_VARNAME_CACHE_LAZY, $cache_lazy); $this->pass("Set cache lazy mode: " . var_export($cache_lazy, TRUE)); // Enable xautoload. module_enable(array('xautoload'), FALSE); // At this time the xautoload_cache_mode setting is not in effect yet, // so we have to clear old cached values from APC cache. xautoload()->cacheManager->renewCachePrefix(); module_enable(array('xautoload_test_1', 'xautoload_test_2', 'xautoload_test_3', 'xautoload_test_4', 'xautoload_test_5'), FALSE); menu_rebuild(); foreach (array('xautoload_test_1' => array('Drupal\\xautoload_test_1\\ExampleClass'), 'xautoload_test_2' => array('xautoload_test_2_ExampleClass'), 'xautoload_test_3' => array('Drupal\\xautoload_test_3\\ExampleClass')) as $module => $classes) { $classes_on_include = in_array($module, array('xautoload_test_2', 'xautoload_test_3')); $this->xautoloadModuleEnabled($module, $classes, $classes_on_include); $this->xautoloadModuleCheckJson($module, $cache_types, $cache_lazy, $classes); } }
/** * Test hook_registry_files_alter() wildcard replacement. */ public function testWildcardClassmap() { $this->filesystem->addClass('test://lib/xy/z.php', 'Foo\\Bar'); $this->assertFalse(class_exists('Foo\\Bar', FALSE), 'Class Foo\\Bar must not exist yet.'); xautoload()->adapter->addClassmapSources(array('test://lib/**/*.php')); $this->assertTrue(class_exists('Foo\\Bar'), 'Class Foo\\Bar must exist.'); }
/** * Example method showing how to register namespaces from anywhere. */ function EXAMPLE_foo() { // Register stuff directly to the class finder. xautoload()->finder->addPsr4('Aaa\\Bbb\\', 'sites/all/libraries/aaa-bbb/src'); // Or use an adapter with more powerful methods. xautoload()->adapter->composerDir('sites/all/vendor/composer'); }
/** * Tests a simulated regular request. */ function testNormalRequest() { // Create virtual class files. $this->filesystem->addClass('test://modules/testmod_psr0/lib/Drupal/testmod_psr0/Foo.php', 'Drupal\\testmod_psr0\\Foo'); $this->filesystem->addClass('test://modules/testmod_psr4/lib/Foo.php', 'Drupal\\testmod_psr4\\Foo'); $this->filesystem->addClass('test://modules/testmod_pearflat/lib/Foo.php', 'testmod_pearflat_Foo'); $this->assertTrue(file_exists('test://modules/testmod_psr0/lib/Drupal/testmod_psr0/Foo.php'), 'Stream wrapper file exists.'); $services = xautoload()->getServiceContainer(); // Mock out DrupalSystem in the service container. $extensions = $this->getExampleExtensions(); $system = new MockDrupalSystem(array(), $extensions); $services->set('system', $system); // Simulate _xautoload_register_drupal(). // No cache is active. // Initialize the finder, to fire scheduled operations. $services->proxyFinder->getFinder(); // Register prefixes and namespaces for enabled extensions. $operation = new FinderOperation\BootPhase($extensions); $services->proxyFinder->onFinderInit($operation); // Simulate inclusion of other module files. // The testmod_psr4.module must contain an equivalent to the following line, // to tell xautoload that PSR-4 is in action: $services->main->registerModulePsr4('test://modules/testmod_psr4/testmod_psr4.module', 'lib'); // Boot modules use their classes. $this->assertLoadClass('Drupal\\testmod_psr0\\Foo'); $this->assertLoadClass('Drupal\\testmod_psr4\\Foo'); $this->assertLoadClass('testmod_pearflat_Foo'); }
/** * setUp() does not help us because of the process sharing problem. * So we use this instead. * * @throws \Exception */ protected function prepare() { $this->initOnce(); $filesystem = StreamWrapper::register('test'); foreach ($this->exampleModules->discoverModuleFilenames('module') as $name => $filename) { $this->exampleDrupal->getSystemTable()->addModuleWithFilename($name, $filename); } $this->exampleDrupal->getSystemTable()->moduleSetEnabled('system'); $this->exampleDrupal->initBootstrapStatus(); # $this->exampleDrupal->getCache()->cacheSet('module_implements', $data, 'cache_bootstrap'); xautoload()->getServiceContainer()->set('system', $this->exampleDrupal->getMockDrupalSystem()); $this->callLog = new CallLog(); StaticCallLog::setCallLog($this->callLog); }
function setUp() { // drupal_load('module', 'xautoload') would register namespaces for all // enabled modules, which is not intended for this unit test. // Instead, we just include xautoload.early.inc. require_once dirname(__FILE__) . '/../../../../xautoload.early.inc'; // Make sure we use the regular loader, not the APC one. // Also make sure to prepend this one. Otherwise, the core class loader will // try to load xautoload-related stuff, e.g. xautoload_Mock_* stuff, and // will fail due to the database. foreach (spl_autoload_functions() as $callback) { if (is_array($callback) && ($loader = $callback[0]) && $loader instanceof ClassLoaderInterface) { $loader->unregister(); } } xautoload()->finder->register(TRUE); // Do the regular setUp(). parent::setUp(); }
/** * @param array $cache_types * The autoloader modes that are enabled, e.g. * array('apc' => 'apc', 'xcache' => 'xcache') * @param bool $cache_lazy * Whether the "lazy" mode is enabled. */ protected function xautoloadTestWithCacheTypes($cache_types, $cache_lazy) { variable_set('xautoload_cache_types', $cache_types); $this->pass("Set cache types: " . var_export($cache_types, TRUE)); variable_set('xautoload_cache_lazy', $cache_lazy); $this->pass("Set cache lazy mode: " . var_export($cache_lazy, TRUE)); // Enable xautoload. module_enable(array('xautoload'), FALSE); // At this time the xautoload_cache_mode setting is not in effect yet, // so we have to clear old cached values from APC cache. xautoload()->cacheManager->renewCachePrefix(); module_enable(array('xautoload_test_1', 'xautoload_test_2', 'xautoload_test_3'), FALSE); menu_rebuild(); foreach (array('xautoload_test_1' => array('Drupal\\xautoload_test_1\\ExampleClass'), 'xautoload_test_2' => array('xautoload_test_2_ExampleClass'), 'xautoload_test_3' => array('Drupal\\xautoload_test_3\\ExampleClass')) as $module => $classes) { $classes_on_include = in_array($module, array('xautoload_test_2', 'xautoload_test_3')); $this->xautoloadModuleEnabled($module, $classes, $classes_on_include); $this->xautoloadModuleCheckJson($module, $cache_types, $cache_lazy, $classes); } }
/** * Callback that is applied directly before the library is loaded. At this * point the library contains variant-specific information, if specified. Note * that in this group the 'variants' property is no longer available. * * @param array $library * An array of library information belonging to the top-level library, a * specific version, a specific variant or a specific variant of a specific * version. Because library information such as the 'files' property (see * above) can be declared in all these different locations of the library * array, but a callback may have to act on all these different parts of the * library, it is called recursively for each library with a certain part of * the libraries array passed as $library each time. * @param string|null $version * If the $library array belongs to a certain version (see above), a string * containing the version. This argument may be empty, so NULL should be * specified as the default value. * @param string|null $variant * If the $library array belongs to a certain variant (see above), a string * containing the variant name. This argument may be empty, so NULL should * be specified as the default value. */ function __invoke($library, $version, $variant) { if (!empty($library['installed'])) { xautoload()->proxyFinder->observeFirstCacheMiss(new LibraryCacheMissObserver($this->callable, $library['library path'])); } }
<?php use Drupal\xautoload\Discovery\ClassMapGenerator; require_once dirname(__DIR__) . '/xautoload.early.lib.inc'; _xautoload_register(); xautoload()->finder->addPsr4('Drupal\\xautoload\\Tests\\', __DIR__ . '/lib/'); // Use a non-cached class map generator. xautoload()->getServiceContainer()->set('classMapGenerator', new ClassMapGenerator());
public function onEvent() { xautoload()->phaseControl->enterMainPhase(); }