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
9992cf30
Commit
9992cf30
authored
Sep 21, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for Doctrine_Resource.
parent
ce0ec8df
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
612 additions
and
380 deletions
+612
-380
Resource.php
lib/Doctrine/Resource.php
+7
-1
Client.php
lib/Doctrine/Resource/Client.php
+5
-357
Collection.php
lib/Doctrine/Resource/Collection.php
+41
-0
Exception.php
lib/Doctrine/Resource/Exception.php
+4
-0
Query.php
lib/Doctrine/Resource/Query.php
+449
-0
Record.php
lib/Doctrine/Resource/Record.php
+65
-0
Server.php
lib/Doctrine/Resource/Server.php
+40
-22
models.php
playground/models.php
+1
-0
No files found.
lib/Doctrine/Resource.php
View file @
9992cf30
<?php
class
Doctrine_Resource
{
public
static
function
request
(
$url
,
$request
)
{
$url
.=
strstr
(
$url
,
'?'
)
?
'&'
:
'?'
;
$url
.=
http_build_query
(
$request
);
return
file_get_contents
(
$url
);
}
}
\ No newline at end of file
lib/Doctrine/Resource/Client.php
View file @
9992cf30
This diff is collapsed.
Click to expand it.
lib/Doctrine/Resource/Collection.php
0 → 100644
View file @
9992cf30
<?php
class
Doctrine_Resource_Collection
extends
Doctrine_Access
implements
Countable
,
IteratorAggregate
{
public
$data
=
array
();
public
$config
=
array
();
public
$model
=
null
;
public
function
count
()
{
return
count
(
$data
);
}
public
function
getIterator
()
{
$data
=
$this
->
data
;
return
new
ArrayIterator
(
$data
);
}
public
function
save
()
{
foreach
(
$data
as
$record
)
{
$record
->
save
();
}
}
public
function
getFirst
()
{
return
$this
->
data
[
0
];
}
public
function
toArray
()
{
$array
=
array
();
foreach
(
$this
->
data
as
$key
=>
$record
)
{
$array
[
$key
]
=
$record
->
toArray
();
}
return
$array
;
}
}
\ No newline at end of file
lib/Doctrine/Resource/Exception.php
0 → 100644
View file @
9992cf30
<?php
class
Doctrine_Resource_Exception
extends
Doctrine_Exception
{
}
\ No newline at end of file
lib/Doctrine/Resource/Query.php
0 → 100644
View file @
9992cf30
This diff is collapsed.
Click to expand it.
lib/Doctrine/Resource/Record.php
0 → 100644
View file @
9992cf30
<?php
class
Doctrine_Resource_Record
extends
Doctrine_Record_Abstract
implements
Countable
,
IteratorAggregate
{
public
$data
=
array
();
public
$config
=
array
();
public
$model
=
null
;
public
$changes
=
array
();
public
function
get
(
$get
)
{
if
(
!
isset
(
$this
->
data
[
$get
]))
{
$this
->
data
[
$get
]
=
null
;
}
return
$this
->
data
[
$get
];
}
public
function
set
(
$set
,
$value
)
{
$this
->
data
[
$set
]
=
$value
;
$this
->
changes
[
$set
]
=
$value
;
}
public
function
count
()
{
return
count
(
$this
->
data
);
}
public
function
getIterator
()
{
$data
=
$this
->
data
;
return
new
ArrayIterator
(
$data
);
}
public
function
save
()
{
$request
=
array
();
$request
[
'format'
]
=
$this
->
config
[
'format'
];
$request
[
'type'
]
=
'save'
;
$request
[
'model'
]
=
$this
->
model
;
$request
[
'data'
]
=
$this
->
data
;
$request
[
'changes'
]
=
$this
->
changes
;
$response
=
Doctrine_Resource
::
request
(
$this
->
config
[
'url'
],
$request
);
$array
=
Doctrine_Parser
::
load
(
$response
,
$request
[
'format'
]);
}
public
function
toArray
()
{
$array
=
array
();
foreach
(
$this
->
data
as
$key
=>
$value
)
{
if
(
$value
instanceof
Doctrine_Resource_Collection
)
{
$array
[
$key
]
=
$value
->
toArray
();
}
else
{
$array
[
$key
]
=
$value
;
}
}
return
$array
;
}
}
\ No newline at end of file
lib/Doctrine/Resource/Server.php
View file @
9992cf30
<?php
class
Doctrine_Resource_Server
extends
Doctrine_Resource
{
public
$config
=
array
();
public
function
__construct
(
$config
)
{
$this
->
config
=
array_merge
(
$config
,
$this
->
config
);
}
public
function
execute
(
$request
)
{
if
(
isset
(
$request
[
'dql'
]))
{
$query
=
new
Doctrine_Query
();
$result
=
$query
->
query
(
$request
[
'dql'
]);
}
else
{
$result
=
$this
->
buildDql
(
$request
[
'parts'
]);
if
(
!
isset
(
$request
[
'type'
]))
{
throw
new
Doctrine_Resource_Exception
(
'You must specify a request type: query or save'
);
}
$data
=
array
();
foreach
(
$result
as
$recordKey
=>
$record
)
{
$array
=
$record
->
toArray
();
$format
=
isset
(
$request
[
'format'
])
?
$request
[
'format'
]
:
'xml'
;
if
(
$request
[
'type'
]
==
'query'
)
{
if
(
isset
(
$request
[
'dql'
])
&&
$request
[
'dql'
])
{
$dql
=
$request
[
'dql'
];
$params
=
isset
(
$request
[
'params'
])
?
$request
[
'params'
]
:
array
();
$conn
=
Doctrine_Manager
::
connection
();
$result
=
$conn
->
query
(
$dql
,
$params
,
Doctrine
::
FETCH_ARRAY
);
}
else
{
throw
new
Doctrine_Resource_Exception
(
'You must specify a dql query'
);
}
}
else
if
(
$request
[
'type'
]
==
'save'
)
{
$table
=
Doctrine_Manager
::
getInstance
()
->
getTable
(
$request
[
'model'
]);
$pks
=
(
array
)
$table
->
getIdentifier
();
$pks
=
array_flip
(
$pks
);
foreach
(
array_keys
(
$pks
)
as
$key
)
{
$pks
[
$key
]
=
$request
[
'data'
][
$key
];
}
$record
=
$table
->
find
(
$pks
);
$
recordKey
=
get_class
(
$record
)
.
'_'
.
(
$recordKey
+
1
)
;
$
changes
=
$request
[
'changes'
]
;
foreach
(
$
array
as
$valueK
ey
=>
$value
)
{
$
data
[
get_class
(
$record
)][
$recordKey
][
$valueKey
]
=
$value
;
foreach
(
$
changes
as
$k
ey
=>
$value
)
{
$
record
->
$key
=
$value
;
}
$record
->
save
();
$result
=
array
(
'success'
=>
true
);
}
$format
=
isset
(
$request
[
'format'
])
?
$request
[
'format'
]
:
'xml'
;
return
Doctrine_Parser
::
dump
(
$data
,
$format
);
return
Doctrine_Parser
::
dump
(
$result
,
$format
);
}
public
function
buildDql
(
$parts
)
public
function
run
(
$request
)
{
}
public
function
run
()
{
$request
=
$_REQUEST
;
echo
$this
->
execute
(
$request
);
}
}
\ No newline at end of file
playground/models.php
View file @
9992cf30
...
...
@@ -12,6 +12,7 @@ $tables = array('Entity',
'Group'
,
'User'
,
'Album'
,
'Book'
,
'Song'
,
'Element'
,
'Error'
,
...
...
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