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
90541334
Commit
90541334
authored
Sep 27, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
General fixes/work.
parent
900df377
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
21 deletions
+58
-21
Resource.php
lib/Doctrine/Resource.php
+1
-5
Client.php
lib/Doctrine/Resource/Client.php
+8
-3
Request.php
lib/Doctrine/Resource/Request.php
+10
-3
Server.php
lib/Doctrine/Resource/Server.php
+14
-7
index.php
playground/index.php
+25
-3
No files found.
lib/Doctrine/Resource.php
View file @
90541334
...
...
@@ -34,7 +34,7 @@
class
Doctrine_Resource
{
protected
$_config
=
null
;
protected
$_defaultFormat
=
'xml
'
;
const
FORMAT
=
'json
'
;
public
function
__construct
(
$config
)
{
...
...
@@ -48,10 +48,6 @@ class Doctrine_Resource
$this
->
loadDoctrine
=
true
;
}
}
if
(
!
$this
->
getConfig
()
->
has
(
'format'
)
OR
!
$this
->
getConfig
()
->
get
(
'format'
))
{
$this
->
getConfig
()
->
set
(
'format'
,
$this
->
_defaultFormat
);
}
}
public
function
getConfig
(
$key
=
null
)
...
...
lib/Doctrine/Resource/Client.php
View file @
90541334
...
...
@@ -61,7 +61,7 @@ class Doctrine_Resource_Client extends Doctrine_Resource
public
function
loadDoctrine
()
{
$path
=
'/tmp/'
.
md5
(
serialize
(
$this
->
getConfig
())
);
$path
=
'/tmp/'
.
$this
->
getClientKey
(
);
$classesPath
=
$path
.
'.classes.php'
;
if
(
file_exists
(
$path
))
{
...
...
@@ -73,13 +73,13 @@ class Doctrine_Resource_Client extends Doctrine_Resource
$schema
=
$request
->
execute
();
if
(
$schema
)
{
file_put_contents
(
$path
,
Doctrine_Parser
::
dump
(
$schema
,
'xml'
));
file_put_contents
(
$path
,
Doctrine_Parser
::
dump
(
$schema
,
Doctrine_Resource
::
FORMAT
));
}
}
if
(
file_exists
(
$path
)
&&
$schema
)
{
$import
=
new
Doctrine_Import_Schema
();
$schema
=
$import
->
buildSchema
(
$path
,
'xml'
);
$schema
=
$import
->
buildSchema
(
$path
,
Doctrine_Resource
::
FORMAT
);
if
(
!
file_exists
(
$classesPath
))
{
$build
=
"<?php
\n
"
;
...
...
@@ -98,6 +98,11 @@ class Doctrine_Resource_Client extends Doctrine_Resource
}
}
public
function
getClientKey
()
{
return
md5
(
Doctrine_Resource
::
FORMAT
.
serialize
(
$this
->
getConfig
()));
}
public
function
getTable
(
$table
)
{
static
$instance
;
...
...
lib/Doctrine/Resource/Request.php
View file @
90541334
...
...
@@ -44,13 +44,15 @@ class Doctrine_Resource_Request extends Doctrine_Resource_Params
{
$url
=
$this
->
getConfig
()
->
get
(
'url'
);
$request
=
array
(
'xml'
=>
Doctrine_Parser
::
dump
(
$this
->
getAll
(),
'xml'
));
$request
=
array
(
'request'
=>
Doctrine_Parser
::
dump
(
$this
->
getAll
(),
$this
->
getFormat
()));
$header
[
0
]
=
'Accept: '
.
$this
->
getFormat
();
$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_HTTPHEADER
,
$header
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
$request
);
$response
=
curl_exec
(
$ch
);
...
...
@@ -63,7 +65,7 @@ class Doctrine_Resource_Request extends Doctrine_Resource_Params
$array
=
array
();
if
(
$response
)
{
$array
=
Doctrine_Parser
::
load
(
$response
,
$this
->
get
Config
()
->
get
(
'format'
));
$array
=
Doctrine_Parser
::
load
(
$response
,
$this
->
get
Format
(
));
}
if
(
isset
(
$array
[
'error'
]))
{
...
...
@@ -72,4 +74,9 @@ class Doctrine_Resource_Request extends Doctrine_Resource_Params
return
$array
;
}
public
function
getFormat
()
{
return
(
$this
->
getConfig
()
->
has
(
'format'
)
&&
$this
->
getConfig
()
->
get
(
'format'
))
?
$this
->
getConfig
()
->
get
(
'format'
)
:
Doctrine_Resource
::
FORMAT
;
}
}
\ No newline at end of file
lib/Doctrine/Resource/Server.php
View file @
90541334
...
...
@@ -171,9 +171,9 @@ class Doctrine_Resource_Server extends Doctrine_Resource
$models
=
$this
->
getConfig
(
'models'
)
?
$this
->
getConfig
(
'models'
)
:
array
();
$export
=
new
Doctrine_Export_Schema
();
$export
->
exportSchema
(
$path
,
'xml'
,
null
,
$models
);
$export
->
exportSchema
(
$path
,
$this
->
getFormat
()
,
null
,
$models
);
$schema
=
Doctrine_Parser
::
load
(
$path
,
'xml'
);
$schema
=
Doctrine_Parser
::
load
(
$path
,
$this
->
getFormat
()
);
unlink
(
$path
);
...
...
@@ -182,11 +182,11 @@ class Doctrine_Resource_Server extends Doctrine_Resource
public
function
execute
(
array
$r
)
{
if
(
!
isset
(
$r
[
'
xml
'
]))
{
throw
new
Doctrine_Resource_Exception
(
'You must specify a
n xml
string in your request'
);
if
(
!
isset
(
$r
[
'
request
'
]))
{
throw
new
Doctrine_Resource_Exception
(
'You must specify a
request '
.
$this
->
getFormat
()
.
'
string in your request'
);
}
$requestArray
=
Doctrine_Parser
::
load
(
$r
[
'
xml'
]
);
$requestArray
=
Doctrine_Parser
::
load
(
$r
[
'
request'
],
$this
->
getFormat
()
);
$request
=
new
Doctrine_Resource_Request
(
$requestArray
);
...
...
@@ -200,7 +200,7 @@ class Doctrine_Resource_Server extends Doctrine_Resource
if
(
$this
->
validate
(
$errors
))
{
$result
=
$this
->
$funcName
(
$request
);
return
Doctrine_Parser
::
dump
(
$result
,
'xml'
);
return
Doctrine_Parser
::
dump
(
$result
,
$this
->
getFormat
()
);
}
}
else
{
throw
new
Doctrine_Resource_Exception
(
'Unknown Doctrine Resource Server function'
);
...
...
@@ -222,6 +222,13 @@ class Doctrine_Resource_Server extends Doctrine_Resource
{
$error
=
array
(
'error'
=>
$e
->
getMessage
());
return
Doctrine_Parser
::
dump
(
$error
);
return
Doctrine_Parser
::
dump
(
$error
,
$this
->
getFormat
());
}
public
function
getFormat
()
{
$headers
=
getallheaders
();
return
isset
(
$headers
[
'Accept'
])
?
$headers
[
'Accept'
]
:
Doctrine_Resource
::
FORMAT
;
}
}
\ No newline at end of file
playground/index.php
View file @
90541334
<?php
require_once
(
'playground.php'
);
require_once
(
'connection.php'
);
require_once
(
'models.php'
);
require_once
(
'data.php'
);
\ No newline at end of file
if
(
isset
(
$_REQUEST
[
'server'
]))
{
require_once
(
'connection.php'
);
require_once
(
'models.php'
);
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'
=>
'json'
);
// 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
();
print_r
(
$users
->
toArray
(
true
));
}
\ 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