1
0
mirror of synced 2025-01-17 22:11:41 +03:00

combined codes and docs manpages; deleted codes (obsolete)

This commit is contained in:
hansbrix 2007-04-12 20:52:30 +00:00
parent eed2a37037
commit 16e4296626
554 changed files with 2330 additions and 2041 deletions

View File

@ -1,32 +0,0 @@
<?php
class User {
public function setTableDefinition() {
$this->hasColumn("name", "string", 200);
$this->hasColumn("password", "string", 32);
}
public function setPassword($password) {
return md5($password);
}
public function getName($name) {
return strtoupper($name);
}
}
$user = new User();
$user->name = 'someone';
print $user->name; // someone
$user->password = '123';
print $user->password; // 123
$user->setAttribute(Doctrine::ATTR_LISTENER, new Doctrine_EventListener_AccessorInvoker());
print $user->name; // SOMEONE
$user->password = '123';
print $user->password; // 202cb962ac59075b964b07152d234b70
?>

View File

@ -1,34 +0,0 @@
<?php
class MyListener extends Doctrine_EventListener {
public function onLoad(Doctrine_Record $record) {
print $record->getTable()->getComponentName()." just got loaded!";
}
public function onSave(Doctrine_Record $record) {
print "saved data access object!";
}
}
class MyListener2 extends Doctrine_EventListener {
public function onPreUpdate() {
try {
$record->set("updated",time());
} catch(InvalidKeyException $e) {
}
}
}
// setting global listener
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_LISTENER,new MyListener());
// setting connection level listener
$conn = $manager->openConnection($dbh);
$conn->setAttribute(Doctrine::ATTR_LISTENER,new MyListener2());
// setting factory level listener
$table = $conn->getTable("User");
$table->setAttribute(Doctrine::ATTR_LISTENER,new MyListener());
?>

View File

@ -1,45 +0,0 @@
<?php
interface Doctrine_EventListener_Interface {
public function onLoad(Doctrine_Record $record);
public function onPreLoad(Doctrine_Record $record);
public function onUpdate(Doctrine_Record $record);
public function onPreUpdate(Doctrine_Record $record);
public function onCreate(Doctrine_Record $record);
public function onPreCreate(Doctrine_Record $record);
public function onSave(Doctrine_Record $record);
public function onPreSave(Doctrine_Record $record);
public function onInsert(Doctrine_Record $record);
public function onPreInsert(Doctrine_Record $record);
public function onDelete(Doctrine_Record $record);
public function onPreDelete(Doctrine_Record $record);
public function onEvict(Doctrine_Record $record);
public function onPreEvict(Doctrine_Record $record);
public function onSleep(Doctrine_Record $record);
public function onWakeUp(Doctrine_Record $record);
public function onClose(Doctrine_Connection $connection);
public function onPreClose(Doctrine_Connection $connection);
public function onOpen(Doctrine_Connection $connection);
public function onTransactionCommit(Doctrine_Connection $connection);
public function onPreTransactionCommit(Doctrine_Connection $connection);
public function onTransactionRollback(Doctrine_Connection $connection);
public function onPreTransactionRollback(Doctrine_Connection $connection);
public function onTransactionBegin(Doctrine_Connection $connection);
public function onPreTransactionBegin(Doctrine_Connection $connection);
public function onCollectionDelete(Doctrine_Collection $collection);
public function onPreCollectionDelete(Doctrine_Collection $collection);
}

View File

@ -1,13 +0,0 @@
<?php
$table = $conn->getTable("User");
$table->setEventListener(new MyListener2());
// retrieve user whose primary key is 2
$user = $table->find(2);
$user->name = "John Locke";
// update event will be listened and current time will be assigned to the field 'updated'
$user->save();
?>

View File

