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
cb79b1d9
Commit
cb79b1d9
authored
Apr 16, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
b6e93657
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
219 additions
and
42 deletions
+219
-42
Collection.class.php
classes/Collection.class.php
+40
-10
Batch.class.php
classes/Collection/Batch.class.php
+10
-0
Immediate.class.php
classes/Collection/Immediate.class.php
+6
-4
Configurable.class.php
classes/Configurable.class.php
+12
-3
Parser.class.php
classes/DQL/Parser.class.php
+17
-7
Doctrine.class.php
classes/Doctrine.class.php
+5
-1
IndexGenerator.php
classes/IndexGenerator.php
+26
-0
Record.class.php
classes/Record.class.php
+1
-1
Sensei.class.php
classes/Sensei/Sensei.class.php
+6
-6
Table.class.php
classes/Table.class.php
+9
-2
CollectionTestCase.class.php
tests/CollectionTestCase.class.php
+55
-2
ConfigurableTestCase.class.php
tests/ConfigurableTestCase.class.php
+23
-0
SenseiTestCase.class.php
tests/SenseiTestCase.class.php
+1
-2
classes.php
tests/classes.php
+1
-1
run.php
tests/run.php
+7
-3
No files found.
classes/Collection.class.php
View file @
cb79b1d9
...
...
@@ -33,12 +33,21 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* @var boolean $expanded whether or not this collection has been expanded
*/
protected
$expanded
=
false
;
/**
* @var mixed $generator
*/
protected
$generator
;
/**
* constructor
*/
public
function
__construct
(
Doctrine_Table
$table
)
{
$this
->
table
=
$table
;
$name
=
$table
->
getAttribute
(
Doctrine
::
ATTR_COLL_KEY
);
if
(
$name
!==
null
)
{
$this
->
generator
=
new
Doctrine_IndexGenerator
(
$name
);
}
}
/**
* @return object Doctrine_Table
...
...
@@ -46,6 +55,25 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
public
function
getTable
()
{
return
$this
->
table
;
}
/**
* @param Doctrine_IndexGenerator $generator
* @return void
*/
public
function
setGenerator
(
$generator
)
{
$this
->
generator
=
$generator
;
}
/**
* @return Doctrine_IndexGenerator
*/
public
function
getGenerator
()
{
return
$this
->
generator
;
}
/**
* @return array
*/
public
function
getData
()
{
return
$this
->
data
;
}
/**
* @param array $data
*/
...
...
@@ -214,7 +242,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
/**
* count
* this class implements interface countable
* @return integer
number of data access object
s in this collection
* @return integer
number of record
s in this collection
*/
public
function
count
()
{
return
count
(
$this
->
data
);
...
...
@@ -231,11 +259,11 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this
->
data
[
$key
]
=
$record
;
}
/**
* add
* adds a dao instance to this collection
* @param Doctrine_Record $record data access object to be added
* @param string $key optional key for the DAO
* adds a record to collection
* @param Doctrine_Record $record record to be added
* @param string $key optional key for the record
* @return boolean
*/
public
function
add
(
Doctrine_Record
$record
,
$key
=
null
)
{
...
...
@@ -243,27 +271,29 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$record
->
rawSet
(
$this
->
reference_field
,
$this
->
reference
);
if
(
isset
(
$key
))
{
if
(
isset
(
$this
->
data
[
$key
]))
return
false
;
$this
->
data
[
$key
]
=
$record
;
}
$this
->
data
[]
=
$record
;
if
(
isset
(
$this
->
generator
))
{
$key
=
$this
->
generator
->
getIndex
(
$record
);
$this
->
data
[
$key
]
=
$record
;
}
else
$this
->
data
[]
=
$record
;
return
true
;
}
/**
* save
* saves all
data access object
s
* saves all
record
s
*/
public
function
save
()
{
$this
->
table
->
getSession
()
->
saveCollection
(
$this
);
}
/**
* single shot delete
* deletes all
dao instance
s from this collection
* deletes all
record
s from this collection
* uses only one database query to perform this operation
* @return boolean
*/
...
...
classes/Collection/Batch.class.php
View file @
cb79b1d9
...
...
@@ -23,10 +23,19 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
public
function
__construct
(
Doctrine_DQL_Parser
$graph
,
$key
)
{
parent
::
__construct
(
$graph
->
getTable
(
$key
));
$this
->
data
=
$graph
->
getData
(
$key
);
if
(
!
is_array
(
$this
->
data
))
$this
->
data
=
array
();
if
(
isset
(
$this
->
generator
))
{
foreach
(
$this
->
data
as
$k
=>
$v
)
{
$record
=
$this
->
get
(
$k
);
$i
=
$this
->
generator
->
getIndex
(
$record
);
$this
->
data
[
$i
]
=
$record
;
unset
(
$this
->
data
[
$k
]);
}
}
$this
->
batchSize
=
$this
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_BATCH_SIZE
);
}
...
...
@@ -138,6 +147,7 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
if
(
!
isset
(
$this
->
data
[
$key
]))
$this
->
data
[
$key
]
=
$this
->
table
->
create
();
}
...
...
classes/Collection/Immediate.class.php
View file @
cb79b1d9
...
...
@@ -13,16 +13,18 @@ class Doctrine_Collection_Immediate extends Doctrine_Collection {
* @param integer $key
*/
public
function
__construct
(
Doctrine_DQL_Parser
$graph
,
$key
)
{
parent
::
__construct
(
$graph
->
getTable
(
$key
));
$name
=
$this
->
table
->
getComponentName
();
$table
=
$graph
->
getTable
(
$key
);
parent
::
__construct
(
$table
);
$name
=
$table
->
getComponentName
();
$data
=
$graph
->
getData
(
$name
);
if
(
is_array
(
$data
))
{
foreach
(
$data
as
$k
=>
$v
)
:
$t
his
->
t
able
->
setData
(
$v
);
$table
->
setData
(
$v
);
$this
->
add
(
$this
->
table
->
getRecord
());
endforeach
;
}
}
}
?>
classes/Configurable.class.php
View file @
cb79b1d9
...
...
@@ -86,16 +86,25 @@ abstract class Doctrine_Configurable {
break
;
case
Doctrine
::
ATTR_CREATE_TABLES
:
$value
=
(
bool
)
$value
;
break
;
case
Doctrine
::
ATTR_COLL_KEY
:
if
(
!
(
$this
instanceof
Doctrine_Table
))
throw
new
Doctrine_Exception
(
"This attribute can only be set at table level."
);
if
(
!
$this
->
hasColumn
(
$value
))
throw
new
Doctrine_Exception
(
"Couldn't set collection key attribute. No such column '
$value
'"
);
break
;
case
Doctrine
::
ATTR_VLD
:
break
;
case
Doctrine
::
ATTR_CACHE
:
if
(
$value
!=
Doctrine
::
CACHE_SQLITE
&&
$value
!=
Doctrine
::
CACHE_NONE
)
throw
new
Doctrine_Exception
(
"Unknown cache container. See Doctrine::CACHE_* constants for availible containers."
);
throw
new
Doctrine_Exception
(
"Unknown cache container. See Doctrine::CACHE_* constants for availible containers."
);
break
;
default
:
throw
new
Exception
(
"Unknown attribute."
);
throw
new
Doctrine_
Exception
(
"Unknown attribute."
);
endswitch
;
$this
->
attributes
[
$attribute
]
=
$value
;
...
...
@@ -115,7 +124,7 @@ abstract class Doctrine_Configurable {
final
public
function
getAttribute
(
$attribute
)
{
$attribute
=
(
int
)
$attribute
;
if
(
$attribute
<
1
||
$attribute
>
1
4
)
if
(
$attribute
<
1
||
$attribute
>
1
5
)
throw
new
InvalidKeyException
();
if
(
!
isset
(
$this
->
attributes
[
$attribute
]))
{
...
...
classes/DQL/Parser.class.php
View file @
cb79b1d9
...
...
@@ -128,6 +128,18 @@ class Doctrine_DQL_Parser {
}
}
}
/**
* @param integer $limit
*/
final
public
function
setLimit
(
$limit
)
{
$this
->
limit
=
$limit
;
}
/**
* @param integer $offset
*/
final
public
function
setOffset
(
$offset
)
{
$this
->
offset
=
$offset
;
}
/**
* @return integer
*/
...
...
@@ -422,7 +434,7 @@ class Doctrine_DQL_Parser {
if
(
$this
->
aggregate
)
{
$keys
=
array_keys
(
$this
->
tnames
);
$query
=
$this
->
getQuery
();
$stmt
=
$this
->
tnames
[
$keys
[
0
]]
->
getSession
()
->
select
(
$query
);
$stmt
=
$this
->
tnames
[
$keys
[
0
]]
->
getSession
()
->
select
(
$query
,
$this
->
limit
,
$this
->
offset
);
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_ASSOC
);
if
(
count
(
$data
)
==
1
)
{
return
current
(
$data
);
...
...
@@ -454,7 +466,7 @@ class Doctrine_DQL_Parser {
case
"order"
:
$p
=
$part
;
$i
=
$k
+
1
;
if
(
isset
(
$e
[
$i
])
AND
strtolower
(
$e
[
$i
])
==
"by"
)
{
if
(
isset
(
$e
[
$i
])
&&
strtolower
(
$e
[
$i
])
==
"by"
)
{
$parts
[
$part
]
=
array
();
}
break
;
...
...
@@ -633,7 +645,7 @@ class Doctrine_DQL_Parser {
* @param string $e2 the second bracket, usually ')'
*/
public
static
function
bracketTrim
(
$str
,
$e1
,
$e2
)
{
if
(
substr
(
$str
,
0
,
1
)
==
$e1
AND
substr
(
$str
,
-
1
)
==
$e2
)
if
(
substr
(
$str
,
0
,
1
)
==
$e1
&&
substr
(
$str
,
-
1
)
==
$e2
)
return
substr
(
$str
,
1
,
-
1
);
else
return
$str
;
...
...
@@ -781,10 +793,8 @@ class Doctrine_DQL_Parser {
$this
->
tnames
[
$name
]
=
$objTable
;
}
}
catch
(
Doctrine_Exception
$e
)
{
throw
new
DQLException
();
}
catch
(
InvalidKeyException
$e
)
{
throw
new
DQLException
();
}
catch
(
Exception
$e
)
{
throw
new
DQLException
(
$e
->
getMessage
(),
$e
->
getCode
());
}
}
return
$objTable
;
...
...
classes/Doctrine.class.php
View file @
cb79b1d9
...
...
@@ -116,6 +116,10 @@ final class Doctrine {
* create tables attribute
*/
const
ATTR_CREATE_TABLES
=
14
;
/**
* collection key attribute
*/
const
ATTR_COLL_KEY
=
15
;
...
...
@@ -189,7 +193,7 @@ final class Doctrine {
public
static
function
getPath
()
{
if
(
!
self
::
$path
)
self
::
$path
=
dirname
(
__FILE__
);
return
self
::
$path
;
}
/**
...
...
classes/IndexGenerator.php
0 → 100644
View file @
cb79b1d9
<?php
class
Doctrine_IndexGenerator
{
/**
* @var string $name
*/
private
$name
;
/**
* @param string $name
*/
public
function
__construct
(
$name
)
{
$this
->
name
=
$name
;
}
/**
* @param Doctrine_Record $record
* @return mixed
*/
public
function
getIndex
(
Doctrine_Record
$record
)
{
$value
=
$record
->
get
(
$this
->
name
);
if
(
$value
===
null
)
throw
new
Doctrine_Exception
(
"Couldn't create collection index. Record field '"
.
$this
->
name
.
"' was null."
);
return
$value
;
}
}
?>
classes/Record.class.php
View file @
cb79b1d9
...
...
@@ -957,7 +957,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return void
*/
final
public
function
hasColumn
(
$name
,
$type
,
$length
=
20
,
$options
=
""
)
{
$this
->
table
->
has
Column
(
$name
,
$type
,
$length
,
$options
);
$this
->
table
->
set
Column
(
$name
,
$type
,
$length
,
$options
);
}
/**
* returns a string representation of this object
...
...
classes/Sensei/Sensei.class.php
View file @
cb79b1d9
...
...
@@ -12,15 +12,15 @@ class Sensei_Entity extends Doctrine_Record {
}
}
class
Sensei_Variable
extends
Doctrine_Record
{
public
function
setUp
()
{
//$this->setAttribute(Doctrine::ATTR_COLL_KEY, "name");
}
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
50
);
$this
->
hasColumn
(
"name"
,
"string"
,
50
,
"unique"
);
$this
->
hasColumn
(
"value"
,
"string"
,
10000
);
$this
->
hasColumn
(
"session_id"
,
"integer"
);
}
}
class
Sensei_Entity_Var
extends
Sensei_Variable
{
}
class
Sensei_Session_Var
extends
Doctrine_Record
{
}
class
Sensei_Session
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
ownsMany
(
"Sensei_variable"
,
"Sensei_variable.session_id"
);
...
...
@@ -159,17 +159,17 @@ class Sensei extends Doctrine_Access {
return
true
;
}
private
function
read
(
$id
)
{
$coll
=
$this
->
session
->
query
(
"FROM Sensei_Session WHERE Sensei_Session.session_id = ?"
,
array
(
$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
();
}
$this
->
vars
=
$this
->
record
->
Sensei_variable
;
return
""
;
}
public
function
write
(
$id
,
$sess_data
)
{
...
...
classes/Table.class.php
View file @
cb79b1d9
...
...
@@ -201,14 +201,14 @@ class Doctrine_Table extends Doctrine_Configurable {
endswitch
;
}
/**
*
has
Column
*
set
Column
* @param string $name
* @param string $type
* @param integer $length
* @param mixed $options
* @return void
*/
final
public
function
has
Column
(
$name
,
$type
,
$length
,
$options
=
""
)
{
final
public
function
set
Column
(
$name
,
$type
,
$length
,
$options
=
""
)
{
$this
->
columns
[
$name
]
=
array
(
$type
,
$length
,
$options
);
$e
=
explode
(
"|"
,
$options
);
...
...
@@ -216,6 +216,13 @@ class Doctrine_Table extends Doctrine_Configurable {
$this
->
primaryKeys
[]
=
$name
;
}
}
/**
* hasColumn
* @return boolean
*/
final
public
function
hasColumn
(
$name
)
{
return
isset
(
$this
->
columns
[
$name
]);
}
/**
* returns all primary keys
* @return array
...
...
tests/CollectionTestCase.class.php
View file @
cb79b1d9
<?php
class
Doctrine_CollectionTestCase
extends
Doctrine_UnitTestCase
{
public
function
testAdd
()
{
}
$coll
=
new
Doctrine_Collection
(
$this
->
objTable
);
$coll
->
add
(
new
User
());
$this
->
assertEqual
(
$coll
->
count
(),
1
);
$coll
->
add
(
new
User
());
$this
->
assertTrue
(
$coll
->
count
(),
2
);
$this
->
assertEqual
(
$coll
->
getKeys
(),
array
(
0
,
1
));
$coll
[
2
]
=
new
User
();
$this
->
assertTrue
(
$coll
->
count
(),
3
);
$this
->
assertEqual
(
$coll
->
getKeys
(),
array
(
0
,
1
,
2
));
}
public
function
testExpand
()
{
$users
=
$this
->
session
->
query
(
"FROM User, User.Phonenumber-l WHERE User.Phonenumber.phonenumber LIKE '%123%'"
);
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection
);
$this
->
assertTrue
(
$users
[
1
]
instanceof
User
);
$data
=
$users
[
1
]
->
Phonenumber
->
getData
();
$coll
=
$users
[
1
]
->
Phonenumber
;
$this
->
assertEqual
(
count
(
$data
),
1
);
$coll
[
1
];
$this
->
assertEqual
(
count
(
$coll
),
3
);
$this
->
assertTrue
(
$coll
[
2
]
->
getState
()
==
Doctrine_Record
::
STATE_PROXY
);
$generator
=
new
Doctrine_IndexGenerator
(
"id"
);
$coll
->
setGenerator
(
$generator
);
$generator
=
$coll
->
getGenerator
();
$this
->
assertEqual
(
$generator
->
getIndex
(
$this
->
old
),
4
);
}
public
function
testGenerator
()
{
$generator
=
new
Doctrine_IndexGenerator
(
"name"
);
$coll
=
new
Doctrine_Collection
(
$this
->
objTable
);
$coll
->
setGenerator
(
$generator
);
$user
=
new
User
();
$user
->
name
=
"name"
;
$coll
->
add
(
$user
);
$this
->
assertEqual
(
$coll
[
"name"
],
$user
);
$this
->
session
->
getTable
(
"email"
)
->
setAttribute
(
Doctrine
::
ATTR_COLL_KEY
,
"address"
);
$emails
=
$this
->
session
->
getTable
(
"email"
)
->
findAll
();
foreach
(
$emails
as
$k
=>
$v
)
{
$this
->
assertTrue
(
gettype
(
$k
),
"string"
);
}
}
}
?>
tests/ConfigurableTestCase.class.php
View file @
cb79b1d9
...
...
@@ -54,6 +54,29 @@ class Doctrine_ConfigurableTestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
$e
instanceof
Exception
);
$this
->
session
->
commit
();
}
$e
=
false
;
try
{
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_COLL_KEY
,
"name"
);
}
catch
(
Exception
$e
)
{
}
$this
->
assertTrue
(
$e
instanceof
Exception
);
$e
=
false
;
try
{
$this
->
objTable
->
setAttribute
(
Doctrine
::
ATTR_COLL_KEY
,
"unknown"
);
}
catch
(
Exception
$e
)
{
}
$this
->
assertTrue
(
$e
instanceof
Exception
);
$e
=
true
;
try
{
$this
->
objTable
->
setAttribute
(
Doctrine
::
ATTR_COLL_KEY
,
"name"
);
}
catch
(
Exception
$e
)
{
}
$this
->
assertTrue
(
$e
);
$e
=
false
;
try
{
$this
->
session
->
beginTransaction
();
$this
->
session
->
setAttribute
(
Doctrine
::
ATTR_LOCKMODE
,
Doctrine
::
LOCK_PESSIMISTIC
);
...
...
tests/SenseiTestCase.class.php
View file @
cb79b1d9
...
...
@@ -52,8 +52,7 @@ class Sensei_UnitTestCase extends UnitTestCase {
$this
->
init
();
}
public
function
testConstructor
()
{
public
function
testConstructor
()
{
$this
->
assertTrue
(
$this
->
record
instanceof
Sensei_Session
);
if
(
isset
(
$_COOKIE
[
"PHPSESSID"
]))
{
...
...
tests/classes.php
View file @
cb79b1d9
...
...
@@ -7,7 +7,7 @@ class Entity extends Doctrine_Record {
}
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
50
);
$this
->
hasColumn
(
"loginname"
,
"string"
,
20
);
$this
->
hasColumn
(
"loginname"
,
"string"
,
20
,
"unique"
);
$this
->
hasColumn
(
"password"
,
"string"
,
16
);
$this
->
hasColumn
(
"type"
,
"integer"
,
1
);
$this
->
hasColumn
(
"created"
,
"integer"
,
11
);
...
...
tests/run.php
View file @
cb79b1d9
...
...
@@ -11,6 +11,7 @@ require_once("RecordTestCase.class.php");
require_once
(
"DQLParserTestCase.class.php"
);
require_once
(
"AccessTestCase.class.php"
);
require_once
(
"ValidatorTestCase.class.php"
);
require_once
(
"CollectionTestCase.class.php"
);
require_once
(
"CacheSqliteTestCase.class.php"
);
require_once
(
"SenseiTestCase.class.php"
);
...
...
@@ -24,7 +25,7 @@ $test = new GroupTest("Doctrine Framework Unit Tests");
/**
$test
->
addTestCase
(
new
Doctrine_RecordTestCase
());
$test
->
addTestCase
(
new
Doctrine_SessionTestCase
());
...
...
@@ -34,16 +35,19 @@ $test->addTestCase(new Doctrine_ManagerTestCase());
$test
->
addTestCase
(
new
Doctrine_TableTestCase
());
$test
->
addTestCase
(
new
Doctrine_AccessTestCase
());
$test->addTestCase(new Doctrine_ConfigurableTestCase());
$test
->
addTestCase
(
new
Doctrine_EventListenerTestCase
());
$test
->
addTestCase
(
new
Doctrine_DQL_ParserTestCase
());
$test
->
addTestCase
(
new
Doctrine_BatchIteratorTestCase
());
*/
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_ConfigurableTestCase
());
$test
->
addTestCase
(
new
Sensei_UnitTestCase
());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
...
...
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