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
ae4b7157
Commit
ae4b7157
authored
Nov 25, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enhanced plugin building procedure
parent
3baf1af6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
61 deletions
+67
-61
AuditLog.php
lib/Doctrine/AuditLog.php
+8
-19
I18n.php
lib/Doctrine/I18n.php
+8
-27
Plugin.php
lib/Doctrine/Plugin.php
+43
-3
I18n.php
lib/Doctrine/Template/I18n.php
+4
-9
Sluggable.php
lib/Doctrine/Template/Sluggable.php
+1
-1
Versionable.php
lib/Doctrine/Template/Versionable.php
+3
-2
No files found.
lib/Doctrine/AuditLog.php
View file @
ae4b7157
...
...
@@ -46,7 +46,7 @@ class Doctrine_AuditLog extends Doctrine_Plugin
* @param array $options An array of options
* @return void
*/
public
function
__construct
(
$options
)
public
function
__construct
(
array
$options
=
array
()
)
{
$this
->
_options
=
array_merge
(
$this
->
_options
,
$options
);
}
...
...
@@ -85,22 +85,11 @@ class Doctrine_AuditLog extends Doctrine_Plugin
* @param Doctrine_Table $table
* @return boolean true on success otherwise false.
*/
public
function
buildDefinition
(
Doctrine_Table
$table
)
public
function
buildDefinition
()
{
$this
->
_options
[
'className'
]
=
str_replace
(
'%CLASS%'
,
$this
->
_options
[
'table'
]
->
getComponentName
(),
$this
->
_options
[
'className'
]);
$name
=
$this
->
_options
[
'table'
]
->
getComponentName
();
$name
=
$table
->
getComponentName
();
$className
=
$name
.
'Version'
;
// check that class doesn't exist (otherwise we cannot create it)
if
(
class_exists
(
$className
))
{
return
false
;
}
$columns
=
$table
->
getColumns
();
$columns
=
$this
->
_options
[
'table'
]
->
getColumns
();
// remove all sequence, autoincrement and unique constraint definitions
foreach
(
$columns
as
$column
=>
$definition
)
{
...
...
@@ -114,10 +103,10 @@ class Doctrine_AuditLog extends Doctrine_Plugin
'length'
=>
8
,
'primary'
=>
true
);
$id
=
$table
->
getIdentifier
();
$id
=
$this
->
_options
[
'table'
]
->
getIdentifier
();
$options
=
array
(
'className'
=>
$this
->
_options
[
'className'
]);
$options
=
array
(
'className'
=>
$className
);
$relations
=
array
(
$name
=>
array
(
'local'
=>
$id
,
'foreign'
=>
$id
,
'onDelete'
=>
'CASCADE'
,
...
...
@@ -125,7 +114,7 @@ class Doctrine_AuditLog extends Doctrine_Plugin
$this
->
generateClass
(
$options
,
$columns
,
array
());
$this
->
_options
[
'pluginTable'
]
=
$t
able
->
getConnection
()
->
getTable
(
$this
->
_options
[
'className'
]);
$this
->
_options
[
'pluginTable'
]
=
$t
his
->
_options
[
'table'
]
->
getConnection
()
->
getTable
(
$this
->
_options
[
'className'
]);
return
true
;
}
...
...
lib/Doctrine/I18n.php
View file @
ae4b7157
...
...
@@ -58,48 +58,29 @@ class Doctrine_I18n extends Doctrine_Plugin
* @param object $Doctrine_Table
* @return void
*/
public
function
buildDefinition
(
Doctrine_Table
$table
)
public
function
buildDefinition
()
{
if
(
empty
(
$this
->
_options
[
'fields'
]))
{
throw
new
Doctrine_I18n_Exception
(
'Fields not set.'
);
}
$this
->
_options
[
'className'
]
=
str_replace
(
'%CLASS%'
,
$this
->
_options
[
'table'
]
->
getComponentName
(),
$this
->
_options
[
'className'
]);
$name
=
$table
->
getComponentName
();
if
(
class_exists
(
$this
->
_options
[
'className'
]))
{
return
false
;
}
$name
=
$this
->
_options
[
'table'
]
->
getComponentName
();
$columns
=
array
();
$id
=
$table
->
getIdentifier
();
$options
=
array
(
'className'
=>
$this
->
_options
[
'className'
]);
$fk
=
array
();
foreach
((
array
)
$id
as
$column
)
{
$def
=
$table
->
getDefinitionOf
(
$column
);
$fk
=
$this
->
buildForeignKeys
(
$this
->
_options
[
'table'
]);
unset
(
$def
[
'autoincrement'
]);
unset
(
$def
[
'sequence'
]);
unset
(
$def
[
'unique'
]);
$fk
[
$column
]
=
$def
;
}
$cols
=
$table
->
getColumns
();
$cols
=
$this
->
_options
[
'table'
]
->
getColumns
();
foreach
(
$cols
as
$column
=>
$definition
)
{
if
(
in_array
(
$column
,
$this
->
_options
[
'fields'
]))
{
$columns
[
$column
]
=
$definition
;
$t
able
->
removeColumn
(
$column
);
$t
his
->
_options
[
'table'
]
->
removeColumn
(
$column
);
}
}
$columns
[
'lang'
]
=
array
(
'type'
=>
'string'
,
'length'
=>
2
,
'fixed'
=>
true
,
...
...
@@ -108,7 +89,7 @@ class Doctrine_I18n extends Doctrine_Plugin
$local
=
(
count
(
$fk
)
>
1
)
?
array_keys
(
$fk
)
:
key
(
$fk
);
$relations
=
array
(
$name
=>
array
(
'local'
=>
$local
,
'foreign'
=>
$
id
,
'foreign'
=>
$
this
->
_options
[
'table'
]
->
getIdentifier
()
,
'onDelete'
=>
'CASCADE'
,
'onUpdate'
=>
'CASCADE'
));
...
...
@@ -120,7 +101,7 @@ class Doctrine_I18n extends Doctrine_Plugin
$this
->
generateClass
(
$options
,
$columns
,
$relations
);
$this
->
_options
[
'pluginTable'
]
=
$t
able
->
getConnection
()
->
getTable
(
$this
->
_options
[
'className'
]);
$this
->
_options
[
'pluginTable'
]
=
$t
his
->
_options
[
'table'
]
->
getConnection
()
->
getTable
(
$this
->
_options
[
'className'
]);
$this
->
_options
[
'pluginTable'
]
->
bindQueryPart
(
'indexBy'
,
'lang'
);
...
...
lib/Doctrine/Plugin.php
View file @
ae4b7157
...
...
@@ -30,13 +30,17 @@
* @link www.phpdoctrine.com
* @since 1.0
*/
class
Doctrine_Plugin
abstract
class
Doctrine_Plugin
{
/**
* @var array $_options an array of plugin specific options
*/
protected
$_options
=
array
(
'generateFiles'
=>
false
,
'identifier'
=>
false
);
'identifier'
=>
false
,
'generateFiles'
=>
false
,
'table'
=>
false
,
'pluginTable'
=>
false
,
'children'
=>
array
(),);
/**
* __get
...
...
@@ -93,7 +97,7 @@ class Doctrine_Plugin
public
function
addChild
(
Doctrine_Template
$template
)
{
$this
->
_options
[
'children'
][]
=
$template
;
$this
->
_options
[
'children'
][]
=
$template
;
}
/**
...
...
@@ -106,6 +110,42 @@ class Doctrine_Plugin
return
$this
->
_options
;
}
public
function
buildPluginDefinition
(
Doctrine_Table
$table
)
{
$this
->
_options
[
'table'
]
=
$table
;
$this
->
_options
[
'className'
]
=
str_replace
(
'%CLASS%'
,
$this
->
_options
[
'table'
]
->
getComponentName
(),
$this
->
_options
[
'className'
]);
// check that class doesn't exist (otherwise we cannot create it)
if
(
class_exists
(
$this
->
_options
[
'className'
]))
{
return
false
;
}
$this
->
buildDefinition
();
}
abstract
public
function
buildDefinition
();
public
function
buildForeignKeys
(
Doctrine_Table
$table
)
{
$id
=
$table
->
getIdentifier
();
$fk
=
array
();
foreach
((
array
)
$id
as
$column
)
{
$def
=
$table
->
getDefinitionOf
(
$column
);
unset
(
$def
[
'autoincrement'
]);
unset
(
$def
[
'sequence'
]);
unset
(
$def
[
'unique'
]);
$fk
[
$column
]
=
$def
;
}
return
$fk
;
}
public
function
generateChildDefinitions
()
{
foreach
(
$this
->
_options
[
'children'
]
as
$child
)
{
...
...
lib/Doctrine/Template/I18n.php
View file @
ae4b7157
...
...
@@ -38,7 +38,7 @@ class Doctrine_Template_I18n extends Doctrine_Template
* @param string $array
* @return void
*/
public
function
__construct
(
array
$options
)
public
function
__construct
(
array
$options
=
array
()
)
{
$this
->
_plugin
=
new
Doctrine_I18n
(
$options
);
}
...
...
@@ -49,17 +49,12 @@ class Doctrine_Template_I18n extends Doctrine_Template
*/
public
function
setUp
()
{
$this
->
_plugin
->
setOption
(
'table'
,
$this
->
_table
);
$name
=
$this
->
_table
->
getComponentName
();
$className
=
$this
->
_plugin
->
getOption
(
'className'
);
if
(
strpos
(
$className
,
'%CLASS%'
)
!==
false
)
{
$this
->
_plugin
->
setOption
(
'className'
,
str_replace
(
'%CLASS%'
,
$name
,
$className
));
$className
=
$this
->
_plugin
->
getOption
(
'className'
);
}
$this
->
_plugin
->
buildPluginDefinition
(
$this
->
_table
);
$className
=
$this
->
_plugin
->
getOption
(
'className'
);
$this
->
_plugin
->
buildDefinition
(
$this
->
_table
);
$id
=
$this
->
_table
->
getIdentifier
();
$this
->
hasMany
(
$className
.
' as Translation'
,
array
(
'local'
=>
$id
,
'foreign'
=>
$id
));
...
...
lib/Doctrine/Template/Sluggable.php
View file @
ae4b7157
...
...
@@ -67,4 +67,4 @@ class Doctrine_Template_Sluggable extends Doctrine_Template
$this
->
addListener
(
new
Doctrine_Template_Listener_Sluggable
(
$this
->
_options
));
}
}
\ No newline at end of file
}
lib/Doctrine/Template/Versionable.php
View file @
ae4b7157
...
...
@@ -38,8 +38,9 @@ class Doctrine_Template_Versionable extends Doctrine_Template
}
public
function
setUp
()
{
$this
->
_plugin
->
setOption
(
'table'
,
$this
->
_table
);
$this
->
_plugin
->
buildDefinition
(
$this
->
_table
);
$this
->
_plugin
->
buildPluginDefinition
(
$this
->
_table
);
$this
->
hasColumn
(
'version'
,
'integer'
,
8
);
$this
->
addListener
(
new
Doctrine_AuditLog_Listener
(
$this
->
_plugin
));
}
...
...
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