@ -1,61 +0,0 @@
At the page where the lock is requested...
<?php
// Get a locking manager instance
$lockingMngr = new Doctrine_Locking_Manager_Pessimistic();
try
{
// Ensure that old locks which timed out are released
// before we try to acquire our lock
// 300 seconds = 5 minutes timeout
$lockingMngr->releaseAgedLocks(300);
// Try to get the lock on a record
$gotLock = $lockingMngr->getLock(
// The record to lock. This can be any Doctrine_Record
$myRecordToLock,
// The unique identifier of the user who is trying to get the lock
'Bart Simpson'
);
if($gotLock)
{
echo "Got lock!";
// ... proceed
}
else
{
echo "Sorry, someone else is currently working on this record";
}
}
catch(Doctrine_Locking_Exception $dle)
{
echo $dle->getMessage();
// handle the error
}
?>
At the page where the transaction finishes...
<?php
// Get a locking manager instance
$lockingMngr = new Doctrine_Locking_Manager_Pessimistic();
try
{
if($lockingMngr->releaseLock($myRecordToUnlock, 'Bart Simpson'))
{
echo "Lock released";
}
else
{
echo "Record was not locked. No locks released.";
}
}
catch(Doctrine_Locking_Exception $dle)
{
echo $dle->getMessage();
// handle the error
}
?>

View File

@ -1,5 +0,0 @@
<?php
// turning on validation
Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_VLD, true);
?>

View File

@ -1,28 +0,0 @@
<?php
class User extends Doctrine_Record {
public function setUp() {
$this->ownsOne("Email","User.email_id");
}
public function setTableDefinition() {
// no special validators used only types
// and lengths will be validated
$this->hasColumn("name","string",15);
$this->hasColumn("email_id","integer");
$this->hasColumn("created","integer",11);
}
// Our own validation
protected function validate() {
if ($this->name == 'God') {
// Blasphemy! Stop that! ;-)
// syntax: add(<fieldName>, <error code/identifier>)
$this->getErrorStack()->add('name', 'forbiddenName');
}
}
}
class Email extends Doctrine_Record {
public function setTableDefinition() {
// validators 'email' and 'unique' used
$this->hasColumn("address","string",150, array("email", "unique"));
}
}
?>

View File

@ -1,30 +0,0 @@
<?php
try {
$user->name = "this is an example of too long name";
$user->Email->address = "drink@@notvalid..";
$user->save();
} catch(Doctrine_Validator_Exception $e) {
// Note: you could also use $e->getInvalidRecords(). The direct way
// used here is just more simple when you know the records you're dealing with.
$userErrors = $user->getErrorStack();
$emailErrors = $user->Email->getErrorStack();
/* Inspect user errors */
foreach($userErrors as $fieldName => $errorCodes) {
switch ($fieldName) {
case 'name':
// $user->name is invalid. inspect the error codes if needed.
break;
}
}
/* Inspect email errors */
foreach($emailErrors as $fieldName => $errorCodes) {
switch ($fieldName) {
case 'address':
// $user->Email->address is invalid. inspect the error codes if needed.
break;
}
}
}
?>

View File

@ -1,15 +0,0 @@
<?php
$conn = Doctrine_Manager::getInstance()
->openConnection(new PDO("dsn","username","password"));
$query = new Doctrine_Query($conn);
$query->from('User.Phonenumber')->limit(20);
$view = new Doctrine_View($query, 'MyView');
// creating a database view
$view->create();
// dropping the view from the database
$view->drop();
?>

View File

@ -1,13 +0,0 @@
<?php
$conn = Doctrine_Manager::getInstance()
->openConnection(new PDO("dsn","username","password"));
$query = new Doctrine_Query($conn);
$query->from('User.Phonenumber')->limit(20);
// hook the query into appropriate view
$view = new Doctrine_View($query, 'MyView');
// now fetch the data from the view
$coll = $view->execute();
?>

View File

@ -1,12 +0,0 @@
<?php
$sampleArray = array('Doctrine', 'ORM', 1, 2, 3);
$sampleArray = array(1, 2, 3,
$a, $b, $c,
56.44, $d, 500);
$sampleArray = array('first' => 'firstValue',
'second' => 'secondValue');

