Skip to content

Commit

Permalink
Enabling namespaces. Final restructurings.
Browse files Browse the repository at this point in the history
  • Loading branch information
romanb committed Jan 22, 2009
1 parent 4ab2ba7 commit 22e94ac
Show file tree
Hide file tree
Showing 230 changed files with 2,187 additions and 1,882 deletions.
27 changes: 24 additions & 3 deletions lib/Doctrine/Common/ClassLoader.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace Doctrine\Common;

/**
* A class loader used to load class files on demand.
*
Expand All @@ -17,9 +20,9 @@
* @since 2.0
* @author romanb <roman@code-factory.org>
*/
class Doctrine_Common_ClassLoader
class ClassLoader
{
private $_namespaceSeparator = '_';
private $_namespaceSeparator = '\\';
private $_fileExtension = '.php';
private $_checkFileExists = false;
private $_basePaths = array();
Expand Down Expand Up @@ -71,7 +74,10 @@ public function loadClass($className)
if (isset($this->_basePaths[$prefix])) {
$class .= $this->_basePaths[$prefix] . DIRECTORY_SEPARATOR;
}
$class .= str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $className)

if ($className[0] == '\\') $className = substr($className, 1);

$class .= str_replace(array($this->_namespaceSeparator, '_'), DIRECTORY_SEPARATOR, $className)
. $this->_fileExtension;

if ($this->_checkFileExists) {
Expand All @@ -81,6 +87,21 @@ public function loadClass($className)
@fclose($fh);
}

if ($class == 'ForumAvatar.php' || $class == 'ForumUser.php') {
echo $class . PHP_EOL;
try {
throw new \Exception();
} catch (\Exception $e) {
echo $e->getTraceAsString();
}
} else if ($class == 'Doctrine/Common/Exceptions/DoctrineException.php') {
try {
throw new \Exception();
} catch (\Exception $e) {
echo $e->getTraceAsString();
}
}

require $class;

return true;
Expand Down
14 changes: 7 additions & 7 deletions lib/Doctrine/Common/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
* and open the template in the editor.
*/

#namespace Doctrine\Common\Collections;
namespace Doctrine\Common\Collections;

#use \Countable;
#use \IteratorAggregate;
#use \ArrayAccess;
use \Countable;
use \IteratorAggregate;
use \ArrayAccess;

