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
12cc664b
Commit
12cc664b
authored
Sep 26, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added exportTo() and importFrom() to Collection and Record.
parent
271d3c8e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
47 deletions
+50
-47
Collection.php
lib/Doctrine/Collection.php
+26
-15
Xml.php
lib/Doctrine/Parser/Xml.php
+5
-5
Record.php
lib/Doctrine/Record.php
+16
-0
index.php
playground/index.php
+3
-27
No files found.
lib/Doctrine/Collection.php
View file @
12cc664b
...
@@ -591,33 +591,44 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -591,33 +591,44 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
*/
public
function
toArray
(
$deep
=
false
,
$prefixKey
=
false
)
public
function
toArray
(
$deep
=
false
,
$prefixKey
=
false
)
{
{
if
(
$deep
)
{
$data
=
array
();
$data
=
array
();
foreach
(
$this
->
data
as
$key
=>
$record
)
{
foreach
(
$this
->
data
as
$key
=>
$record
)
{
$key
=
$prefixKey
?
get_class
(
$record
)
.
'_'
.
$key
:
$key
;
$key
=
$prefixKey
?
get_class
(
$record
)
.
'_'
.
$key
:
$key
;
$data
[
$key
]
=
$record
->
toArray
(
$deep
,
$prefixKey
);
$data
[
$key
]
=
$record
->
toArray
(
$deep
,
$prefixKey
);
}
return
$data
;
}
else
{
// this is preserved for backwards compatibility
// but could be replaced with above code
return
$this
->
data
;
}
}
return
$data
;
}
}
public
function
fromArray
(
$array
)
public
function
fromArray
(
$array
)
{
{
$data
=
array
();
$data
=
array
();
foreach
(
$array
as
$
key
=>
$
row
)
{
foreach
(
$array
as
$row
)
{
$record
=
$this
->
_table
->
getRecord
();
$record
=
$this
->
_table
->
getRecord
();
$record
->
fromArray
(
$row
);
$record
->
fromArray
(
$row
);
$data
[
$key
]
=
$record
;
$data
[]
=
$record
;
}
}
$this
->
data
=
$data
;
$this
->
data
=
$data
;
}
}
public
function
exportTo
(
$type
,
$deep
=
false
)
{
if
(
$type
==
'array'
)
{
return
$this
->
toArray
(
$deep
);
}
else
{
return
Doctrine_Parser
::
dump
(
$this
->
toArray
(
$deep
,
true
),
$type
);
}
}
public
function
importFrom
(
$type
,
$data
)
{
if
(
$type
==
'array'
)
{
return
$this
->
fromArray
(
$data
);
}
else
{
return
$this
->
fromArray
(
Doctrine_Parser
::
load
(
$data
,
$type
));
}
}
public
function
getDeleteDiff
()
public
function
getDeleteDiff
()
{
{
return
array_udiff
(
$this
->
_snapshot
,
$this
->
data
,
array
(
$this
,
"compareRecords"
));
return
array_udiff
(
$this
->
_snapshot
,
$this
->
data
,
array
(
$this
,
"compareRecords"
));
...
...
lib/Doctrine/Parser/Xml.php
View file @
12cc664b
...
@@ -87,18 +87,18 @@ class Doctrine_Parser_Xml extends Doctrine_Parser
...
@@ -87,18 +87,18 @@ class Doctrine_Parser_Xml extends Doctrine_Parser
foreach
(
$children
as
$element
=>
$value
)
{
foreach
(
$children
as
$element
=>
$value
)
{
if
(
$value
instanceof
SimpleXMLElement
)
{
if
(
$value
instanceof
SimpleXMLElement
)
{
$values
=
(
array
)
$value
->
children
();
$values
=
(
array
)
$value
->
children
();
if
(
count
(
$values
)
>
0
)
{
if
(
count
(
$values
)
>
0
)
{
$return
[
$element
]
=
$this
->
prepareData
(
$value
);
$return
[
$element
]
=
$this
->
prepareData
(
$value
);
}
else
{
}
else
{
if
(
!
isset
(
$return
[
$element
]))
{
if
(
!
isset
(
$return
[
$element
]))
{
$return
[
$element
]
=
(
string
)
$value
;
$return
[
$element
]
=
(
string
)
$value
;
}
else
{
}
else
{
if
(
!
is_array
(
$return
[
$element
]))
{
if
(
!
is_array
(
$return
[
$element
]))
{
$return
[
$element
]
=
array
(
$return
[
$element
],
(
string
)
$value
);
$return
[
$element
]
=
array
(
$return
[
$element
],
(
string
)
$value
);
}
else
{
}
else
{
$return
[
$element
][]
=
(
string
)
$value
;
$return
[
$element
][]
=
(
string
)
$value
;
}
}
}
}
}
}
...
@@ -111,4 +111,4 @@ class Doctrine_Parser_Xml extends Doctrine_Parser
...
@@ -111,4 +111,4 @@ class Doctrine_Parser_Xml extends Doctrine_Parser
return
array
();
return
array
();
}
}
}
}
}
}
\ No newline at end of file
lib/Doctrine/Record.php
View file @
12cc664b
...
@@ -1153,6 +1153,22 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
...
@@ -1153,6 +1153,22 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
}
}
}
}
}
}
public
function
exportTo
(
$type
,
$deep
=
false
)
{
if
(
$type
==
'array'
)
{
return
$this
->
toArray
(
$deep
);
}
else
{
return
Doctrine_Parser
::
dump
(
$this
->
toArray
(
$deep
,
true
),
$type
);
}
}
public
function
importFrom
(
$type
,
$data
)
{
if
(
$type
==
'array'
)
{
return
$this
->
fromArray
(
$data
);
}
else
{
return
$this
->
fromArray
(
Doctrine_Parser
::
load
(
$data
,
$type
));
}
}
/**
/**
* exists
* exists
* returns true if this record is persistent, otherwise false
* returns true if this record is persistent, otherwise false
...
...
playground/index.php
View file @
12cc664b
<?php
<?php
require_once
(
'playground.php'
);
require_once
(
'playground.php'
);
require_once
(
'connection.php'
);
if
(
isset
(
$_REQUEST
[
'server'
]))
{
require_once
(
'models.php'
);
require_once
(
'connection.php'
);
require_once
(
'data.php'
);
require_once
(
'models.php'
);
\ No newline at end of file
require_once
(
'data.php'
);
$name
=
'Doctrine_Resource_Playground'
;
$config
=
array
(
'models'
=>
$tables
);
$server
=
Doctrine_Resource_Server
::
getInstance
(
$name
,
$config
);
$server
->
run
(
$_REQUEST
);
}
else
{
$url
=
'http://localhost/~jwage/doctrine_trunk/playground/index.php?server'
;
$config
=
array
(
'format'
=>
'xml'
);
// Instantiate a new client
$client
=
Doctrine_Resource_Client
::
getInstance
(
$url
,
$config
);
$query
=
new
Doctrine_Resource_Query
();
$users
=
$query
->
from
(
'User u, u.Phonenumber p, u.Email e, u.Address a'
)
->
execute
();
$json
=
Doctrine_Parser
::
load
(
Doctrine_Parser
::
dump
(
$users
->
getFirst
()
->
toArray
(
true
,
true
),
'json'
),
'json'
);
print_r
(
$json
);
}
\ No newline at end of file
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