View File

@ -1,8 +0,0 @@
<?php
/**
* Documentation here
*/
class Doctrine_SampleClass {
// entire content of class
// must be indented four spaces
}

View File

@ -1,18 +0,0 @@
<?php
// literal string
$string = 'something';
// string contains apostrophes
$sql = "SELECT id, name FROM people WHERE name = 'Fred' OR name = 'Susan'";
// variable substitution
$greeting = "Hello $name, welcome back!";
// concatenation
$framework = 'Doctrine' . ' ORM ' . 'Framework';
// concatenation line breaking
$sql = "SELECT id, name FROM user "
. "WHERE name = ? "
. "ORDER BY name ASC";

View File

@ -1,6 +0,0 @@
<?php
class Doctrine_SomeClass {
const MY_CONSTANT = 'something';
}
print Doctrine_SomeClass::MY_CONSTANT;
?>

View File

@ -1,5 +0,0 @@
<?php
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_LISTENER, new MyListener());
?>

View File

@ -1,20 +0,0 @@
<?php
// setting a global level attribute
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_VLD, false);
// setting a connection level attribute
// (overrides the global level attribute on this connection)
$conn = $manager->openConnection(new PDO('dsn', 'username', 'pw'));
$conn->setAttribute(Doctrine::ATTR_VLD, true);
// setting a table level attribute
// (overrides the connection/global level attribute on this table)
$table = $conn->getTable('User');
$table->setAttribute(Doctrine::ATTR_LISTENER, new UserListener());
?>

View File

@ -1,5 +0,0 @@
<?php
// setting default batch size for batch collections
$manager->setAttribute(Doctrine::ATTR_BATCH_SIZE, 7);
?>

View File

@ -1,5 +0,0 @@
<?php
// setting default event listener
$manager->setAttribute(Doctrine::ATTR_LISTENER, new MyListener());
?>

View File

@ -1,5 +0,0 @@
<?php
// sets the default collection type (fetching strategy)
$manager->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_LAZY);
?>

View File

@ -1,5 +0,0 @@
<?php
// sets the default offset collection limit
$manager->setAttribute(Doctrine::ATTR_COLL_LIMIT, 10);
?>

View File

@ -1,5 +0,0 @@
<?php
// setting default lockmode
$manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_PESSIMISTIC);
?>

View File

@ -1,5 +0,0 @@
<?php
// turns automatic table creation off
$manager->setAttribute(Doctrine::ATTR_CREATE_TABLES, false);
?>

View File

@ -1,5 +0,0 @@
<?php
// turns transactional validation on
$manager->setAttribute(Doctrine::ATTR_VLD, true);
?>

View File

@ -1,39 +0,0 @@
<?php
$a = array('name' => 'userlist',
'add' => array(
'quota' => array(
'type' => 'integer',
'unsigned' => 1
)
),
'remove' => array(
'file_limit' => array(),
'time_limit' => array()
),
'change' => array(
'name' => array(
'length' => '20',
'definition' => array(
'type' => 'text',
'length' => 20
)
)
),
'rename' => array(
'sex' => array(
'name' => 'gender',
'definition' => array(
'type' => 'text',
'length' => 1,
'default' => 'M'
)
)
)
);
$dbh = new PDO('dsn','username','pw');
$conn = Doctrine_Manager::getInstance()->openConnection($dbh);
$conn->export->alterTable('mytable', $a);
?>

View File

@ -1,22 +0,0 @@
<?php
$dbh = new PDO('dsn','username','pw');
$conn = Doctrine_Manager::getInstance()->openConnection($dbh);
$fields = array('id' => array(
'type' => 'integer',
'autoincrement' => true),
'name' => array(
'type' => 'string',
'fixed' => true,
'length' => 8)
);
// the following option is mysql specific and
// skipped by other drivers
$options = array('type' => 'MYISAM');
$conn->export->createTable('mytable', $fields);
// on mysql this executes query:
// CREATE TABLE mytable (id INT AUTO_INCREMENT PRIMARY KEY,
// name CHAR(8));
?>

