From abdcd65a150085fa8acd30b30833212683344810 Mon Sep 17 00:00:00 2001 From: doctrine Date: Wed, 7 Jun 2006 20:10:21 +0000 Subject: [PATCH] Removed legacy classes --- Doctrine/Debugger.php | 151 ------------------ Doctrine/Sensei/Sensei.class.php | 264 ------------------------------- tests/SenseiTestCase.php | 113 ------------- 3 files changed, 528 deletions(-) delete mode 100644 Doctrine/Debugger.php delete mode 100644 Doctrine/Sensei/Sensei.class.php delete mode 100644 tests/SenseiTestCase.php diff --git a/Doctrine/Debugger.php b/Doctrine/Debugger.php deleted file mode 100644 index dc81c8c96..000000000 --- a/Doctrine/Debugger.php +++ /dev/null @@ -1,151 +0,0 @@ -object = $object; - $this->code = $code; - } - final public function getCode() { - return $this->code; - } - final public function getObject() { - return $this->object; - } -} -class Doctrine_Debugger extends Doctrine_EventListener { - const EVENT_LOAD = 1; - const EVENT_PRELOAD = 2; - const EVENT_SLEEP = 3; - const EVENT_WAKEUP = 4; - const EVENT_UPDATE = 5; - const EVENT_PREUPDATE = 6; - const EVENT_CREATE = 7; - const EVENT_PRECREATE = 8; - - const EVENT_SAVE = 9; - const EVENT_PRESAVE = 10; - const EVENT_INSERT = 11; - const EVENT_PREINSERT = 12; - const EVENT_DELETE = 13; - const EVENT_PREDELETE = 14; - const EVENT_EVICT = 15; - const EVENT_PREEVICT = 16; - const EVENT_CLOSE = 17; - const EVENT_PRECLOSE = 18; - - const EVENT_OPEN = 19; - const EVENT_COMMIT = 20; - const EVENT_PRECOMMIT = 21; - const EVENT_ROLLBACK = 22; - const EVENT_PREROLLBACK = 23; - const EVENT_BEGIN = 24; - const EVENT_PREBEGIN = 25; - const EVENT_COLLDELETE = 26; - const EVENT_PRECOLLDELETE = 27; - private $debug; - - public function getMessages() { - return $this->debug; - } - - - public function onLoad(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_LOAD); - } - public function onPreLoad(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PRELOAD); - } - - public function onSleep(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_SLEEP); - } - - public function onWakeUp(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_WAKEUP); - } - - public function onUpdate(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_UPDATE); - } - public function onPreUpdate(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREUPDATE); - } - - public function onCreate(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_CREATE); - } - public function onPreCreate(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PRECREATE); - } - - public function onSave(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_SAVE); - } - public function onPreSave(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PRESAVE); - } - - public function onInsert(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_INSERT); - } - public function onPreInsert(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREINSERT); - } - - public function onDelete(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_DELETE); - } - public function onPreDelete(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREDELETE); - } - - public function onEvict(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_EVICT); - } - public function onPreEvict(Doctrine_Record $record) { - $this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_PREEVICT); - } - - public function onClose(Doctrine_Session $session) { - $this->debug[] = new Doctrine_DebugMessage($session,self::EVENT_CLOSE); - } - public function onPreClose(Doctrine_Session $session) { - $this->debug[] = new Doctrine_DebugMessage($session,self::EVENT_PRECLOSE); - } - - public function onOpen(Doctrine_Session $session) { - $this->debug[] = new Doctrine_DebugMessage($session,self::EVENT_OPEN); - } - - public function onTransactionCommit(Doctrine_Session $session) { - $this->debug[] = new Doctrine_DebugMessage($session,self::EVENT_COMMIT); - } - public function onPreTransactionCommit(Doctrine_Session $session) { - $this->debug[] = new Doctrine_DebugMessage($session,self::EVENT_PRECOMMIT); - } - - public function onTransactionRollback(Doctrine_Session $session) { - $this->debug[] = new Doctrine_DebugMessage($session,self::EVENT_ROLLBACK); - } - public function onPreTransactionRollback(Doctrine_Session $session) { - $this->debug[] = new Doctrine_DebugMessage($session,self::EVENT_PREROLLBACK); - } - - public function onTransactionBegin(Doctrine_Session $session) { - $this->debug[] = new Doctrine_DebugMessage($session,self::EVENT_BEGIN); - } - public function onPreTransactionBegin(Doctrine_Session $session) { - $this->debug[] = new Doctrine_DebugMessage($session,self::EVENT_PREBEGIN); - } - - public function onCollectionDelete(Doctrine_Collection $collection) { - $this->debug[] = new Doctrine_DebugMessage($collection,self::EVENT_COLLDELETE); - } - public function onPreCollectionDelete(Doctrine_Collection $collection) { - $this->debug[] = new Doctrine_DebugMessage($collection,self::EVENT_PRECOLLDELETE); - } -} -?> diff --git a/Doctrine/Sensei/Sensei.class.php b/Doctrine/Sensei/Sensei.class.php deleted file mode 100644 index 2f4b6c9ab..000000000 --- a/Doctrine/Sensei/Sensei.class.php +++ /dev/null @@ -1,264 +0,0 @@ -hasColumn("loginname","string",32,"unique"); - $this->hasColumn("password","string",32); - } -} -class Sensei_Variable extends Doctrine_Record { - /** - * setUp - * initializes relations and options - * - * @return void - */ - public function setUp() { - //$this->setAttribute(Doctrine::ATTR_COLL_KEY, "name"); - } - /** - * setTableDefinition - * initializes column definitions - * - * @return void - */ - public function setTableDefinition() { - $this->hasColumn("name","string",50,"unique"); - $this->hasColumn("value","string",10000); - $this->hasColumn("session_id","integer"); - } -} -class Sensei_Session extends Doctrine_Record { - /** - * setUp - * initializes relations and options - * - * @return void - */ - public function setUp() { - $this->ownsMany("Sensei_Variable","Sensei_Variable.session_id"); - $this->hasOne("Sensei_Entity","Sensei_Session.entity_id"); - } - /** - * setTableDefinition - * initializes column definitions - * - * @return void - */ - public function setTableDefinition() { - $this->hasColumn("session_id","string",32); - $this->hasColumn("logged_in","integer",1); - $this->hasColumn("entity_id","integer"); - $this->hasColumn("user_agent","string",200); - $this->hasColumn("updated","integer"); - $this->hasColumn("created","integer"); - } -} -class Sensei_Exception extends Exception { } -class Sensei extends Doctrine_Access { - const ATTR_LIFESPAN = 0; - /** - * @var Sensei_Session $record - */ - private $record; - /** - * @var Doctrine_Session $session - */ - private $session; - /** - * @var Doctrine_Table $table - */ - private $table; - /** - * @var array $attributes - */ - private $attributes = array(); - /** - * @var Doctrine_Collection $vars - */ - private $vars; - - - public function __construct() { - if(headers_sent()) - throw new Sensei_Exception("Headers already sent. Couldn't initialize session."); - - $this->session = Doctrine_Manager::getInstance()->getCurrentSession(); - $this->table = $this->session->getTable("Sensei_session"); - $this->init(); - - - $this->gc(1); - - if( ! isset($_SESSION)) - session_start(); - - } - /** - * getRecord - */ - public function getRecord() { - return $this->record; - } - /** - * init - */ - private function init() { - session_set_save_handler( - array($this,"open"), - array($this,"close"), - array($this,"read"), - array($this,"write"), - array($this,"destroy"), - array($this,"gc") - ); - } - /** - * @param string $username - * @param string $password - * @return boolean - */ - public function login($username,$password) { - $coll = $this->session->query("FROM Sensei_Entity WHERE Sensei_Entity.loginname = ? && Sensei_Entity.password = ?",array($username,$password)); - if(count($coll) > 0) { - $this->record->logged_in = 1; - $this->record->entity_id = $coll[0]->getID(); - $this->record->save(); - return true; - } - return false; - } - /** - * logout - * @return boolean - */ - public function logout() { - if( $this->record->logged_in == true) { - $this->record->logged_in = 0; - $this->record->entity_id = 0; - return true; - } else { - return false; - } - } - /** - * returns a session variable - * - * @param mixed $name - * @return mixed - */ - public function get($name) { - foreach($this->vars as $var) { - if($var->name == $name) { - return $var->value; - } - } - } - /** - * sets a session variable - * returns true on success, false on failure - * - * @param mixed $name - * @param mixed $value - * @return boolean - */ - public function set($name,$value) { - foreach($this->vars as $var) { - if($var->name == $name) { - $var->value = $value; - return true; - } - } - return false; - } - /** - * @param integer $attr - * @param mixed $value - */ - public function setAttribute($attr, $value) { - switch($attr): - case Sensei::ATTR_LIFESPAN: - - break; - default: - throw new Sensei_Exception("Unknown attribute"); - endswitch; - - $this->attributes[$attr] = $value; - } - /** - * @return boolean - */ - private function open($save_path,$session_name) { - return true; - } - /** - * @return boolean - */ - public function close() { - return true; - } - /** - * always returns an empty string - * - * @param string $id php session identifier - * @return string - */ - private function read($id) { - $coll = $this->session->query("FROM Sensei_Session, Sensei_Session.Sensei_Variable WHERE Sensei_Session.session_id = ?",array($id)); - $this->record = $coll[0]; - $this->record->user_agent = $_SERVER['HTTP_USER_AGENT']; - $this->record->updated = time(); - $this->record->session_id = $id; - $this->vars = $this->record->Sensei_Variable; - - if($this->record->getState() == Doctrine_Record::STATE_TDIRTY) { - $this->record->created = time(); - $this->record->save(); - } - return ""; - } - /** - * @return boolean - */ - public function write($id,$sess_data) { - return true; - } - /** - * @param string $id php session identifier - * @return Doctrine_Record - */ - private function destroy($id) { - $this->record->delete(); - return $this->record; - } - /** - * @param integer $maxlifetime - */ - private function gc($maxlifetime) { - return true; - } - /** - * flush - * makes all changes persistent - */ - public function flush() { - $this->record->save(); - } - /** - * destructor - */ - public function __destruct() { - $this->flush(); - } -} -?> diff --git a/tests/SenseiTestCase.php b/tests/SenseiTestCase.php deleted file mode 100644 index a807262ba..000000000 --- a/tests/SenseiTestCase.php +++ /dev/null @@ -1,113 +0,0 @@ -manager = Doctrine_Manager::getInstance(); - $this->manager->setAttribute(Doctrine::ATTR_CACHE, Doctrine::CACHE_NONE); - - if($this->manager->count() > 0) { - $this->session = $this->manager->getSession(0); - $this->session->clear(); - $this->dbh = $this->session->getDBH(); - $this->listener = $this->manager->getAttribute(Doctrine::ATTR_LISTENER); - } else { - $this->dbh = Doctrine_DB::getConnection(); - $this->session = $this->manager->openSession($this->dbh); - } - - - - $this->tables = array("sensei_group","sensei_user","sensei_entity","sensei_session","sensei_variable"); - $tables = $this->tables; - foreach($tables as $name) { - $this->dbh->query("DROP TABLE IF EXISTS $name"); - } - - $this->sensei = new Sensei(); - - $entity = new Sensei_Entity(); - - $entity->loginname = "Chuck Norris"; - $entity->password = "toughguy"; - - $entity->save(); - - $this->init = true; - - $this->record = $this->sensei->getRecord(); - } - public function setUp() { - if( ! $this->init) - $this->init(); - } - - public function testConstructor() { - $this->assertTrue($this->record instanceof Sensei_Session); - - if(isset($_COOKIE["PHPSESSID"])) { - $this->assertEqual($this->record->session_id, $_COOKIE["PHPSESSID"]); - } - $updated = $this->record->updated; - $this->assertFalse(empty($updated)); - $created = $this->record->created; - $this->assertFalse(empty($created)); - - $this->assertEqual($this->record->user_agent, $_SERVER['HTTP_USER_AGENT']); - - // make the changes persistent - - $this->sensei->flush(); - - if(isset($_COOKIE["PHPSESSID"])) { - $this->assertEqual($this->record->session_id, $_COOKIE["PHPSESSID"]); - } - $updated = $this->record->updated; - $this->assertFalse(empty($updated)); - $created = $this->record->created; - $this->assertFalse(empty($created)); - - $this->assertEqual($this->record->user_agent, $_SERVER['HTTP_USER_AGENT']); - } - - public function testLogin() { - - $this->assertFalse($this->sensei->login('Chuck Norris','unknown')); - $this->assertEqual($this->record->logged_in, null); - - $this->assertEqual($this->record->entity_id, null); - - $this->assertTrue($this->sensei->login('Chuck Norris','toughguy')); - $this->assertEqual($this->record->logged_in, 1); - - $this->assertEqual($this->record->entity_id, 1); - } - - public function testLogout() { - $this->assertTrue($this->sensei->logout()); - $this->assertEqual($this->record->logged_in, 0); - - $this->assertEqual($this->record->entity_id, 0); - $this->assertEqual($this->record->getState(), Doctrine_Record::STATE_DIRTY); - $this->assertEqual($this->record->getTable()->getIdentifierType(), Doctrine_Identifier::AUTO_INCREMENT); - - $this->assertEqual($this->record->getID(), 1); - - $this->sensei->flush(); - - $this->assertEqual($this->record->logged_in, 0); - - $this->assertEqual($this->record->entity_id, 0); - } -} -?>