/**
* A Collection is a wrapper around a php array and just like a php array a
* collection instance can be a list, a set or a map, depending on how it is used.
*
* @author robo
*/
class Doctrine_Common_Collections_Collection implements Countable, IteratorAggregate, ArrayAccess
class Collection implements Countable, IteratorAggregate, ArrayAccess
{
/**
* An array containing the entries of this collection.
Expand Down Expand Up @@ -323,7 +323,7 @@ public function getIterator()
*/
public function map(Closure $func)
{
return new Doctrine_Common_Collections_Collection(array_map($func, $this->_data));
return new Collection(array_map($func, $this->_data));
}

/**
Expand All @@ -334,7 +334,7 @@ public function map(Closure $func)
*/
public function filter(Closure $func)
{
return new Doctrine_Common_Collections_Collection(array_filter($this->_data, $func));
return new Collection(array_filter($this->_data, $func));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class Doctrine_Common_Exceptions_DoctrineException extends Exception
namespace Doctrine\Common;

class DoctrineException extends \Exception
{
private $_innerException;

Expand All @@ -21,4 +23,3 @@ public static function notImplemented($method, $class)
}
}

?>
11 changes: 6 additions & 5 deletions lib/Doctrine/Common/EventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* <http://www.phpdoctrine.org>.
*/

#namespace Doctrine\Common;
namespace Doctrine\Common;

use Doctrine\Common\Events\Event;

/**
* The EventManager is the central point of Doctrine's event listener system.
Expand All @@ -30,7 +32,7 @@
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @since 2.0
*/
class Doctrine_Common_EventManager
class EventManager
{
/**
* Map of registered listeners.
Expand All @@ -52,7 +54,7 @@ public function dispatchEvent($event)
$callback = $argIsCallback ? $event : $event->getType();

if (isset($this->_listeners[$callback])) {
$event = $argIsCallback ? new Doctrine_Event($event) : $event;
$event = $argIsCallback ? new Event($event) : $event;
foreach ($this->_listeners[$callback] as $listener) {
$listener->$callback($event);
}
Expand Down Expand Up @@ -103,10 +105,9 @@ public function addEventListener($events, $listener)
*
* @param Doctrine\Common\EventSubscriber $subscriber The subscriber.
*/
public function addEventSubscriber(Doctrine_Common_EventSubscriber $subscriber)
public function addEventSubscriber(EventSubscriber $subscriber)
{
$this->addEventListener($subscriber->getSubscribedEvents(), $subscriber);
}
}

?>
4 changes: 2 additions & 2 deletions lib/Doctrine/Common/EventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* <http://www.phpdoctrine.org>.
*/

#namespace Doctrine::Common;
namespace Doctrine\Common;

/**
* An EventSubscriber knows himself what events he is interested in.
Expand All @@ -33,7 +33,7 @@
* @since 2.0
* @version $Revision: 4653 $
*/
interface Doctrine_Common_EventSubscriber
interface EventSubscriber
{
public function getSubscribedEvents();
}
6 changes: 2 additions & 4 deletions lib/Doctrine/Common/Events/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@
* <http://www.phpdoctrine.org>.
*/

#namespace Doctrine\Common\Events;
namespace Doctrine\Common\Events;

/**
* Doctrine_Event
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @package Doctrine
* @subpackage Event
* @link www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_Common_Events_Event
class Event
{
/* Event callback constants */
const preDelete = 'preDelete';
Expand Down
10 changes: 6 additions & 4 deletions lib/Doctrine/DBAL/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
* <http://www.phpdoctrine.org>.
*/

#namespace Doctrine\DBAL;
namespace Doctrine\DBAL;

use Doctrine\DBAL\Types\Type;

/**
* Configuration container for the Doctrine DBAL.
Expand All @@ -30,7 +32,7 @@
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class Doctrine_DBAL_Configuration
class Configuration
{
/**
* The attributes that are contained in the configuration.
Expand Down Expand Up @@ -99,14 +101,14 @@ public function setTableNameFormat($format)
public function setCustomTypes(array $types)
{
foreach ($types as $name => $typeClassName) {
Doctrine_DBAL_Types_Type::addCustomType($name, $typeClassName);
Type::addCustomType($name, $typeClassName);
}
}

public function setTypeOverrides(array $overrides)
{
foreach ($override as $name => $typeClassName) {
Doctrine_DBAL_Types_Type::overrideType($name, $typeClassName);
Type::overrideType($name, $typeClassName);
}
}
}
19 changes: 10 additions & 9 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
* <http://www.phpdoctrine.org>.
*/

#namespace Doctrine\DBAL;
namespace Doctrine\DBAL;

#use Doctrine\Common\EventManager;
use Doctrine\Common\EventManager;
use Doctrine\Common\DoctrineException;
#use Doctrine\DBAL\Exceptions\ConnectionException;

/**
Expand Down Expand Up @@ -53,7 +54,7 @@
* Doctrine\DBAL could ship with a simple standard broker that uses a primitive
* round-robin approach to distribution. User can provide its own brokers.
*/
class Doctrine_DBAL_Connection
class Connection
{
/**
* Constant for transaction isolation level READ UNCOMMITTED.
Expand Down Expand Up @@ -155,9 +156,9 @@ class Doctrine_DBAL_Connection
*
* @param array $params The connection parameters.
*/
public function __construct(array $params, Doctrine_DBAL_Driver $driver,
Doctrine_DBAL_Configuration $config = null,
Doctrine_Common_EventManager $eventManager = null)
public function __construct(array $params, Driver $driver,
Configuration $config = null,
EventManager $eventManager = null)
{
$this->_driver = $driver;
$this->_params = $params;
Expand All @@ -169,10 +170,10 @@ public function __construct(array $params, Doctrine_DBAL_Driver $driver,

// Create default config and event manager if none given
if ( ! $config) {
$this->_config = new Doctrine_DBAL_Configuration();
$this->_config = new Configuration();
}
if ( ! $eventManager) {
$this->_eventManager = new Doctrine_Common_EventManager();
$this->_eventManager = new EventManager();
}

$this->_platform = $driver->getDatabasePlatform();
Expand Down Expand Up @@ -702,7 +703,7 @@ public function beginTransaction()
public function commit()
{
if ($this->_transactionNestingLevel == 0) {
throw new Doctrine_Exception("Commit failed. There is no active transaction.");
throw new DoctrineException("Commit failed. There is no active transaction.");
}

$this->connect();
Expand Down
8 changes: 5 additions & 3 deletions lib/Doctrine/DBAL/Driver.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

namespace Doctrine\DBAL;

/**
* Driver interface.
* Interface that all DBAL drivers must implement.
*
* @since 2.0
*/
interface Doctrine_DBAL_Driver
interface Driver
{
/**
* Attempts to create a connection with the database.
Expand All @@ -32,7 +35,6 @@ public function getDatabasePlatform();
*
* @return Doctrine\DBAL\SchemaManager
*/
public function getSchemaManager(Doctrine_DBAL_Connection $conn);
public function getSchemaManager(Connection $conn);
}

?>
4 changes: 3 additions & 1 deletion lib/Doctrine/DBAL/Driver/Connection.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Doctrine\DBAL\Driver;

/**
* Connection interface.
* Drivers must implement this interface.
Expand All @@ -8,7 +10,7 @@
*
* @since 2.0
*/
interface Doctrine_DBAL_Driver_Connection
interface Connection
{
public function prepare($prepareString);
public function query();
Expand Down
9 changes: 7 additions & 2 deletions lib/Doctrine/DBAL/Driver/PDOConnection.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<?php

namespace Doctrine\DBAL\Driver;

use \PDO;

/**
* PDO implementation of the driver Connection interface.
* Used by all PDO-based drivers.
*
* @since 2.0
*/
class Doctrine_DBAL_Driver_PDOConnection extends PDO implements Doctrine_DBAL_Driver_Connection
class PDOConnection extends PDO implements \Doctrine\DBAL\Driver\Connection
{
public function __construct($dsn, $user = null, $password = null, array $options = null)
{
parent::__construct($dsn, $user, $password, $options);
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine_DBAL_Driver_PDOStatement', array()));
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine\DBAL\Driver\PDOStatement', array()));
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
}
Expand Down
5 changes: 2 additions & 3 deletions lib/Doctrine/DBAL/Driver/PDOMsSql/Connection.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

#namespace Doctrine::DBAL::Driver::PDOMsSql;
namespace Doctrine\DBAL\Driver\PDOMsSql;

/**
* MsSql Connection implementation.
*
* @since 2.0
*/
class Doctrine_DBAL_Driver_PDOMsSql_Connection extends PDO implements Doctrine_DBAL_Driver_Connection
class Connection extends PDO implements \Doctrine\DBAL\Driver\Connection
{
/**
* Performs the rollback.
Expand Down Expand Up @@ -40,4 +40,3 @@ public function beginTransaction()
}
}

?>
Loading

0 comments on commit 22e94ac

Please sign in to comment.