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
e9ba4504
Commit
e9ba4504
authored
Sep 24, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for Doctrine Resource
parent
d6c0bcb4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
139 additions
and
53 deletions
+139
-53
Record.php
lib/Doctrine/Record.php
+2
-2
Client.php
lib/Doctrine/Resource/Client.php
+2
-2
Collection.php
lib/Doctrine/Resource/Collection.php
+4
-2
Record.php
lib/Doctrine/Resource/Record.php
+64
-5
Request.php
lib/Doctrine/Resource/Request.php
+28
-28
Server.php
lib/Doctrine/Resource/Server.php
+34
-10
index.php
playground/index.php
+5
-4
No files found.
lib/Doctrine/Record.php
View file @
e9ba4504
...
...
@@ -1143,9 +1143,9 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
if
(
is_array
(
$array
))
{
foreach
(
$array
as
$key
=>
$value
)
{
if
(
is_array
(
$value
)
)
{
if
(
$this
->
getTable
()
->
hasRelation
(
$key
)
&&
$value
)
{
$this
->
$key
->
fromArray
(
$value
);
}
else
{
}
else
if
(
$this
->
getTable
()
->
hasColumn
(
$key
)
&&
$value
)
{
$this
->
$key
=
$value
;
}
}
...
...
lib/Doctrine/Resource/Client.php
View file @
e9ba4504
...
...
@@ -59,7 +59,7 @@ class Doctrine_Resource_Client extends Doctrine_Resource
}
else
{
$request
=
new
Doctrine_Resource_Request
();
$request
->
set
(
'type'
,
'load'
);
$request
->
set
(
'format'
,
'xml'
);
$request
->
set
(
'format'
,
$this
->
getConfig
()
->
get
(
'format'
)
);
$schema
=
$request
->
execute
();
...
...
@@ -67,7 +67,7 @@ class Doctrine_Resource_Client extends Doctrine_Resource
}
$import
=
new
Doctrine_Import_Schema
();
$schema
=
$import
->
buildSchema
(
$path
,
'xml'
);
$schema
=
$import
->
buildSchema
(
$path
,
$this
->
getConfig
()
->
get
(
'format'
)
);
$this
->
getConfig
()
->
set
(
'schema'
,
$schema
);
}
...
...
lib/Doctrine/Resource/Collection.php
View file @
e9ba4504
...
...
@@ -31,7 +31,7 @@
* @link www.phpdoctrine.com
* @since 1.0
*/
class
Doctrine_Resource_Collection
extends
Doctrine_Access
implements
Countable
,
IteratorAggregate
class
Doctrine_Resource_Collection
extends
Doctrine_
Resource_
Access
implements
Countable
,
IteratorAggregate
{
protected
$_data
=
array
();
protected
$_config
=
array
();
...
...
@@ -84,7 +84,9 @@ class Doctrine_Resource_Collection extends Doctrine_Access implements Countable,
$array
=
array
();
foreach
(
$this
->
_data
as
$key
=>
$record
)
{
$array
[
$key
]
=
$record
->
toArray
();
if
(
$record
->
exists
())
{
$array
[
$this
->
_model
.
'_'
.
$key
]
=
$record
->
toArray
();
}
}
return
$array
;
...
...
lib/Doctrine/Resource/Record.php
View file @
e9ba4504
...
...
@@ -31,7 +31,7 @@
* @link www.phpdoctrine.com
* @since 1.0
*/
class
Doctrine_Resource_Record
extends
Doctrine_Re
cord_Abstract
implements
Countable
,
IteratorAggregate
class
Doctrine_Resource_Record
extends
Doctrine_Re
source_Access
implements
Countable
,
IteratorAggregate
{
protected
$_data
=
array
();
protected
$_model
=
null
;
...
...
@@ -119,7 +119,7 @@ class Doctrine_Resource_Record extends Doctrine_Record_Abstract implements Count
public
function
save
()
{
$format
=
$this
->
getConfig
(
'format'
)
?
$this
->
getConfig
(
'format'
)
:
'xml'
;
$format
=
$this
->
getConfig
(
'format'
);
$request
=
new
Doctrine_Resource_Request
();
$request
->
set
(
'format'
,
$format
);
...
...
@@ -139,14 +139,73 @@ class Doctrine_Resource_Record extends Doctrine_Record_Abstract implements Count
return
$this
->
_model
;
}
public
function
identifier
()
{
$identifier
=
array
();
if
(
isset
(
$this
->
_schema
[
'columns'
])
&&
is_array
(
$this
->
_schema
[
'columns'
]))
{
foreach
(
$this
->
_schema
[
'columns'
]
as
$name
=>
$column
)
{
if
(
$column
[
'primary'
]
==
true
)
{
$identifier
[
$name
]
=
$this
->
_data
[
$name
];
}
}
}
return
$identifier
;
}
public
function
exists
()
{
$identifier
=
$this
->
identifier
();
foreach
(
$identifier
as
$key
=>
$value
)
{
if
(
!
$value
)
{
return
false
;
}
}
return
true
;
}
public
function
hasColumn
(
$name
)
{
return
isset
(
$this
->
_schema
[
'columns'
][
$name
])
?
true
:
false
;
}
public
function
getColumn
(
$name
)
{
if
(
$this
->
hasColumn
(
$name
))
{
return
$this
->
_columns
[
$name
];
}
}
public
function
hasRelation
(
$name
)
{
return
isset
(
$this
->
_schema
[
'relations'
][
$name
])
?
true
:
false
;
}
public
function
getRelation
(
$name
)
{
if
(
$this
->
hasRelation
(
$name
))
{
return
$this
->
_schema
[
'relations'
][
$name
];
}
}
public
function
toArray
()
{
$array
=
array
();
foreach
(
$this
->
_data
as
$key
=>
$value
)
{
if
(
$value
instanceof
Doctrine_Resource_Collection
OR
$value
instanceof
Doctrine_Resource_Record
)
{
$array
[
$key
]
=
$value
->
toArray
();
}
else
{
if
(
$this
->
hasRelation
(
$key
)
&&
$value
instanceof
Doctrine_Resource_Collection
)
{
if
(
$value
->
count
()
>
0
)
{
$array
[
$key
]
=
$value
->
toArray
();
}
}
else
if
(
$this
->
hasRelation
(
$key
)
&&
$value
instanceof
Doctrine_Resource_Record
)
{
if
(
$value
->
exists
())
{
$array
[
$key
]
=
$value
->
toArray
();
}
}
else
if
(
!
$this
->
hasRelation
(
$key
)
&&
$this
->
hasColumn
(
$key
))
{
$array
[
$key
]
=
$value
;
}
}
...
...
lib/Doctrine/Resource/Request.php
View file @
e9ba4504
...
...
@@ -40,49 +40,49 @@ class Doctrine_Resource_Request extends Doctrine_Resource_Params
return
Doctrine_Resource_Client
::
getInstance
()
->
getConfig
(
$key
);
}
public
function
getParams
()
{
if
(
$this
->
_params
===
null
)
{
$this
->
_params
=
new
Doctrine_Resource_Params
();
}
return
$this
->
_params
;
}
public
function
get
(
$key
)
{
return
$this
->
getParams
()
->
get
(
$key
);
}
public
function
set
(
$key
,
$value
)
{
return
$this
->
getParams
()
->
set
(
$key
,
$value
);
}
public
function
execute
()
{
$url
=
$this
->
getConfig
()
->
get
(
'url'
);
$url
.=
strstr
(
$this
->
getConfig
()
->
get
(
'url'
),
'?'
)
?
'&'
:
'?'
;
$url
.=
http_build_query
(
$this
->
getParams
()
->
getAll
());
$data
=
array
(
'type'
=>
$this
->
get
(
'type'
),
'format'
=>
$this
->
getConfig
()
->
get
(
'format'
),
'data'
=>
Doctrine_Parser
::
dump
(
$this
->
getAll
(),
$this
->
getConfig
()
->
get
(
'format'
)));
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_POST
,
1
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
$data
);
$response
=
curl_exec
(
$ch
);
if
(
curl_errno
(
$ch
))
{
throw
new
Doctrine_Resource_Exception
(
'Request failed'
);
}
$response
=
file_get_contents
(
$url
);
curl_close
(
$ch
);
return
$response
;
}
public
function
hydrate
(
array
$array
,
$model
,
$passedKey
=
null
)
{
$config
=
$this
->
getConfig
();
if
(
empty
(
$array
))
{
return
false
;
}
$collection
=
new
Doctrine_Resource_Collection
(
$model
,
$config
);
$collection
=
new
Doctrine_Resource_Collection
(
$model
);
foreach
(
$array
as
$record
)
{
$r
=
new
Doctrine_Resource_Record
(
$model
,
$config
);
$r
=
new
Doctrine_Resource_Record
(
$model
);
foreach
(
$record
as
$key
=>
$value
)
{
if
(
is_array
(
$value
))
{
$r
->
set
(
$key
,
$this
->
hydrate
(
$value
,
$model
,
$config
,
$key
));
}
else
{
if
(
$r
->
hasRelation
(
$key
)
&&
!
empty
(
$value
))
{
$relation
=
$r
->
getRelation
(
$key
);
if
(
$relation
[
'type'
]
===
Doctrine_Relation
::
MANY
)
{
$r
->
set
(
$key
,
$this
->
hydrate
(
$value
,
$relation
[
'class'
],
$key
));
}
else
{
$r
->
set
(
$key
,
$this
->
hydrate
(
array
(
$value
),
$relation
[
'class'
],
$key
)
->
getFirst
());
}
}
else
if
(
$r
->
hasColumn
(
$key
))
{
$r
->
set
(
$key
,
$value
);
}
}
...
...
lib/Doctrine/Resource/Server.php
View file @
e9ba4504
...
...
@@ -31,7 +31,7 @@
* @link www.phpdoctrine.com
* @since 1.0
*/
class
Doctrine_Resource_Server
extends
Doctrine_
r
esource
class
Doctrine_Resource_Server
extends
Doctrine_
R
esource
{
static
public
function
getInstance
(
$config
=
null
)
{
...
...
@@ -49,7 +49,29 @@ class Doctrine_Resource_Server extends Doctrine_resource
$model
=
$request
->
get
(
'model'
);
$data
=
$request
->
get
(
'data'
);
$record
=
new
$model
();
$table
=
Doctrine_Manager
::
getInstance
()
->
getTable
(
$model
);
$identifier
=
$table
->
getIdentifier
();
if
(
!
is_array
(
$identifier
))
{
$identifier
=
array
(
$identifier
);
}
$existing
=
true
;
$pks
=
array
();
foreach
(
$identifier
as
$name
)
{
if
(
isset
(
$data
[
$name
]))
{
$pks
[
$name
]
=
$data
[
$name
];
}
else
{
$existing
=
false
;
}
}
if
(
$existing
)
{
$record
=
$table
->
find
(
$pks
);
}
else
{
$record
=
new
$model
();
}
$record
->
fromArray
(
$data
);
$record
->
save
();
...
...
@@ -82,20 +104,22 @@ class Doctrine_Resource_Server extends Doctrine_resource
return
$schema
;
}
public
function
execute
(
$request
)
public
function
execute
(
array
$r
)
{
if
(
!
isset
(
$request
[
'type'
]))
{
throw
new
Doctrine_Resource_Exception
(
'You must specify a request type'
);
}
if
(
!
isset
(
$r
[
'data'
]))
{
throw
new
Doctrine_Resource_Exception
(
'You must specify a data xml string in your request'
);
}
$type
=
$r
[
'type'
];
$format
=
isset
(
$r
[
'format'
])
?
$r
[
'format'
]
:
'xml'
;
$data
=
Doctrine_Parser
::
load
(
$r
[
'data'
],
$format
);
$format
=
isset
(
$request
[
'format'
])
?
$request
[
'format'
]
:
'xml'
;
$type
=
$request
[
'type'
];
$funcName
=
'execute'
.
Doctrine
::
classify
(
$type
);
$request
=
new
Doctrine_Resource_Request
(
$request
);
$request
Obj
=
new
Doctrine_Resource_Request
(
$data
);
if
(
method_exists
(
$this
,
$funcName
))
{
$result
=
$this
->
$funcName
(
$request
);
$result
=
$this
->
$funcName
(
$request
Obj
);
}
else
{
throw
new
Doctrine_Resource_Exception
(
'Unknown Doctrine Resource Server function'
);
}
...
...
playground/index.php
View file @
e9ba4504
...
...
@@ -18,9 +18,10 @@ if ($action == 'server') {
$client
=
Doctrine_Resource_Client
::
getInstance
(
$config
);
$user
=
$client
->
newRecord
(
'User'
);
$user
->
name
=
'jonathan h. wage'
;
$user
->
save
();
$query
=
new
Doctrine_Resource_Query
();
$query
->
from
(
'User u, u.Email e, u.Phonenumber p'
);
print_r
(
$user
->
toArray
());
$users
=
$query
->
execute
();
print_r
(
$users
->
toArray
());
}
\ 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