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
611c65e7
Commit
611c65e7
authored
Dec 30, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added null key handling for Doctrine_Collection
parent
74736918
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
4 deletions
+50
-4
Collection.php
lib/Doctrine/Collection.php
+31
-4
CollectionTestCase.php
tests/CollectionTestCase.php
+10
-0
UnitTestCase.php
tests/UnitTestCase.php
+9
-0
No files found.
lib/Doctrine/Collection.php
View file @
611c65e7
...
@@ -425,7 +425,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -425,7 +425,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
{
{
if
(
!
isset
(
$this
->
data
[
$key
]))
{
if
(
!
isset
(
$this
->
data
[
$key
]))
{
$this
->
expand
(
$key
);
$this
->
expand
(
$key
);
throw
new
InvalidKeyException
();
throw
new
Doctrine_Collection_Exception
(
'Unknown key '
.
$key
);
}
}
$removed
=
$this
->
data
[
$key
];
$removed
=
$this
->
data
[
$key
];
...
@@ -437,7 +438,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -437,7 +438,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
* contains
* contains
* whether or not this collection contains a specified element
* whether or not this collection contains a specified element
*
*
* @param mixed $key
* @param mixed $key
the key of the element
* @return boolean
* @return boolean
*/
*/
public
function
contains
(
$key
)
public
function
contains
(
$key
)
...
@@ -445,11 +446,37 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -445,11 +446,37 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return
isset
(
$this
->
data
[
$key
]);
return
isset
(
$this
->
data
[
$key
]);
}
}
/**
/**
* @param mixed $key
* get
* @return object Doctrine_Record return a specified record
* returns a record for given key
*
* There are two special cases:
*
* 1. if null is given as a key a new record is created and attached
* at the end of the collection
*
* 2. if given key does not exist, then a new record is create and attached
* to the given key
*
* Collection also maps referential information to newly created records
*
* @param mixed $key the key of the element
* @return Doctrine_Record return a specified record
*/
*/
public
function
get
(
$key
)
public
function
get
(
$key
)
{
{
if
(
$key
===
null
)
{
$record
=
$this
->
table
->
create
();
if
(
isset
(
$this
->
reference_field
))
{
$record
->
set
(
$this
->
reference_field
,
$this
->
reference
,
false
);
}
$this
->
data
[]
=
$record
;
return
$record
;
}
if
(
!
isset
(
$this
->
data
[
$key
]))
{
if
(
!
isset
(
$this
->
data
[
$key
]))
{
$this
->
expand
(
$key
);
$this
->
expand
(
$key
);
...
...
tests/CollectionTestCase.php
View file @
611c65e7
...
@@ -85,6 +85,16 @@ class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase {
...
@@ -85,6 +85,16 @@ class Doctrine_Collection_TestCase extends Doctrine_UnitTestCase {
$this
->
connection
->
clear
();
$this
->
connection
->
clear
();
}
}
public
function
testOffsetGetWithNullArgumentReturnsNewRecord
()
{
$coll
=
new
Doctrine_Collection
(
'User'
);
$this
->
assertEqual
(
$coll
->
count
(),
0
);
$coll
[]
->
name
=
'zYne'
;
$this
->
assertEqual
(
$coll
->
count
(),
1
);
$this
->
assertEqual
(
$coll
[
0
]
->
name
,
'zYne'
);
}
public
function
testLoadRelatedForNormalAssociation
()
{
public
function
testLoadRelatedForNormalAssociation
()
{
$resource
=
new
Doctrine_Collection
(
'Resource'
);
$resource
=
new
Doctrine_Collection
(
'Resource'
);
...
...
tests/UnitTestCase.php
View file @
611c65e7
...
@@ -203,6 +203,15 @@ class Doctrine_UnitTestCase extends UnitTestCase {
...
@@ -203,6 +203,15 @@ class Doctrine_UnitTestCase extends UnitTestCase {
public
function
getConnection
()
{
public
function
getConnection
()
{
return
$this
->
connection
;
return
$this
->
connection
;
}
}
public
function
assertDeclarationType
(
$type
,
$type2
)
{
$dec
=
$this
->
getDeclaration
(
$type
);
if
(
!
is_array
(
$type2
))
$type2
=
array
(
$type2
);
$this
->
assertEqual
(
$dec
[
0
],
$type2
);
}
public
function
getDeclaration
(
$type
)
{
return
$this
->
dataDict
->
getPortableDeclaration
(
array
(
'type'
=>
$type
,
'name'
=>
'colname'
,
'length'
=>
1
,
'fixed'
=>
true
));
}
public
function
clearCache
()
{
public
function
clearCache
()
{
foreach
(
$this
->
tables
as
$name
)
{
foreach
(
$this
->
tables
as
$name
)
{
$table
=
$this
->
connection
->
getTable
(
$name
);
$table
=
$this
->
connection
->
getTable
(
$name
);
...
...
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