本文整理汇总了PHP中Zend\Loader\StandardAutoloader::autoload方法的典型用法代码示例。如果您正苦于以下问题:PHP StandardAutoloader::autoload方法的具体用法?PHP StandardAutoloader::autoload怎么用?PHP StandardAutoloader::autoload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Loader\StandardAutoloader
的用法示例。
在下文中一共展示了StandardAutoloader::autoload方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
if (!class_exists('Archive_Tar')) {
$autoloader = new StandardAutoloader();
$autoloader->setFallbackAutoloader(true);
if (!$autoloader->autoload('Archive_Tar')) {
$this->markTestSkipped('This filter needs PEARs Archive_Tar');
}
}
$files = array(dirname(__DIR__) . '/_files/zipextracted.txt', dirname(__DIR__) . '/_files/_compress/Compress/First/Second/zipextracted.txt', dirname(__DIR__) . '/_files/_compress/Compress/First/Second', dirname(__DIR__) . '/_files/_compress/Compress/First/zipextracted.txt', dirname(__DIR__) . '/_files/_compress/Compress/First', dirname(__DIR__) . '/_files/_compress/Compress/zipextracted.txt', dirname(__DIR__) . '/_files/_compress/Compress', dirname(__DIR__) . '/_files/_compress/zipextracted.txt', dirname(__DIR__) . '/_files/_compress', dirname(__DIR__) . '/_files/compressed.tar');
foreach ($files as $file) {
if (file_exists($file)) {
if (is_dir($file)) {
rmdir($file);
} else {
unlink($file);
}
}
}
if (!file_exists(dirname(__DIR__) . '/_files/Compress/First/Second')) {
mkdir(dirname(__DIR__) . '/_files/Compress/First/Second', 0777, true);
file_put_contents(dirname(__DIR__) . '/_files/Compress/First/Second/zipextracted.txt', 'compress me');
file_put_contents(dirname(__DIR__) . '/_files/Compress/First/zipextracted.txt', 'compress me');
file_put_contents(dirname(__DIR__) . '/_files/Compress/zipextracted.txt', 'compress me');
}
}
示例2: testAutoloadsNamespacedClassesWithUnderscores
public function testAutoloadsNamespacedClassesWithUnderscores()
{
$loader = new StandardAutoloader();
$loader->registerNamespace('ZendTest\\UnusualNamespace', __DIR__ . '/TestAsset');
$loader->autoload('ZendTest\\UnusualNamespace\\Name_Space\\Namespaced_Class');
$this->assertTrue(class_exists('ZendTest\\UnusualNamespace\\Name_Space\\Namespaced_Class', false));
}
示例3: testReturnsFalseForUnresolveableClassNames
public function testReturnsFalseForUnresolveableClassNames()
{
$loader = new StandardAutoloader();
$this->assertFalse($loader->autoload('Some\\Fake\\Classname'));
}
示例4: testCanActAsFallbackAutoloader
/**
* borrowed from Zend\Loader\StandardAutoloader
*/
public function testCanActAsFallbackAutoloader()
{
$loader = new StandardAutoloader();
$loader->setFallbackAutoloader(true);
set_include_path(__DIR__ . '/TestAsset/' . PATH_SEPARATOR . $this->includePath);
$loader->autoload('TestNamespace\TestProvider');
$loader->autoload('TestNamespace\TestInvalidProvider');
//initialize ini
$ini = __DIR__. '/_files/enable.ini';
file_put_contents($ini, '');
$clientConfig = new ClientConfig;
$clientConfig->setConfigFilePath($ini);
$this->_registry->setConfig($clientConfig);
$config = $this->_configProvider;
// Test enable provider
try {
$config->enableProvider('TestNamespace\TestInvalidProvider');
$this->fail('RuntimeException was expected but not thrown');
} catch (RuntimeException $re) {
}
$config->enableProvider('TestNamespace\TestProvider');
$configs = $clientConfig->basicloader->classes;
$this->assertEquals('TestNamespace\TestProvider', $configs->current());
// Test disable provider
try {
$config->disableProvider('TestNamespace\TestInvalidProvider');
$this->fail('RuntimeException was expected but not thrown');
} catch (RuntimeException $re) {
}
$config->disableProvider('TestNamespace\TestProvider');
$this->assertEmpty($configs->current(), 'No config setting will exists');
/**
* manifest test
*/
$loader->autoload('TestNamespace\TestManifest');
$loader->autoload('TestNamespace\TestInvalidManifest');
try {
$config->enableManifest('TestNamespace\TestInvalidManifest');
$this->fail('RuntimeException was expected but not thrown');
} catch (RuntimeException $re) {
}
$config->enableManifest('TestNamespace\TestManifest');
$configs = $clientConfig->basicloader->classes;
$this->assertEquals('TestNamespace\TestManifest', $configs->current());
try {
$config->disableManifest('TestNamespace\TestInvalidManifest');
$this->fail('RuntimeException was expected but not thrown');
} catch (RuntimeException $re) {
}
$config->disableManifest('TestNamespace\TestManifest');
$this->assertEmpty($configs->current(), 'No config setting will exists');
// cleanup
file_put_contents($ini, '');
}
示例5: testCanActAsFallbackAutoloader
/**
* borrowed from Zend\Loader\StandardAutoloader
*/
public function testCanActAsFallbackAutoloader()
{
$loader = new StandardAutoloader();
$loader->setFallbackAutoloader(true);
set_include_path(__DIR__ . '/TestAsset/' . PATH_SEPARATOR . $this->includePath);
$loader->autoload('TestNamespace\TestProvider');
$loader->autoload('TestNamespace\TestInvalidProvider');
//initialize ini
$ini = __DIR__. '/_files/enable.ini';
file_put_contents($ini, '');
$clientConfig = new ClientConfig;
$clientConfig->setConfigFilePath($ini);
$this->_registry->setConfig($clientConfig);
$config = $this->_configProvider;
try {
$config->enableProvider('TestNamespace\TestInvalidProvider');
$this->fail('RuntimeException was expected but not thrown');
} catch (RuntimeException $re) {
}
$config->enableProvider('TestNamespace\TestProvider');
$providers = $clientConfig->basicloader->classes->toArray();
$this->assertEquals('TestNamespace\TestProvider', current($providers));
file_put_contents($ini, '');
}
示例6: testWillLoopThroughAllNamespacesUntilMatchIsFoundWhenAutoloading
public function testWillLoopThroughAllNamespacesUntilMatchIsFoundWhenAutoloading()
{
$loader = new StandardAutoloader();
$loader->registerNamespace('ZendTest\\Loader\\TestAsset\\Parent', __DIR__ . '/TestAsset/Parent');
$loader->registerNamespace('ZendTest\\Loader\\TestAsset\\Parent\\Child', __DIR__ . '/TestAsset/Child');
$result = $loader->autoload('ZendTest\\Loader\\TestAsset\\Parent\\Child\\Subclass');
$this->assertTrue($result !== false);
$this->assertTrue(class_exists('ZendTest\\Loader\\TestAsset\\Parent\\Child\\Subclass', false));
}