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
b447f6ca
Commit
b447f6ca
authored
Sep 24, 2007
by
Jonathan.Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor tweaks.
parent
bf59f2e8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
59 deletions
+80
-59
Record.php
lib/Doctrine/Resource/Record.php
+20
-49
Request.php
lib/Doctrine/Resource/Request.php
+4
-4
Table.php
lib/Doctrine/Resource/Table.php
+50
-0
index.php
playground/index.php
+6
-6
No files found.
lib/Doctrine/Resource/Record.php
View file @
b447f6ca
...
...
@@ -35,22 +35,13 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
{
protected
$_data
=
array
();
protected
$_model
=
null
;
protected
$_
schema
=
null
;
protected
$_
table
=
null
;
protected
$_changes
=
array
();
public
function
__construct
(
$model
,
$loadRelations
=
true
)
{
$this
->
_model
=
$model
;
$schema
=
$this
->
getConfig
(
'schema'
);
if
(
isset
(
$schema
[
'schema'
][
$model
])
&&
$schema
[
'schema'
][
$model
])
{
$this
->
_schema
=
$schema
[
'schema'
][
$model
];
}
if
(
isset
(
$schema
[
'relations'
][
$model
])
&&
$schema
[
'relations'
][
$model
])
{
$this
->
_schema
[
'relations'
]
=
$schema
[
'relations'
][
$model
];
}
$this
->
_table
=
Doctrine_Resource_Client
::
getInstance
()
->
getTable
(
$model
);
$this
->
initialize
(
$loadRelations
);
}
...
...
@@ -62,12 +53,8 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
public
function
initialize
(
$loadRelations
=
true
)
{
if
(
!
$this
->
_schema
)
{
return
false
;
}
$schema
=
$this
->
_schema
;
$relations
=
$this
->
_schema
[
'relations'
];
$schema
=
$this
->
getTable
()
->
getSchema
();
$relations
=
$schema
[
'relations'
];
if
(
isset
(
$schema
[
'columns'
]))
{
$columns
=
$schema
[
'columns'
];
...
...
@@ -126,9 +113,9 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
$array
=
array
();
foreach
(
$this
->
_data
as
$key
=>
$value
)
{
if
(
$this
->
hasRelation
(
$key
))
{
if
(
$this
->
getTable
()
->
hasRelation
(
$key
))
{
$relation
=
$this
->
getRelation
(
$key
);
$relation
=
$this
->
get
Table
()
->
get
Relation
(
$key
);
if
(
$relation
[
'type'
]
===
Doctrine_Relation
::
ONE
)
{
if
(
$this
->
_data
[
$key
]
->
hasChanges
())
{
...
...
@@ -141,7 +128,7 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
}
}
}
}
else
if
(
$this
->
hasColumn
(
$key
))
{
}
else
if
(
$this
->
getTable
()
->
hasColumn
(
$key
))
{
if
(
isset
(
$this
->
_changes
[
$key
]))
{
$array
[
$key
]
=
$value
;
}
...
...
@@ -191,6 +178,11 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
$response
=
$request
->
execute
();
}
public
function
getTable
()
{
return
$this
->
_table
;
}
public
function
getModel
()
{
return
$this
->
_model
;
...
...
@@ -200,8 +192,11 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
{
$identifier
=
array
();
if
(
isset
(
$this
->
_schema
[
'columns'
])
&&
is_array
(
$this
->
_schema
[
'columns'
]))
{
foreach
(
$this
->
_schema
[
'columns'
]
as
$name
=>
$column
)
{
$schema
=
$this
->
getTable
()
->
getSchema
();
$columns
=
$schema
[
'columns'
];
if
(
isset
(
$columns
)
&&
is_array
(
$columns
))
{
foreach
(
$columns
as
$name
=>
$column
)
{
if
(
$column
[
'primary'
]
==
true
)
{
$identifier
[
$name
]
=
$this
->
_data
[
$name
];
}
...
...
@@ -223,30 +218,6 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
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
()
{
...
...
@@ -254,15 +225,15 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
foreach
(
$this
->
_data
as
$key
=>
$value
)
{
if
(
$this
->
hasRelation
(
$key
)
&&
$value
instanceof
Doctrine_Resource_Collection
)
{
if
(
$this
->
getTable
()
->
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
)
{
}
else
if
(
$this
->
getTable
()
->
hasRelation
(
$key
)
&&
$value
instanceof
Doctrine_Resource_Record
)
{
if
(
$value
->
exists
()
||
$value
->
hasChanges
())
{
$array
[
$key
]
=
$value
->
toArray
();
}
}
else
if
(
!
$this
->
hasRelation
(
$key
)
&&
$this
->
hasColumn
(
$key
))
{
}
else
if
(
!
$this
->
getTable
()
->
hasRelation
(
$key
)
&&
$this
->
getTable
()
->
hasColumn
(
$key
))
{
$array
[
$key
]
=
$value
;
}
}
...
...
lib/Doctrine/Resource/Request.php
View file @
b447f6ca
...
...
@@ -71,18 +71,18 @@ class Doctrine_Resource_Request extends Doctrine_Resource_Params
$collection
=
new
Doctrine_Resource_Collection
(
$model
);
foreach
(
$array
as
$record
)
{
$r
=
new
Doctrine_Resource_Record
(
$model
);
$r
=
new
$model
(
);
foreach
(
$record
as
$key
=>
$value
)
{
if
(
$r
->
hasRelation
(
$key
)
&&
!
empty
(
$value
))
{
$relation
=
$r
->
getRelation
(
$key
);
if
(
$r
->
getTable
()
->
hasRelation
(
$key
)
&&
!
empty
(
$value
))
{
$relation
=
$r
->
get
Table
()
->
get
Relation
(
$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
))
{
}
else
if
(
$r
->
getTable
()
->
hasColumn
(
$key
))
{
$r
->
set
(
$key
,
$value
);
}
...
...
lib/Doctrine/Resource/Table.php
View file @
b447f6ca
...
...
@@ -34,10 +34,36 @@
class
Doctrine_Resource_Table
{
protected
$_model
=
null
;
protected
$_schema
=
null
;
public
function
__construct
(
$model
)
{
$this
->
_model
=
$model
;
$schema
=
$this
->
getConfig
(
'schema'
);
if
(
isset
(
$schema
[
'schema'
][
$model
])
&&
$schema
[
'schema'
][
$model
])
{
$this
->
_schema
=
$schema
[
'schema'
][
$model
];
}
if
(
isset
(
$schema
[
'relations'
][
$model
])
&&
$schema
[
'relations'
][
$model
])
{
$this
->
_schema
[
'relations'
]
=
$schema
[
'relations'
][
$model
];
}
}
public
function
getSchema
()
{
return
$this
->
_schema
;
}
public
function
getRelations
()
{
return
$this
->
_schema
[
'relations'
];
}
public
function
getConfig
(
$key
=
null
)
{
return
Doctrine_Resource_Client
::
getInstance
()
->
getConfig
(
$key
);
}
public
function
find
(
$pk
)
...
...
@@ -61,4 +87,28 @@ class Doctrine_Resource_Table
return
$query
->
execute
()
->
getFirst
();
}
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
];
}
}
}
\ No newline at end of file
playground/index.php
View file @
b447f6ca
...
...
@@ -18,12 +18,12 @@ if ($action == 'server') {
$config
=
array
(
'url'
=>
'http://localhost/~jwage/doctrine_trunk/playground/index.php?action=server'
);
$client
=
Doctrine_Resource_Client
::
getInstance
(
$config
);
$table
=
$client
->
getTable
(
'User'
);
$user
=
$table
->
find
(
4
);
$user
->
Phonenumber
->
add
()
->
phonenumber
=
'555-5555'
;
$user
->
name
=
'jonnwage'
;
$user
->
save
();
//$table = $client->getTable('User');
print_r
(
$user
->
toArray
());
$query
=
new
Doctrine_Resource_Query
();
$users
=
$query
->
from
(
'User u, u.Phonenumber p, u.Address a, u.Book b, b.Author a'
)
->
execute
();
print_r
(
$users
);
}
\ 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