Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
9dfab03e
Commit
9dfab03e
authored
Feb 17, 2009
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Small changes to ClassLoader and add basic unit test for it
parent
554adc32
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
31 deletions
+79
-31
ClassLoader.php
lib/Doctrine/Common/ClassLoader.php
+39
-28
AllTests.php
tests/Doctrine/Tests/Common/AllTests.php
+1
-0
ClassLoaderTest.php
tests/Doctrine/Tests/Common/ClassLoaderTest.php
+29
-0
ClassA.class.php
tests/Doctrine/Tests/Common/ClassLoaderTest/ClassA.class.php
+5
-0
ClassB.class.php
tests/Doctrine/Tests/Common/ClassLoaderTest/ClassB.class.php
+5
-0
TestInit.php
tests/Doctrine/Tests/TestInit.php
+0
-3
No files found.
lib/Doctrine/Common/ClassLoader.php
View file @
9dfab03e
...
...
@@ -16,47 +16,71 @@ namespace Doctrine\Common;
*
* 3) DO NOT setCheckFileExists(true). Doing so is expensive in terms of performance.
* 4) Use an opcode-cache (i.e. APC) (STRONGLY RECOMMENDED).
*
*
* @since 2.0
* @author
romanb
<roman@code-factory.org>
* @author
Roman S. Borschel
<roman@code-factory.org>
*/
class
ClassLoader
{
private
$_namespaceSeparator
=
'\\'
;
private
$_fileExtension
=
'.php'
;
private
$_checkFileExists
=
false
;
private
$_basePaths
=
array
();
{
private
$_namespaceSeparator
=
'\\'
,
$_fileExtension
=
'.php'
,
$_checkFileExists
=
false
,
$_basePaths
=
array
();
/**
* Constructor registers the autoloader automatically
*/
public
function
__construct
()
{
spl_autoload_register
(
array
(
$this
,
'loadClass'
));
}
/**
* Set check file exists
*
* @param boolean $bool
* @return void
*/
public
function
setCheckFileExists
(
$bool
)
{
$this
->
_checkFileExists
=
$bool
;
}
/**
* Set class file extension
*
* @param string $extension
* @return void
*/
public
function
setClassFileExtension
(
$extension
)
{
$this
->
_fileExtension
=
$extension
;
}
/**
* Set namespace separator
*
* @param string $separator
* @return void
*/
public
function
setNamespaceSeparator
(
$separator
)
{
$this
->
_namespaceSeparator
=
$separator
;
}
/**
* Sets a static base path for classes with a certain prefix that is prepended
* to the path derived from the class itself.
*
* @param string $classPrefix
* @param string $basePath
*/
public
function
setBasePath
(
$classPrefix
,
$basePath
)
{
$this
->
_basePaths
[
$classPrefix
]
=
$basePath
;
}
/**
* Loads the given class or interface.
*
...
...
@@ -86,20 +110,7 @@ class ClassLoader
}
require
$class
;
return
true
;
}
/**
* Registers this class loader using spl_autoload_register().
*
* @return void
*/
public
function
register
()
{
spl_autoload_register
(
array
(
$this
,
'loadClass'
));
}
}
?>
\ No newline at end of file
}
\ No newline at end of file
tests/Doctrine/Tests/Common/AllTests.php
View file @
9dfab03e
...
...
@@ -22,6 +22,7 @@ class AllTests
$suite
=
new
\Doctrine\Tests\DoctrineTestSuite
(
'Doctrine Common Tests'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\Common\EventManagerTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\Common\ClassLoaderTest'
);
$suite
->
addTest
(
Collections\AllTests
::
suite
());
...
...
tests/Doctrine/Tests/Common/ClassLoaderTest.php
0 → 100644
View file @
9dfab03e
<?php
namespace
Doctrine\Tests\Common
;
use
Doctrine\Common\ClassLoader
;
class
ClassLoaderTest
extends
\Doctrine\Tests\DoctrineTestCase
{
public
function
testCustomFileExtensionAndNamespaceSeparator
()
{
$classLoader
=
new
\Doctrine\Common\ClassLoader
();
$classLoader
->
setBasePath
(
'ClassLoaderTest'
,
__DIR__
);
$classLoader
->
setClassFileExtension
(
'.class.php'
);
$classLoader
->
setNamespaceSeparator
(
'_'
);
$this
->
assertEquals
(
$classLoader
->
loadClass
(
'ClassLoaderTest_ClassA'
),
true
);
$this
->
assertEquals
(
$classLoader
->
loadClass
(
'ClassLoaderTest_ClassB'
),
true
);
}
public
function
testClassLoaderCheckFileExists
()
{
$classLoader
=
new
\Doctrine\Common\ClassLoader
();
$classLoader
->
setBasePath
(
'ClassLoaderTest'
,
__DIR__
);
$classLoader
->
setCheckFileExists
(
true
);
// This would return a fatal error without check file exists true
$this
->
assertEquals
(
$classLoader
->
loadClass
(
'SomeInvalidClass'
),
false
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/Common/ClassLoaderTest/ClassA.class.php
0 → 100644
View file @
9dfab03e
<?php
class
ClassLoaderTest_ClassA
{
}
\ No newline at end of file
tests/Doctrine/Tests/Common/ClassLoaderTest/ClassB.class.php
0 → 100644
View file @
9dfab03e
<?php
class
ClassLoaderTest_ClassB
{
}
\ No newline at end of file
tests/Doctrine/Tests/TestInit.php
View file @
9dfab03e
...
...
@@ -9,9 +9,6 @@ require_once 'PHPUnit/TextUI/TestRunner.php';
require_once
'../lib/Doctrine/Common/ClassLoader.php'
;
$classLoader
=
new
\Doctrine\Common\ClassLoader
();
// checking for existance should not be necessary, remove as soon as possible
//$classLoader->setCheckFileExists(true);
$classLoader
->
register
();
$modelDir
=
__DIR__
.
DIRECTORY_SEPARATOR
.
'..'
.
DIRECTORY_SEPARATOR
.
'models'
;
set_include_path
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment