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
5490247c
Commit
5490247c
authored
Aug 03, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new templating model
parent
90bf6241
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
69 deletions
+43
-69
Configurable.php
lib/Doctrine/Configurable.php
+3
-3
Record.php
lib/Doctrine/Record.php
+1
-4
Abstract.php
lib/Doctrine/Record/Abstract.php
+6
-0
Parser.php
lib/Doctrine/Relation/Parser.php
+30
-56
Template.php
lib/Doctrine/Template.php
+3
-6
No files found.
lib/Doctrine/Configurable.php
View file @
5490247c
...
...
@@ -180,13 +180,13 @@ abstract class Doctrine_Configurable extends Doctrine_Object
*/
public
function
getImpl
(
$template
)
{
if
(
!
isset
(
$this
->
_impl
[
$
attribu
te
]))
{
if
(
!
isset
(
$this
->
_impl
[
$
templa
te
]))
{
if
(
isset
(
$this
->
parent
))
{
return
$this
->
parent
->
getImpl
(
$
attribu
te
);
return
$this
->
parent
->
getImpl
(
$
templa
te
);
}
return
null
;
}
return
$this
->
_impl
[
$
attribu
te
];
return
$this
->
_impl
[
$
templa
te
];
}
/**
* getCacheDriver
...
...
lib/Doctrine/Record.php
View file @
5490247c
...
...
@@ -72,10 +72,7 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
* and saves will not cause infinite loops
*/
const
STATE_LOCKED
=
6
;
/**
* @var object Doctrine_Table $_table the factory that created this data access object
*/
protected
$_table
;
/**
* @var Doctrine_Node_<TreeImpl> node object
*/
...
...
lib/Doctrine/Record/Abstract.php
View file @
5490247c
...
...
@@ -32,6 +32,10 @@ Doctrine::autoload('Doctrine_Access');
*/
abstract
class
Doctrine_Record_Abstract
extends
Doctrine_Access
{
/**
* @param Doctrine_Table $_table reference to associated Doctrine_Table instance
*/
protected
$_table
;
/**
* addListener
*
...
...
@@ -244,7 +248,9 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
{
$tpl
=
new
$template
(
$options
);
$tpl
->
setTable
(
$this
->
_table
);
$tpl
->
setUp
();
$tpl
->
setTableDefinition
();
return
$this
;
}
...
...
lib/Doctrine/Relation/Parser.php
View file @
5490247c
...
...
@@ -110,59 +110,6 @@ class Doctrine_Relation_Parser
throw
new
Doctrine_Relation_Exception
(
'Relation type not set.'
);
}
if
(
strpos
(
$name
,
'[Component]'
)
!==
false
)
{
$name
=
str_replace
(
'[Component]'
,
$this
->
_table
->
getComponentName
(),
$name
);
$templateName
=
substr
(
$name
,
strlen
(
$this
->
_table
->
getComponentName
()));
if
(
substr
(
$name
,
-
8
)
===
'Template'
)
{
$name
=
substr
(
$name
,
0
,
-
8
);
}
$parent
=
new
ReflectionClass
(
$this
->
_table
->
getComponentName
());
$fileName
=
dirname
(
$parent
->
getFileName
())
.
DIRECTORY_SEPARATOR
.
$name
.
'.php'
;
if
(
file_exists
(
$fileName
))
{
require_once
(
$fileName
);
}
if
(
!
class_exists
(
$name
))
{
$template
=
new
$templateName
();
$conn
=
$this
->
_table
->
getConnection
();
$refl
=
new
ReflectionClass
(
$templateName
);
$file
=
file
(
$refl
->
getFileName
());
$lines
[]
=
'class '
.
$name
.
' extends Doctrine_Record'
.
"
\n
"
;
$lines
[]
=
'{'
.
"
\n
"
;
// read all template method definitions
foreach
(
$refl
->
getMethods
()
as
$method
)
{
if
(
$method
->
getDeclaringClass
()
->
getName
()
===
$refl
->
getName
())
{
$start
=
$method
->
getStartLine
()
-
1
;
$end
=
$method
->
getEndLine
()
-
1
;
// append method definitions
$lines
=
array_merge
(
$lines
,
array_slice
(
$file
,
$start
,
(
$end
-
$start
)
+
1
));
}
}
$lines
[]
=
'}'
.
"
\n
"
;
if
(
file_exists
(
$fileName
))
{
throw
new
Doctrine_Template_Exception
(
"Couldn't generate class for template."
);
}
$code
=
str_replace
(
'[Component]'
,
$this
->
_table
->
getComponentName
(),
implode
(
""
,
$lines
));
// create the actual class file
$fp
=
fopen
(
$fileName
,
'w+'
);
fwrite
(
$fp
,
"<?php
\n
"
.
$code
);
fclose
(
$fp
);
// include the generated class
require_once
(
$fileName
);
}
}
$this
->
_pending
[
$alias
]
=
array_merge
(
$options
,
array
(
'class'
=>
$name
,
'alias'
=>
$alias
));
$m
=
Doctrine_Manager
::
getInstance
();
...
...
@@ -261,6 +208,30 @@ class Doctrine_Relation_Parser
return
$this
->
_relations
;
}
/**
* getImpl
* returns the table class of the concrete implementation for given template
* if the given template is not a template then this method just returns the
* table class for the given record
*
* @param string $template
*/
public
function
getImpl
(
$template
)
{
$conn
=
$this
->
_table
->
getConnection
();
if
(
in_array
(
'Doctrine_Template'
,
class_parents
(
$template
)))
{
$impl
=
$this
->
_table
->
getImpl
(
$template
);
if
(
$impl
===
null
)
{
throw
new
Doctrine_Relation_Parser_Exception
(
"Couldn't find concrete implementation for template "
.
$template
);
}
}
else
{
$impl
=
$template
;
}
return
$conn
->
getTable
(
$impl
);
}
/**
* Completes the given association definition
*
...
...
@@ -270,8 +241,9 @@ class Doctrine_Relation_Parser
public
function
completeAssocDefinition
(
$def
)
{
$conn
=
$this
->
_table
->
getConnection
();
$def
[
'table'
]
=
$conn
->
getTable
(
$def
[
'class'
]);
$def
[
'refTable'
]
=
$conn
->
getTable
(
$def
[
'refClass'
]);
$def
[
'table'
]
=
$this
->
getImpl
(
$def
[
'class'
]);
$def
[
'class'
]
=
$def
[
'table'
]
->
getComponentName
();
$def
[
'refTable'
]
=
$this
->
getImpl
(
$def
[
'refClass'
]);
$id
=
$def
[
'refTable'
]
->
getIdentifier
();
...
...
@@ -378,7 +350,9 @@ class Doctrine_Relation_Parser
public
function
completeDefinition
(
$def
)
{
$conn
=
$this
->
_table
->
getConnection
();
$def
[
'table'
]
=
$conn
->
getTable
(
$def
[
'class'
]);
$def
[
'table'
]
=
$this
->
getImpl
(
$def
[
'class'
]);
$def
[
'class'
]
=
$def
[
'table'
]
->
getComponentName
();
$foreignClasses
=
array_merge
(
$def
[
'table'
]
->
getOption
(
'parents'
),
array
(
$def
[
'class'
]));
$localClasses
=
array_merge
(
$this
->
_table
->
getOption
(
'parents'
),
array
(
$this
->
_table
->
getComponentName
()));
...
...
lib/Doctrine/Template.php
View file @
5490247c
...
...
@@ -32,10 +32,7 @@ Doctrine::autoload('Doctrine_Record_Abstract');
*/
class
Doctrine_Template
extends
Doctrine_Record_Abstract
{
/**
* @param Doctrine_Table $_table reference to associated Doctrine_Table instance
*/
protected
$_table
;
/**
* setTable
*
...
...
@@ -55,10 +52,10 @@ class Doctrine_Template extends Doctrine_Record_Abstract
{
return
$this
->
_table
;
}
public
function
setUp
()
{
}
public
function
setTableDefinition
()
...
...
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