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
Hide 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
'generateFiles'
=>
false
,
'table'
=>
false
,
'pluginTable'
=>
false
,
'children'
=>
array
(),
);
/**
...
...
@@ -105,14 +106,9 @@ class Doctrine_AuditLog extends Doctrine_Plugin
$id
=
$this
->
_options
[
'table'
]
->
getIdentifier
();
$
options
=
array
(
'className'
=>
$this
->
_options
[
'className'
]
);
$
relations
=
$this
->
buildRelation
(
);
$relations
=
array
(
$name
=>
array
(
'local'
=>
$id
,
'foreign'
=>
$id
,
'onDelete'
=>
'CASCADE'
,
'onUpdate'
=>
'CASCADE'
));
$this
->
generateClass
(
$options
,
$columns
,
array
());
$this
->
generateClass
(
$columns
,
$relations
);
$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
'fixed'
=>
true
,
'primary'
=>
true
);
$local
=
(
count
(
$fk
)
>
1
)
?
array_keys
(
$fk
)
:
key
(
$fk
);
$relations
=
array
(
$name
=>
array
(
'local'
=>
$local
,
'foreign'
=>
$this
->
_options
[
'table'
]
->
getIdentifier
(),
'onDelete'
=>
'CASCADE'
,
'onUpdate'
=>
'CASCADE'
));
$relations
=
$this
->
buildRelation
();
$columns
+=
$fk
;
$options
=
array
(
'className'
=>
$this
->
_options
[
'className'
],
'queryParts'
=>
array
(
'indexBy'
=>
'lang'
));
$options
=
array
(
'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'
]
->
bindQueryPart
(
'indexBy'
,
'lang'
);
$this
->
generateChildDefinitions
();
return
true
;
}
}
lib/Doctrine/Plugin.php
View file @
2174bc99
...
...
@@ -40,7 +40,7 @@ abstract class Doctrine_Plugin
'generateFiles'
=>
false
,
'table'
=>
false
,
'pluginTable'
=>
false
,
'children'
=>
array
()
,
);
'children'
=>
array
());
/**
* __get
...
...
@@ -112,6 +112,8 @@ abstract class Doctrine_Plugin
public
function
buildPluginDefinition
(
Doctrine_Table
$table
)
{
$this
->
initOptions
();
$this
->
_options
[
'table'
]
=
$table
;
$this
->
_options
[
'className'
]
=
str_replace
(
'%CLASS%'
,
...
...
@@ -122,32 +124,31 @@ abstract class Doctrine_Plugin
if
(
class_exists
(
$this
->
_options
[
'className'
]))
{
return
false
;
}
$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
;
}
public
function
generateChildDefinitions
()
abstract
public
function
buildDefinition
();
public
function
buildChildDefinitions
()
{
if
(
!
isset
(
$this
->
_options
[
'children'
]))
{
Doctrine
::
dump
(
debug_backtrace
());
throw
new
Doctrine_Plugin_Exception
(
"Unknown option 'children'."
);
}
foreach
(
$this
->
_options
[
'children'
]
as
$child
)
{
$this
->
_options
[
'pluginTable'
]
->
addTemplate
(
get_class
(
$child
),
$child
);
...
...
@@ -166,7 +167,7 @@ abstract class Doctrine_Plugin
* @param Doctrine_Table $table the table object that owns the plugin
* @return array an array of foreign key definitions
*/
public
function
generate
ForeignKeys
(
Doctrine_Table
$table
)
public
function
build
ForeignKeys
(
Doctrine_Table
$table
)
{
$fk
=
array
();
...
...
@@ -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
* 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
*/
public
function
generateRelation
(
Doctrine_Table
$table
,
array
$foreignKeys
)
public
function
buildRelation
(
)
{
$local
=
(
count
(
$foreignKeys
)
>
1
)
?
array_keys
(
$foreignKeys
)
:
key
(
$foreignKeys
);
$relation
=
array
(
$table
->
getComponentName
()
=>
array
(
'local'
=>
$local
,
'foreign'
=>
$table
->
getIdentifier
(),
$relation
=
array
(
$this
->
_options
[
'table'
]
->
getComponentName
()
=>
array
(
'local'
=>
$this
->
_options
[
'table'
]
->
getIdentifier
(),
'foreign'
=>
$this
->
_options
[
'table'
]
->
getIdentifier
(),
'onDelete'
=>
'CASCADE'
,
'onUpdate'
=>
'CASCADE'
));
...
...
@@ -211,15 +208,19 @@ abstract class Doctrine_Plugin
/**
* 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
* and values as column definitions
*
* @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
*/
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
();
if
(
$this
->
_options
[
'generateFiles'
])
{
...
...
lib/Doctrine/Record/Abstract.php
View file @
2174bc99
...
...
@@ -275,7 +275,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
/**
* actAs
* loads
a
given plugin
* loads
the
given plugin
*
* @param mixed $tpl
* @param array $options
...
...
lib/Doctrine/Search.php
View file @
2174bc99
...
...
@@ -40,15 +40,12 @@ class Doctrine_Search extends Doctrine_Plugin
'type'
=>
self
::
INDEX_TABLES
,
'className'
=>
'%CLASS%Index'
,
'generatePath'
=>
false
,
'
resource'
=>
null
,
'
table'
=>
null
,
'batchUpdates'
=>
false
,
'pluginTable'
=>
false
,
'fields'
=>
array
(),
'connection'
=>
null
);
protected
$_built
=
false
;
'connection'
=>
null
,
'children'
=>
array
());
/**
* __construct
*
...
...
@@ -71,7 +68,7 @@ class Doctrine_Search extends Doctrine_Plugin
/**
* search
*
* @param string $query
* @param string $query
* @return Doctrine_Collection The collection of search results
*/
public
function
search
(
$query
)
...
...
@@ -107,10 +104,10 @@ class Doctrine_Search extends Doctrine_Plugin
$fields
=
$this
->
getOption
(
'fields'
);
$class
=
$this
->
getOption
(
'className'
);
$name
=
$this
->
getOption
(
'
resourc
e'
)
->
getComponentName
();
$conn
=
$this
->
getOption
(
'
resourc
e'
)
->
getConnection
();
$identifier
=
$this
->
_options
[
'
resourc
e'
]
->
getIdentifier
();
$name
=
$this
->
getOption
(
'
tabl
e'
)
->
getComponentName
();
$conn
=
$this
->
getOption
(
'
tabl
e'
)
->
getConnection
();
$identifier
=
$this
->
_options
[
'
tabl
e'
]
->
getIdentifier
();
$q
=
Doctrine_Query
::
create
()
->
delete
()
->
from
(
$class
);
foreach
((
array
)
$identifier
as
$id
)
{
...
...
@@ -121,7 +118,7 @@ class Doctrine_Search extends Doctrine_Plugin
if
(
$this
->
_options
[
'batchUpdates'
]
===
true
)
{
$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
];
}
...
...
@@ -139,7 +136,7 @@ class Doctrine_Search extends Doctrine_Plugin
$index
->
keyword
=
$term
;
$index
->
position
=
$pos
;
$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
];
}
...
...
@@ -160,9 +157,9 @@ class Doctrine_Search extends Doctrine_Plugin
{
$this
->
buildDefinition
();
$conn
=
$this
->
_options
[
'
resourc
e'
]
->
getConnection
();
$tableName
=
$this
->
_options
[
'
resourc
e'
]
->
getTableName
();
$id
=
$this
->
_options
[
'
resourc
e'
]
->
getIdentifier
();
$conn
=
$this
->
_options
[
'
tabl
e'
]
->
getConnection
();
$tableName
=
$this
->
_options
[
'
tabl
e'
]
->
getTableName
();
$id
=
$this
->
_options
[
'
tabl
e'
]
->
getIdentifier
();
$query
=
'SELECT * FROM '
.
$conn
->
quoteIdentifier
(
$tableName
)
.
' WHERE '
.
$conn
->
quoteIdentifier
(
$id
)
...
...
@@ -188,7 +185,7 @@ class Doctrine_Search extends Doctrine_Plugin
{
$this
->
buildDefinition
();
$id
=
$this
->
_options
[
'
resourc
e'
]
->
getIdentifier
();
$id
=
$this
->
_options
[
'
tabl
e'
]
->
getIdentifier
();
$class
=
$this
->
_options
[
'className'
];
$fields
=
$this
->
_options
[
'fields'
];
$conn
=
$this
->
_options
[
'connection'
];
...
...
@@ -241,17 +238,12 @@ class Doctrine_Search extends Doctrine_Plugin
*/
public
function
buildDefinition
()
{
if
(
$this
->
_built
)
{
return
true
;
if
(
!
isset
(
$this
->
_options
[
'table'
]))
{
Doctrine
::
dump
(
debug_backtrace
());
throw
new
Doctrine_Plugin_Exception
(
"Unknown option 'table'."
);
}
$this
->
_built
=
true
;
$componentName
=
$this
->
_options
[
'resource'
]
->
getComponentName
();
// check for placeholders
if
(
strpos
(
$this
->
_options
[
'className'
],
'%'
)
!==
false
)
{
$this
->
_options
[
'className'
]
=
str_replace
(
'%CLASS%'
,
$componentName
,
$this
->
_options
[
'className'
]);
}
$componentName
=
$this
->
_options
[
'table'
]
->
getComponentName
();
$className
=
$this
->
getOption
(
'className'
);
...
...
@@ -271,20 +263,19 @@ class Doctrine_Search extends Doctrine_Plugin
'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
;
$relations
=
array
();
// only generate relations for database based searches
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'
]);
...
...
lib/Doctrine/Search/File.php
View file @
2174bc99
...
...
@@ -40,15 +40,13 @@ class Doctrine_Search_File extends Doctrine_Search
$table
=
new
Doctrine_Table
(
'File'
,
Doctrine_Manager
::
connection
());
$table
->
setColumn
(
'url'
,
'string'
,
255
,
array
(
'primary'
=>
true
));
$this
->
_options
[
'resource'
]
=
$table
;
}
if
(
empty
(
$this
->
_options
[
'fields'
]))
{
$this
->
_options
[
'fields'
]
=
array
(
'url'
,
'content'
);
}
$this
->
build
Definition
(
);
$this
->
build
PluginDefinition
(
$table
);
}
public
function
indexDirectory
(
$dir
)
...
...
@@ -58,7 +56,7 @@ class Doctrine_Search_File extends Doctrine_Search
foreach
(
$it
as
$file
)
{
if
(
strpos
(
$file
,
DIRECTORY_SEPARATOR
.
'.svn'
)
!==
false
)
{
continue
;
continue
;
}
$this
->
updateIndex
(
array
(
'url'
=>
$file
->
getPathName
(),
...
...
lib/Doctrine/Template/Searchable.php
View file @
2174bc99
...
...
@@ -45,17 +45,10 @@ class Doctrine_Template_Searchable extends Doctrine_Template
public
function
setUp
()
{
$id
=
$this
->
_table
->
getIdentifier
();
$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
->
setOption
(
'resource'
,
$this
->
_table
);
$this
->
_plugin
->
buildDefinition
();
$this
->
_plugin
->
buildPluginDefinition
(
$this
->
_table
);
$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
));
}
...
...
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