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
9c34cb29
Commit
9c34cb29
authored
Aug 07, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started the building of Doctrine_ValueHolder
parent
8d6c72cd
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
224 additions
and
9 deletions
+224
-9
Doctrine.php
Doctrine.php
+14
-0
Filter.php
Doctrine/Filter.php
+14
-0
Hydrate.php
Doctrine/Hydrate.php
+47
-3
Table.php
Doctrine/Table.php
+5
-5
ValueHolder.php
Doctrine/ValueHolder.php
+64
-0
FilterTestCase.php
tests/FilterTestCase.php
+14
-0
UnitTestCase.php
tests/UnitTestCase.php
+3
-1
ValueHolderTestCase.php
tests/ValueHolderTestCase.php
+61
-0
run.php
tests/run.php
+2
-0
No files found.
Doctrine.php
View file @
9c34cb29
...
...
@@ -196,6 +196,20 @@ final class Doctrine {
* mode for lazy offset fetching
*/
const
FETCH_LAZY_OFFSET
=
4
;
/**
* RETURN CONSTANTS
*/
/**
* RETURN VALUEHOLDER
*/
const
RETURN_VHOLDER
=
1
;
/**
* RETURN RECORD
*/
const
RETURN_RECORD
=
2
;
/**
* LOCKMODE CONSTANTS
*/
...
...
Doctrine/Filter.php
0 → 100644
View file @
9c34cb29
<?php
class
Doctrine_Filter
{
private
$name
;
public
function
__construct
(
$name
)
{
$this
->
name
=
$name
;
}
public
function
getName
()
{
return
$this
->
name
;
}
}
?>
Doctrine/Hydrate.php
View file @
9c34cb29
...
...
@@ -92,6 +92,11 @@ class Doctrine_Hydrate extends Doctrine_Access {
public
function
__construct
(
Doctrine_Session
$session
)
{
$this
->
session
=
$session
;
}
/**
* remove
*
* @param $name
*/
public
function
remove
(
$name
)
{
if
(
isset
(
$this
->
parts
[
$name
]))
{
if
(
$name
==
"limit"
||
$name
==
"offset"
)
...
...
@@ -215,7 +220,7 @@ class Doctrine_Hydrate extends Doctrine_Access {
* @param string $params
* @return Doctrine_Collection the root collection
*/
public
function
execute
(
$params
=
array
())
{
public
function
execute
(
$params
=
array
()
,
$return
=
Doctrine
::
RETURN_RECORD
)
{
$this
->
data
=
array
();
$this
->
collections
=
array
();
...
...
@@ -224,6 +229,8 @@ class Doctrine_Hydrate extends Doctrine_Access {
else
$query
=
$this
->
view
->
getSelectSql
();
switch
(
count
(
$this
->
tables
))
:
case
0
:
throw
new
Doctrine_Exception
(
"No tables selected"
);
...
...
@@ -262,6 +269,9 @@ class Doctrine_Hydrate extends Doctrine_Access {
$array
=
$this
->
parseData
(
$stmt
);
if
(
$return
==
Doctrine
::
RETURN_VHOLDER
)
{
return
$this
->
hydrateHolders
(
$array
);
}
$colls
=
array
();
...
...
@@ -387,13 +397,47 @@ class Doctrine_Hydrate extends Doctrine_Access {
return
$coll
;
endswitch
;
}
/**
* hydrateHolders
*
* @param array $array
*/
public
function
hydrateHolders
(
array
$array
)
{
$keys
=
array_keys
(
$this
->
tables
);
$root
=
$keys
[
0
];
$coll
=
new
Doctrine_ValueHolder
(
$this
->
tables
[
$root
]);
foreach
(
$keys
as
$key
)
{
$prev
[
$key
]
=
array
();
}
foreach
(
$array
as
$data
)
{
foreach
(
$data
as
$alias
=>
$row
)
{
if
(
isset
(
$prev
[
$alias
])
&&
$row
!==
$prev
[
$alias
])
{
$holder
=
new
Doctrine_ValueHolder
(
$this
->
tables
[
$alias
]);
$holder
->
data
=
$row
;
if
(
$alias
===
$root
)
{
$coll
->
data
[]
=
$holder
;
}
else
{
$pointer
=
$this
->
joins
[
$alias
];
$component
=
$this
->
tables
[
$alias
]
->
getComponentName
();
$last
[
$pointer
]
->
data
[
$component
][]
=
$holder
;
}
$last
[
$alias
]
=
$holder
;
}
$prev
[
$alias
]
=
$row
;
}
}
return
$coll
;
}
/**
* applyInheritance
* applies column aggregation inheritance to DQL query
* applies column aggregation inheritance to DQL
/ SQL
query
*
* @return string
*/
final
public
function
applyInheritance
()
{
public
function
applyInheritance
()
{
// get the inheritance maps
$array
=
array
();
...
...
Doctrine/Table.php
View file @
9c34cb29
...
...
@@ -721,17 +721,17 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
return
$users
;
}
/**
* findBy
S
ql
* finds records with given
sql
where clause
* findBy
D
ql
* finds records with given
DQL
where clause
* returns a collection of records
*
* @param string $
sql S
QL after WHERE clause
* @param string $
dql D
QL after WHERE clause
* @param array $params query parameters
* @return Doctrine_Collection
*/
public
function
findBySql
(
$
s
ql
,
array
$params
=
array
())
{
public
function
findBySql
(
$
d
ql
,
array
$params
=
array
())
{
$q
=
new
Doctrine_Query
(
$this
->
session
);
$users
=
$q
->
query
(
"FROM "
.
$this
->
name
.
" WHERE "
.
$
s
ql
,
$params
);
$users
=
$q
->
query
(
"FROM "
.
$this
->
name
.
" WHERE "
.
$
d
ql
,
$params
);
return
$users
;
}
/**
...
...
Doctrine/ValueHolder.php
0 → 100644
View file @
9c34cb29
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine
::
autoload
(
'Doctrine_Access'
);
/**
* Doctrine_ValueHolder is a simple class representing a lightweight
* version of Doctrine_Record. It can be used when developer does not
* intend to save / delete the object.
*
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*/
class
Doctrine_ValueHolder
extends
Doctrine_Access
implements
Countable
{
public
$data
=
array
();
private
$table
;
public
function
__construct
(
Doctrine_Table
$table
)
{
$this
->
table
=
$table
;
}
public
function
set
(
$name
,
$value
)
{
$this
->
data
[
$name
]
=
$value
;
}
public
function
get
(
$name
)
{
if
(
!
isset
(
$this
->
data
[
$name
]))
throw
new
InvalidKeyException
(
"Unknown property
$name
."
);
return
$this
->
data
[
$name
];
}
public
function
count
()
{
return
count
(
$this
->
data
);
}
public
function
delete
()
{
throw
new
Doctrine_Exception
(
"Method 'delete' not availible on Doctrine_ValueHolder."
);
}
public
function
save
()
{
throw
new
Doctrine_Exception
(
"Method 'save' not availible on Doctrine_ValueHolder."
);
}
}
?>
tests/FilterTestCase.php
0 → 100644
View file @
9c34cb29
<?php
require_once
(
"UnitTestCase.php"
);
class
Doctrine_Filter_TestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareData
()
{
}
public
function
prepareTables
()
{
$this
->
tables
=
array
(
"FilterTest"
,
"FilterTest2"
);
}
public
function
testOperations
()
{
$t
=
new
FilterTest
;
}
}
?>
tests/UnitTestCase.php
View file @
9c34cb29
...
...
@@ -22,6 +22,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
protected
$listener
;
protected
$cache
;
protected
$users
;
protected
$valueHolder
;
protected
$tables
=
array
();
private
$init
=
false
;
...
...
@@ -70,10 +71,11 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this
->
listener
=
new
Doctrine_EventListener_Debugger
();
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_LISTENER
,
$this
->
listener
);
}
$this
->
query
=
new
Doctrine_Query
(
$this
->
session
);
$this
->
prepareTables
();
$this
->
prepareData
();
$this
->
valueHolder
=
new
Doctrine_ValueHolder
(
$this
->
session
->
getTable
(
'User'
));
}
public
function
prepareTables
()
{
foreach
(
$this
->
tables
as
$name
)
{
...
...
tests/ValueHolderTestCase.php
0 → 100644
View file @
9c34cb29
<?php
require_once
(
"UnitTestCase.php"
);
class
Doctrine_ValueHolder_TestCase
extends
Doctrine_UnitTestCase
{
public
function
testGetSet
()
{
$this
->
valueHolder
->
data
[
0
]
=
'first'
;
$this
->
assertEqual
(
$this
->
valueHolder
->
data
[
0
],
'first'
);
$this
->
assertEqual
(
$this
->
valueHolder
[
0
],
'first'
);
$this
->
assertEqual
(
$this
->
valueHolder
->
get
(
0
),
'first'
);
$this
->
valueHolder
->
data
[
'key'
]
=
'second'
;
$this
->
assertEqual
(
$this
->
valueHolder
->
data
[
'key'
],
'second'
);
$this
->
assertEqual
(
$this
->
valueHolder
->
key
,
'second'
);
$this
->
assertEqual
(
$this
->
valueHolder
[
'key'
],
'second'
);
$this
->
assertEqual
(
$this
->
valueHolder
->
get
(
'key'
),
'second'
);
}
public
function
testSimpleQuery
()
{
$q
=
new
Doctrine_Query
(
$this
->
session
);
$q
->
from
(
"User"
);
$users
=
$q
->
execute
(
array
(),
Doctrine
::
RETURN_VHOLDER
);
$this
->
assertEqual
(
$users
->
count
(),
8
);
}
public
function
testQueryWithOneToManyRelation
()
{
$q
=
new
Doctrine_Query
(
$this
->
session
);
$q
->
from
(
"User.Phonenumber"
);
$users
=
$q
->
execute
(
array
(),
Doctrine
::
RETURN_VHOLDER
);
$this
->
assertEqual
(
$users
->
count
(),
8
);
$this
->
assertTrue
(
$users
[
0
]
instanceof
Doctrine_ValueHolder
);
$this
->
assertTrue
(
$users
[
3
]
instanceof
Doctrine_ValueHolder
);
$this
->
assertTrue
(
$users
[
7
]
instanceof
Doctrine_ValueHolder
);
$this
->
assertEqual
(
count
(
$users
[
0
]
->
Phonenumber
),
1
);
$this
->
assertEqual
(
count
(
$users
[
1
]
->
Phonenumber
),
3
);
$this
->
assertEqual
(
count
(
$users
[
2
]
->
Phonenumber
),
1
);
$this
->
assertEqual
(
count
(
$users
[
3
]
->
Phonenumber
),
1
);
$this
->
assertEqual
(
count
(
$users
[
4
]
->
Phonenumber
),
3
);
}
public
function
testDelete
()
{
$f
=
false
;
try
{
$this
->
valueHolder
->
delete
();
}
catch
(
Doctrine_Exception
$e
)
{
$f
=
true
;
}
$this
->
assertTrue
(
$f
);
}
public
function
testSave
()
{
$f
=
false
;
try
{
$this
->
valueHolder
->
save
();
}
catch
(
Doctrine_Exception
$e
)
{
$f
=
true
;
}
$this
->
assertTrue
(
$f
);
}
}
?>
tests/run.php
View file @
9c34cb29
...
...
@@ -22,6 +22,7 @@ require_once("ViewTestCase.php");
require_once
(
"RawSqlTestCase.php"
);
require_once
(
"CustomPrimaryKeyTestCase.php"
);
require_once
(
"FilterTestCase.php"
);
require_once
(
"ValueHolderTestCase.php"
);
error_reporting
(
E_ALL
);
...
...
@@ -63,6 +64,7 @@ $test->addTestCase(new Doctrine_CustomPrimaryKeyTestCase());
$test
->
addTestCase
(
new
Doctrine_Filter_TestCase
());
$test
->
addTestCase
(
new
Doctrine_ValueHolder_TestCase
());
//$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