Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://git.zendframework.com/zf
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkael committed Jul 15, 2010
3 parents 50ba497 + ca06bae + 9201751 commit 204968d
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/Autoloadable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,14 @@
*/
interface Autoloadable
{
/**
* Autoload a class
*
* @abstract
* @param $class
* @return mixed
* False [if unable to load $class]
* get_class($class) [if $class is successfully loaded]
*/
public function autoload($class);
}
8 changes: 4 additions & 4 deletions src/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ public static function autoload($class)
if ($autoloader->autoload($class)) {
return true;
}
} elseif (is_string($autoloader)) {
if ($autoloader($class)) {
} elseif (is_array($autoloader)) {
if (call_user_func($autoloader, $class)) {
return true;
}
} elseif (is_callable($autoloader)) {
if (call_user_func($autoloader, $class)) {
} elseif (is_string($autoloader) || is_callable($autoloader)) {
if ($autoloader($class)) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/AutoloadDoesNotHideParseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@

Zend_Loader::registerAutoload();

set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/_files');
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . '/_files');

$parseError = new ParseError();
2 changes: 1 addition & 1 deletion test/AutoloaderMultiVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testSettingZfPathFailsWhenBasePathDoesNotExist()
*/
public function testSettingZfVersionFailsWhenNoValidInstallsDiscovered()
{
$this->autoloader->setZfPath(dirname(__FILE__), 'latest');
$this->autoloader->setZfPath(__DIR__, 'latest');
}

public function testAutoloadLatestUsesLatestVersion()
Expand Down
18 changes: 17 additions & 1 deletion test/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,25 @@ public function testUsingAlternateDefaultLoaderShouldOverrideUsageOfZendLoader()
$this->assertFalse(class_exists($class, false));
}

/**
* @group ZF-10024
*/
public function testClosuresRegisteredWithAutoloaderShouldBeUtilized()
{
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
$this->markTestSkipped(__METHOD__ . ' requires PHP version 5.3.0 or greater');
}

$this->autoloader->pushAutoloader(function($class) {
require_once __DIR__ . '/_files/AutoloaderClosure.php';
});
$test = new AutoloaderTest_AutoloaderClosure();
$this->assertTrue($test instanceof AutoloaderTest_AutoloaderClosure);
}

public function addTestIncludePath()
{
set_include_path(dirname(__FILE__) . '/_files/' . PATH_SEPARATOR . $this->includePath);
set_include_path(__DIR__ . '/_files/' . PATH_SEPARATOR . $this->includePath);
}

public function handleErrors($errno, $errstr)
Expand Down
29 changes: 28 additions & 1 deletion test/LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testLoaderClassValid()
public function testLoaderInterfaceViaLoadClass()
{
try {
Loader::loadClass('\\Zend_Controller_Dispatcher_Interface');
Loader::loadClass('Zend\Controller\Dispatcher');
} catch (\Zend_Exception $e) {
$this->fail('Loading interfaces should not fail');
}
Expand Down Expand Up @@ -220,6 +220,19 @@ public function testLoaderIsReadable()
$this->assertTrue(Loader::isReadable('Zend/Controller/Front.php'), get_include_path());
}

public function testLoaderRegisterAutoloadFailsWithoutSplAutoload()
{
if (function_exists('spl_autoload_register')) {
$this->markTestSkipped("spl_autoload() is installed on this PHP installation; cannot test for failure");
}

try {
Loader::registerAutoload();
$this->fail('registerAutoload should fail without spl_autoload');
} catch (Zend_Exception $e) {
}
}

/**
* @group ZF-8200
*/
Expand Down Expand Up @@ -289,4 +302,18 @@ public function testIsReadableShouldReturnTrueForAbsolutePaths()
$path = __DIR__;
$this->assertTrue(Loader::isReadable($path));
}

/**
* @group ZF-9263
* @group ZF-9166
* @group ZF-9306
*/
public function testIsReadableShouldFailEarlyWhenProvidedInvalidWindowsAbsolutePath()
{
if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
$this->markTestSkipped('Windows-only test');
}
$path = 'C:/this/file/should/not/exist.php';
$this->assertFalse(Loader::isReadable($path));
}
}
10 changes: 5 additions & 5 deletions test/PluginLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function testClassFilesAreSearchedInLifoOrder()
{
$loader = new PluginLoader(array());
$loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
$loader->addPrefixPath('ZfTest', dirname(__FILE__) . '/_files/ZfTest');
$loader->addPrefixPath('ZfTest', __DIR__ . '/_files/ZfTest');
try {
$className = $loader->load('FormSubmit');
} catch (Exception $e) {
Expand Down Expand Up @@ -383,7 +383,7 @@ public function testPluginLoaderShouldAllowSpecifyingIncludeFileCache()
public function testPluginLoaderShouldThrowExceptionWhenPathDoesNotExist()
{
$this->setExpectedException('\\Zend\\Loader\\PluginLoaderException', 'file does not exist');
$cacheFile = dirname(__FILE__) . '/_filesDoNotExist/includeCache.inc.php';
$cacheFile = __DIR__ . '/_filesDoNotExist/includeCache.inc.php';
$this->testIncludeCacheShouldBeNullByDefault();
PluginLoader::setIncludeFileCache($cacheFile);
}
Expand All @@ -397,7 +397,7 @@ public function testPluginLoaderShouldAppendIncludeCacheWhenClassIsFound()
PluginLoader::setIncludeFileCache($cacheFile);
$loader = new PluginLoader(array());
$loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
$loader->addPrefixPath('ZfTest', dirname(__FILE__) . '/_files/ZfTest');
$loader->addPrefixPath('ZfTest', __DIR__ . '/_files/ZfTest');
try {
$className = $loader->load('CacheTest');
} catch (Exception $e) {
Expand Down Expand Up @@ -433,7 +433,7 @@ public function testClassFilesGrabCorrectPathForLoadedClasses()

$loader = new PluginLoader(array());
$loader->addPrefixPath('Zend_View_Helper', $this->libPath . '/Zend/View/Helper');
$loader->addPrefixPath('ZfTest', dirname(__FILE__) . '/_files/ZfTest');
$loader->addPrefixPath('ZfTest', __DIR__ . '/_files/ZfTest');
try {
// Class in /Zend/View/Helper and not in /_files/ZfTest
$className = $loader->load('DeclareVars');
Expand All @@ -452,7 +452,7 @@ public function testClassFilesGrabCorrectPathForLoadedClasses()
public function testPrefixesEndingInBackslashDenoteNamespacedClasses()
{
$loader = new PluginLoader(array());
$loader->addPrefixPath('Zfns\\', dirname(__FILE__) . '/_files/Zfns');
$loader->addPrefixPath('Zfns\\', __DIR__ . '/_files/Zfns');
try {
$className = $loader->load('Foo');
} catch (Exception $e) {
Expand Down
5 changes: 5 additions & 0 deletions test/_files/AutoloaderClosure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

class AutoloaderTest_AutoloaderClosure
{
}

0 comments on commit 204968d

Please sign in to comment.