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
2174bc99
Commit
2174bc99
authored
Nov 25, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enhanced the internal API of various plugins
parent
c25d481d
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
98 deletions
+68
-98
AuditLog.php
lib/Doctrine/AuditLog.php
+3
-7
I18n.php
lib/Doctrine/I18n.php
+3
-12
Plugin.php
lib/Doctrine/Plugin.php
+35
-34
Abstract.php
lib/Doctrine/Record/Abstract.php
+1
-1
Search.php
lib/Doctrine/Search.php
+22
-31
File.php
lib/Doctrine/Search/File.php
+2
-4
Searchable.php
lib/Doctrine/Template/Searchable.php
+2
-9
No files found.
lib/Doctrine/AuditLog.php
View file @
2174bc99
...
@@ -38,6 +38,7 @@ class Doctrine_AuditLog extends Doctrine_Plugin
...
@@ -38,6 +38,7 @@ class Doctrine_AuditLog extends Doctrine_Plugin
'generateFiles'
=>
false
,
'generateFiles'
=>
false
,
'table'
=>
false
,
'table'
=>
false
,
'pluginTable'
=>
false
,
'pluginTable'
=>
false
,
'children'
=>
array
(),
);
);
/**
/**
...
@@ -105,14 +106,9 @@ class Doctrine_AuditLog extends Doctrine_Plugin
...
@@ -105,14 +106,9 @@ class Doctrine_AuditLog extends Doctrine_Plugin
$id
=
$this
->
_options
[
'table'
]
->
getIdentifier
();
$id
=
$this
->
_options
[
'table'
]
->
getIdentifier
();
$
options
=
array
(
'className'
=>
$this
->
_options
[
'className'
]
);
$
relations
=
$this
->
buildRelation
(
);
$relations
=
array
(
$name
=>
array
(
'local'
=>
$id
,
$this
->
generateClass
(
$columns
,
$relations
);
'foreign'
=>
$id
,
'onDelete'
=>
'CASCADE'
,
'onUpdate'
=>
'CASCADE'
));
$this
->
generateClass
(
$options
,
$columns
,
array
());
$this
->
_options
[
'pluginTable'
]
=
$this
->
_options
[
'table'
]
->
getConnection
()
->
getTable
(
$this
->
_options
[
'className'
]);
$this
->
_options
[
'pluginTable'
]
=
$this
->
_options
[
'table'
]
->
getConnection
()
->
getTable
(
$this
->
_options
[
'className'
]);
...
...
lib/Doctrine/I18n.php
View file @
2174bc99
...
@@ -86,27 +86,18 @@ class Doctrine_I18n extends Doctrine_Plugin
...
@@ -86,27 +86,18 @@ class Doctrine_I18n extends Doctrine_Plugin
'fixed'
=>
true
,
'fixed'
=>
true
,
'primary'
=>
true
);
'primary'
=>
true
);
$local
=
(
count
(
$fk
)
>
1
)
?
array_keys
(
$fk
)
:
key
(
$fk
);
$relations
=
$this
->
buildRelation
();
$relations
=
array
(
$name
=>
array
(
'local'
=>
$local
,
'foreign'
=>
$this
->
_options
[
'table'
]
->
getIdentifier
(),
'onDelete'
=>
'CASCADE'
,
'onUpdate'
=>
'CASCADE'
));
$columns
+=
$fk
;
$columns
+=
$fk
;
$options
=
array
(
'className'
=>
$this
->
_options
[
'className'
],
$options
=
array
(
'queryParts'
=>
array
(
'indexBy'
=>
'lang'
));
'queryParts'
=>
array
(
'indexBy'
=>
'lang'
));
$this
->
generateClass
(
$
options
,
$columns
,
$rela
tions
);
$this
->
generateClass
(
$
columns
,
$relations
,
$op
tions
);
$this
->
_options
[
'pluginTable'
]
=
$this
->
_options
[
'table'
]
->
getConnection
()
->
getTable
(
$this
->
_options
[
'className'
]);
$this
->
_options
[
'pluginTable'
]
=
$this
->
_options
[
'table'
]
->
getConnection
()
->
getTable
(
$this
->
_options
[
'className'
]);
$this
->
_options
[
'pluginTable'
]
->
bindQueryPart
(
'indexBy'
,
'lang'
);
$this
->
_options
[
'pluginTable'
]
->
bindQueryPart
(
'indexBy'
,
'lang'
);
$this
->
generateChildDefinitions
();
return
true
;
return
true
;
}
}
}
}
lib/Doctrine/Plugin.php
View file @
2174bc99
...
@@ -40,7 +40,7 @@ abstract class Doctrine_Plugin
...
@@ -40,7 +40,7 @@ abstract class Doctrine_Plugin
'generateFiles'
=>
false
,
'generateFiles'
=>
false
,
'table'
=>
false
,
'table'
=>
false
,
'pluginTable'
=>
false
,
'pluginTable'
=>
false
,
'children'
=>
array
()
,
);
'children'
=>
array
());
/**
/**
* __get
* __get
...
@@ -112,6 +112,8 @@ abstract class Doctrine_Plugin
...
@@ -112,6 +112,8 @@ abstract class Doctrine_Plugin
public
function
buildPluginDefinition
(
Doctrine_Table
$table
)
public
function
buildPluginDefinition
(
Doctrine_Table
$table
)
{
{
$this
->
initOptions
();
$this
->
_options
[
'table'
]
=
$table
;
$this
->
_options
[
'table'
]
=
$table
;
$this
->
_options
[
'className'
]
=
str_replace
(
'%CLASS%'
,
$this
->
_options
[
'className'
]
=
str_replace
(
'%CLASS%'
,
...
@@ -124,30 +126,29 @@ abstract class Doctrine_Plugin
...
@@ -124,30 +126,29 @@ abstract class Doctrine_Plugin
}
}
$this
->
buildDefinition
();
$this
->
buildDefinition
();
}
abstract
public
function
buildDefinition
();
public
function
buildForeignKeys
(
Doctrine_Table
$table
)
$this
->
buildChildDefinitions
();
}
/**
* empty template method for providing the concrete plugins the ability
* to initialize options before the actual definition is being built
*
* @return void
*/
public
function
initOptions
()
{
{
$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
;
abstract
public
function
buildDefinition
();
}
public
function
generate
ChildDefinitions
()
public
function
build
ChildDefinitions
()
{
{
if
(
!
isset
(
$this
->
_options
[
'children'
]))
{
Doctrine
::
dump
(
debug_backtrace
());
throw
new
Doctrine_Plugin_Exception
(
"Unknown option 'children'."
);
}
foreach
(
$this
->
_options
[
'children'
]
as
$child
)
{
foreach
(
$this
->
_options
[
'children'
]
as
$child
)
{
$this
->
_options
[
'pluginTable'
]
->
addTemplate
(
get_class
(
$child
),
$child
);
$this
->
_options
[
'pluginTable'
]
->
addTemplate
(
get_class
(
$child
),
$child
);
...
@@ -166,7 +167,7 @@ abstract class Doctrine_Plugin
...
@@ -166,7 +167,7 @@ abstract class Doctrine_Plugin
* @param Doctrine_Table $table the table object that owns the plugin
* @param Doctrine_Table $table the table object that owns the plugin
* @return array an array of foreign key definitions
* @return array an array of foreign key definitions
*/
*/
public
function
generate
ForeignKeys
(
Doctrine_Table
$table
)
public
function
build
ForeignKeys
(
Doctrine_Table
$table
)
{
{
$fk
=
array
();
$fk
=
array
();
...
@@ -186,22 +187,18 @@ abstract class Doctrine_Plugin
...
@@ -186,22 +187,18 @@ abstract class Doctrine_Plugin
}
}
/**
/**
*
generates
a relation array to given table
*
build
a relation array to given table
*
*
* this method can be used for generating the relation from the plugin
* this method can be used for generating the relation from the plugin
* table to the owner table
* table to the owner table
*
*
* @param Doctrine_Table $table the table object to construct the relation to
* @param array $foreignKeys an array of foreign keys
* @return array the generated relation array
* @return array the generated relation array
*/
*/
public
function
generateRelation
(
Doctrine_Table
$table
,
array
$foreignKeys
)
public
function
buildRelation
(
)
{
{
$local
=
(
count
(
$foreignKeys
)
>
1
)
?
array_keys
(
$foreignKeys
)
:
key
(
$foreignKeys
);
$relation
=
array
(
$this
->
_options
[
'table'
]
->
getComponentName
()
=>
array
(
'local'
=>
$this
->
_options
[
'table'
]
->
getIdentifier
(),
$relation
=
array
(
$table
->
getComponentName
()
=>
'foreign'
=>
$this
->
_options
[
'table'
]
->
getIdentifier
(),
array
(
'local'
=>
$local
,
'foreign'
=>
$table
->
getIdentifier
(),
'onDelete'
=>
'CASCADE'
,
'onDelete'
=>
'CASCADE'
,
'onUpdate'
=>
'CASCADE'
));
'onUpdate'
=>
'CASCADE'
));
...
@@ -211,15 +208,19 @@ abstract class Doctrine_Plugin
...
@@ -211,15 +208,19 @@ abstract class Doctrine_Plugin
/**
/**
* generates the class definition for plugin class
* generates the class definition for plugin class
*
*
* @param array $options plugin class options, keys representing the option names
* and values as option values
* @param array $columns the plugin class columns, keys representing the column names
* @param array $columns the plugin class columns, keys representing the column names
* and values as column definitions
* and values as column definitions
*
* @param array $relations the bound relations of the plugin class
* @param array $relations the bound relations of the plugin class
*
* @param array $options plugin class options, keys representing the option names
* and values as option values
* @return void
* @return void
*/
*/
public
function
generateClass
(
$options
,
$columns
,
$relations
)
public
function
generateClass
(
array
$columns
=
array
(),
array
$relations
=
array
(),
array
$options
=
array
()
)
{
{
$options
[
'className'
]
=
$this
->
_options
[
'className'
];
$builder
=
new
Doctrine_Import_Builder
();
$builder
=
new
Doctrine_Import_Builder
();
if
(
$this
->
_options
[
'generateFiles'
])
{
if
(
$this
->
_options
[
'generateFiles'
])
{
...
...
lib/Doctrine/Record/Abstract.php
View file @
2174bc99
...
@@ -275,7 +275,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
...
@@ -275,7 +275,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
/**
/**
* actAs
* actAs
* loads
a
given plugin
* loads
the
given plugin
*
*
* @param mixed $tpl
* @param mixed $tpl
* @param array $options
* @param array $options
...
...
lib/Doctrine/Search.php
View file @
2174bc99
...
@@ -40,15 +40,12 @@ class Doctrine_Search extends Doctrine_Plugin
...
@@ -40,15 +40,12 @@ class Doctrine_Search extends Doctrine_Plugin
'type'
=>
self
::
INDEX_TABLES
,
'type'
=>
self
::
INDEX_TABLES
,
'className'
=>
'%CLASS%Index'
,
'className'
=>
'%CLASS%Index'
,
'generatePath'
=>
false
,
'generatePath'
=>
false
,
'
resource'
=>
null
,
'
table'
=>
null
,
'batchUpdates'
=>
false
,
'batchUpdates'
=>
false
,
'pluginTable'
=>
false
,
'pluginTable'
=>
false
,
'fields'
=>
array
(),
'fields'
=>
array
(),
'connection'
=>
null
);
'connection'
=>
null
,
'children'
=>
array
());
protected
$_built
=
false
;
/**
/**
* __construct
* __construct
*
*
...
@@ -107,9 +104,9 @@ class Doctrine_Search extends Doctrine_Plugin
...
@@ -107,9 +104,9 @@ class Doctrine_Search extends Doctrine_Plugin
$fields
=
$this
->
getOption
(
'fields'
);
$fields
=
$this
->
getOption
(
'fields'
);
$class
=
$this
->
getOption
(
'className'
);
$class
=
$this
->
getOption
(
'className'
);
$name
=
$this
->
getOption
(
'
resourc
e'
)
->
getComponentName
();
$name
=
$this
->
getOption
(
'
tabl
e'
)
->
getComponentName
();
$conn
=
$this
->
getOption
(
'
resourc
e'
)
->
getConnection
();
$conn
=
$this
->
getOption
(
'
tabl
e'
)
->
getConnection
();
$identifier
=
$this
->
_options
[
'
resourc
e'
]
->
getIdentifier
();
$identifier
=
$this
->
_options
[
'
tabl
e'
]
->
getIdentifier
();
$q
=
Doctrine_Query
::
create
()
->
delete
()
$q
=
Doctrine_Query
::
create
()
->
delete
()
->
from
(
$class
);
->
from
(
$class
);
...
@@ -121,7 +118,7 @@ class Doctrine_Search extends Doctrine_Plugin
...
@@ -121,7 +118,7 @@ class Doctrine_Search extends Doctrine_Plugin
if
(
$this
->
_options
[
'batchUpdates'
]
===
true
)
{
if
(
$this
->
_options
[
'batchUpdates'
]
===
true
)
{
$index
=
new
$class
();
$index
=
new
$class
();
foreach
((
array
)
$this
->
_options
[
'
resourc
e'
]
->
getIdentifier
()
as
$id
)
{
foreach
((
array
)
$this
->
_options
[
'
tabl
e'
]
->
getIdentifier
()
as
$id
)
{
$index
->
$id
=
$data
[
$id
];
$index
->
$id
=
$data
[
$id
];
}
}
...
@@ -139,7 +136,7 @@ class Doctrine_Search extends Doctrine_Plugin
...
@@ -139,7 +136,7 @@ class Doctrine_Search extends Doctrine_Plugin
$index
->
keyword
=
$term
;
$index
->
keyword
=
$term
;
$index
->
position
=
$pos
;
$index
->
position
=
$pos
;
$index
->
field
=
$field
;
$index
->
field
=
$field
;
foreach
((
array
)
$this
->
_options
[
'
resourc
e'
]
->
getIdentifier
()
as
$id
)
{
foreach
((
array
)
$this
->
_options
[
'
tabl
e'
]
->
getIdentifier
()
as
$id
)
{
$index
->
$id
=
$data
[
$id
];
$index
->
$id
=
$data
[
$id
];
}
}
...
@@ -160,9 +157,9 @@ class Doctrine_Search extends Doctrine_Plugin
...
@@ -160,9 +157,9 @@ class Doctrine_Search extends Doctrine_Plugin
{
{
$this
->
buildDefinition
();
$this
->
buildDefinition
();
$conn
=
$this
->
_options
[
'
resourc
e'
]
->
getConnection
();
$conn
=
$this
->
_options
[
'
tabl
e'
]
->
getConnection
();
$tableName
=
$this
->
_options
[
'
resourc
e'
]
->
getTableName
();
$tableName
=
$this
->
_options
[
'
tabl
e'
]
->
getTableName
();
$id
=
$this
->
_options
[
'
resourc
e'
]
->
getIdentifier
();
$id
=
$this
->
_options
[
'
tabl
e'
]
->
getIdentifier
();
$query
=
'SELECT * FROM '
.
$conn
->
quoteIdentifier
(
$tableName
)
$query
=
'SELECT * FROM '
.
$conn
->
quoteIdentifier
(
$tableName
)
.
' WHERE '
.
$conn
->
quoteIdentifier
(
$id
)
.
' WHERE '
.
$conn
->
quoteIdentifier
(
$id
)
...
@@ -188,7 +185,7 @@ class Doctrine_Search extends Doctrine_Plugin
...
@@ -188,7 +185,7 @@ class Doctrine_Search extends Doctrine_Plugin
{
{
$this
->
buildDefinition
();
$this
->
buildDefinition
();
$id
=
$this
->
_options
[
'
resourc
e'
]
->
getIdentifier
();
$id
=
$this
->
_options
[
'
tabl
e'
]
->
getIdentifier
();
$class
=
$this
->
_options
[
'className'
];
$class
=
$this
->
_options
[
'className'
];
$fields
=
$this
->
_options
[
'fields'
];
$fields
=
$this
->
_options
[
'fields'
];
$conn
=
$this
->
_options
[
'connection'
];
$conn
=
$this
->
_options
[
'connection'
];
...
@@ -241,17 +238,12 @@ class Doctrine_Search extends Doctrine_Plugin
...
@@ -241,17 +238,12 @@ class Doctrine_Search extends Doctrine_Plugin
*/
*/
public
function
buildDefinition
()
public
function
buildDefinition
()
{
{
if
(
$this
->
_built
)
{
if
(
!
isset
(
$this
->
_options
[
'table'
]))
{
return
true
;
Doctrine
::
dump
(
debug_backtrace
());
throw
new
Doctrine_Plugin_Exception
(
"Unknown option 'table'."
);
}
}
$this
->
_built
=
true
;
$componentName
=
$this
->
_options
[
'resource'
]
->
getComponentName
();
// check for placeholders
$componentName
=
$this
->
_options
[
'table'
]
->
getComponentName
();
if
(
strpos
(
$this
->
_options
[
'className'
],
'%'
)
!==
false
)
{
$this
->
_options
[
'className'
]
=
str_replace
(
'%CLASS%'
,
$componentName
,
$this
->
_options
[
'className'
]);
}
$className
=
$this
->
getOption
(
'className'
);
$className
=
$this
->
getOption
(
'className'
);
...
@@ -271,20 +263,19 @@ class Doctrine_Search extends Doctrine_Plugin
...
@@ -271,20 +263,19 @@ class Doctrine_Search extends Doctrine_Plugin
'primary'
=>
true
,
'primary'
=>
true
,
));
));
$id
=
$this
->
_options
[
'
resourc
e'
]
->
getIdentifier
();
$id
=
$this
->
_options
[
'
tabl
e'
]
->
getIdentifier
();
$
options
=
array
(
'className'
=>
$className
);
$
fk
=
$this
->
buildForeignKeys
(
$this
->
_options
[
'table'
]
);
$fk
=
$this
->
generateForeignKeys
(
$this
->
_options
[
'resource'
]);
$columns
+=
$fk
;
$columns
+=
$fk
;
$relations
=
array
();
$relations
=
array
();
// only generate relations for database based searches
// only generate relations for database based searches
if
(
!
$this
instanceof
Doctrine_Search_File
)
{
if
(
!
$this
instanceof
Doctrine_Search_File
)
{
$relations
=
$this
->
generateRelation
(
$this
->
_options
[
'resource'
],
$fk
);
$relations
=
$this
->
buildRelation
(
);
}
}
$this
->
generateClass
(
$
options
,
$
columns
,
$relations
);
$this
->
generateClass
(
$columns
,
$relations
);
$this
->
_options
[
'pluginTable'
]
=
$this
->
_options
[
'connection'
]
->
getTable
(
$this
->
_options
[
'className'
]);
$this
->
_options
[
'pluginTable'
]
=
$this
->
_options
[
'connection'
]
->
getTable
(
$this
->
_options
[
'className'
]);
...
...
lib/Doctrine/Search/File.php
View file @
2174bc99
...
@@ -40,15 +40,13 @@ class Doctrine_Search_File extends Doctrine_Search
...
@@ -40,15 +40,13 @@ class Doctrine_Search_File extends Doctrine_Search
$table
=
new
Doctrine_Table
(
'File'
,
Doctrine_Manager
::
connection
());
$table
=
new
Doctrine_Table
(
'File'
,
Doctrine_Manager
::
connection
());
$table
->
setColumn
(
'url'
,
'string'
,
255
,
array
(
'primary'
=>
true
));
$table
->
setColumn
(
'url'
,
'string'
,
255
,
array
(
'primary'
=>
true
));
$this
->
_options
[
'resource'
]
=
$table
;
}
}
if
(
empty
(
$this
->
_options
[
'fields'
]))
{
if
(
empty
(
$this
->
_options
[
'fields'
]))
{
$this
->
_options
[
'fields'
]
=
array
(
'url'
,
'content'
);
$this
->
_options
[
'fields'
]
=
array
(
'url'
,
'content'
);
}
}
$this
->
build
Definition
(
);
$this
->
build
PluginDefinition
(
$table
);
}
}
public
function
indexDirectory
(
$dir
)
public
function
indexDirectory
(
$dir
)
...
...
lib/Doctrine/Template/Searchable.php
View file @
2174bc99
...
@@ -45,17 +45,10 @@ class Doctrine_Template_Searchable extends Doctrine_Template
...
@@ -45,17 +45,10 @@ class Doctrine_Template_Searchable extends Doctrine_Template
public
function
setUp
()
public
function
setUp
()
{
{
$id
=
$this
->
_table
->
getIdentifier
();
$id
=
$this
->
_table
->
getIdentifier
();
$name
=
$this
->
_table
->
getComponentName
();
$className
=
$this
->
_plugin
->
getOption
(
'className'
);
if
(
strpos
(
$className
,
'%CLASS%'
)
!==
false
)
{
$this
->
_plugin
->
buildPluginDefinition
(
$this
->
_table
);
$this
->
_plugin
->
setOption
(
'className'
,
str_replace
(
'%CLASS%'
,
$name
,
$className
));
$className
=
$this
->
_plugin
->
getOption
(
'className'
);
}
$this
->
_plugin
->
setOption
(
'resource'
,
$this
->
_table
);
$this
->
_plugin
->
buildDefinition
();
$this
->
hasMany
(
$
className
,
array
(
'local'
=>
$id
,
'foreign'
=>
$id
));
$this
->
hasMany
(
$
this
->
_plugin
->
getOption
(
'className'
)
,
array
(
'local'
=>
$id
,
'foreign'
=>
$id
));
$this
->
addListener
(
new
Doctrine_Search_Listener
(
$this
->
_plugin
));
$this
->
addListener
(
new
Doctrine_Search_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