View File

@ -1,14 +0,0 @@
<?php
// POSITIONAL PARAMETERS:
$users = $conn->query("FROM User WHERE User.name = ?", array('Arnold'));
$users = $conn->query("FROM User WHERE User.id > ? AND User.name LIKE ?", array(50, 'A%'));
// NAMED PARAMETERS:
$users = $conn->query("FROM User WHERE User.name = :name", array(':name' => 'Arnold'));
$users = $conn->query("FROM User WHERE User.id > :id AND User.name LIKE :name", array(':id' => 50, ':name' => 'A%'));
?>

View File

@ -1,8 +0,0 @@
<?php
// finding all users whose email ends with '@gmail.com'
$users = $conn->query("FROM User u, u.Email e WHERE e.address LIKE '%@gmail.com'");
// finding all users whose name starts with letter 'A'
$users = $conn->query("FROM User u WHERE u.name LIKE 'A%'");
?>

View File

@ -1,19 +0,0 @@
<?php
// finding all users which don't belong to any group 1
$query = "FROM User WHERE User.id NOT IN
(SELECT u.id FROM User u
INNER JOIN u.Group g WHERE g.id = ?";
$users = $conn->query($query, array(1));
// finding all users which don't belong to any groups
// Notice:
// the usage of INNER JOIN
// the usage of empty brackets preceding the Group component
$query = "FROM User WHERE User.id NOT IN
(SELECT u.id FROM User u
INNER JOIN u.Group g)";
$users = $conn->query($query);
?>

View File

@ -1,16 +0,0 @@
<?php
$q = 'DELETE FROM Account WHERE id > ?';
$rows = $this->conn->query($q, array(3));
// the same query using the query interface
$q = new Doctrine_Query();
$rows = $q->delete('Account')
->from('Account a')
->where('a.id > ?', 3)
->execute();
print $rows; // the number of affected rows
?>

View File

@ -1,7 +0,0 @@
<?php
$q = new Doctrine_Query();
$q->from('User')->where('User.Phonenumber.phonenumber.contains(?,?,?)');
$users = $q->execute(array('123 123 123', '0400 999 999', '+358 100 100'));
?>

View File

@ -1,7 +0,0 @@
<?php
$q = new Doctrine_Query();
$q->from('User')->where('User.Phonenumber.phonenumber.like(?,?)');
$users = $q->execute(array('%123%', '456%'));
?>

View File

@ -1,7 +0,0 @@
<?php
$q = new Doctrine_Query();
$q->from('User')->where('User.Phonenumber.phonenumber.regexp(?,?)');
$users = $q->execute(array('[123]', '^[3-5]'));
?>

View File

@ -1,10 +0,0 @@
<?php
// retrieve all users and the phonenumber count for each user
$users = $conn->query("SELECT u.*, COUNT(p.id) count FROM User u, u.Phonenumber p GROUP BY u.id");
foreach($users as $user) {
print $user->name . ' has ' . $user->Phonenumber[0]->count . ' phonenumbers';
}
?>

View File

@ -1,26 +0,0 @@
<?php
// DO NOT USE THE FOLLOWING CODE
// (using many sql queries for object population):
$users = $conn->getTable('User')->findAll();
foreach($users as $user) {
print $user->name."<br \>";
foreach($user->Phonenumber as $phonenumber) {
print $phonenumber."<br \>";
}
}
// same thing implemented much more efficiently:
// (using only one sql query for object population)
$users = $conn->query("FROM User.Phonenumber");
foreach($users as $user) {
print $user->name."<br \>";
foreach($user->Phonenumber as $phonenumber) {
print $phonenumber."<br \>";
}
}
?>

Some files were not shown because too many files have changed in this diff Show More