Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
535f9075
Commit
535f9075
authored
Sep 10, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated plugin example for new eventdispatcher
parent
43dae657
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
15 deletions
+26
-15
examples/5.3.1-plugin-event-hooks.php
examples/5.3.1-plugin-event-hooks.php
+26
-15
No files found.
examples/5.3.1-plugin-event-hooks.php
View file @
535f9075
<?php
<?php
require
(
__DIR__
.
'/init.php'
);
require
(
__DIR__
.
'/init.php'
);
use
Solarium\Core\Event\Events
;
// this very simple plugin shows a timing for each event and display some request debug info
// this very simple plugin shows a timing for each event and display some request debug info
class
basicDebug
extends
Solarium\Core\Plugin\Plugin
class
basicDebug
extends
Solarium\Core\Plugin\Plugin
...
@@ -9,16 +9,27 @@ class basicDebug extends Solarium\Core\Plugin\Plugin
...
@@ -9,16 +9,27 @@ class basicDebug extends Solarium\Core\Plugin\Plugin
protected
$start
;
protected
$start
;
protected
$output
=
array
();
protected
$output
=
array
();
p
ublic
function
initPlugin
(
$client
,
$options
)
p
rotected
function
initPluginType
(
)
{
{
$this
->
start
=
microtime
(
true
);
$this
->
start
=
microtime
(
true
);
$dispatcher
=
$this
->
client
->
getEventDispatcher
();
$dispatcher
->
addListener
(
Events
::
PRE_CREATE_REQUEST
,
array
(
$this
,
'preCreateRequest'
));
$dispatcher
->
addListener
(
Events
::
POST_CREATE_REQUEST
,
array
(
$this
,
'postCreateRequest'
));
$dispatcher
->
addListener
(
Events
::
PRE_EXECUTE_REQUEST
,
array
(
$this
,
'preExecuteRequest'
));
$dispatcher
->
addListener
(
Events
::
POST_EXECUTE_REQUEST
,
array
(
$this
,
'postExecuteRequest'
));
$dispatcher
->
addListener
(
Events
::
PRE_CREATE_RESULT
,
array
(
$this
,
'preCreateResult'
));
$dispatcher
->
addListener
(
Events
::
POST_CREATE_RESULT
,
array
(
$this
,
'postCreateResult'
));
$dispatcher
->
addListener
(
Events
::
PRE_EXECUTE
,
array
(
$this
,
'preExecute'
));
$dispatcher
->
addListener
(
Events
::
POST_EXECUTE
,
array
(
$this
,
'postExecute'
));
$dispatcher
->
addListener
(
Events
::
PRE_CREATE_QUERY
,
array
(
$this
,
'preCreateQuery'
));
$dispatcher
->
addListener
(
Events
::
POST_CREATE_QUERY
,
array
(
$this
,
'postCreateQuery'
));
}
}
protected
function
timer
(
$event
)
protected
function
timer
(
$event
)
{
{
$time
=
round
(
microtime
(
true
)
-
$this
->
start
,
5
);
$time
=
round
(
microtime
(
true
)
-
$this
->
start
,
5
);
$this
->
output
[]
=
'['
.
$time
.
'] '
.
$event
;
$this
->
output
[]
=
'['
.
$time
.
'] '
.
$event
;
}
}
public
function
display
()
public
function
display
()
...
@@ -26,59 +37,59 @@ class basicDebug extends Solarium\Core\Plugin\Plugin
...
@@ -26,59 +37,59 @@ class basicDebug extends Solarium\Core\Plugin\Plugin
echo
implode
(
'<br/>'
,
$this
->
output
);
echo
implode
(
'<br/>'
,
$this
->
output
);
}
}
public
function
preCreateRequest
(
$query
)
public
function
preCreateRequest
()
{
{
$this
->
timer
(
'preCreateRequest'
);
$this
->
timer
(
'preCreateRequest'
);
}
}
public
function
postCreateRequest
(
$query
,
$request
)
public
function
postCreateRequest
()
{
{
$this
->
timer
(
'postCreateRequest'
);
$this
->
timer
(
'postCreateRequest'
);
}
}
// This method uses the aviable param(s) (see plugin abstract class)
// This method uses the aviable param(s) (see plugin abstract class)
// You can access or modify data this way
// You can access or modify data this way
public
function
preExecuteRequest
(
$
reques
t
)
public
function
preExecuteRequest
(
$
even
t
)
{
{
$this
->
timer
(
'preExecuteRequest'
);
$this
->
timer
(
'preExecuteRequest'
);
// this dummy param will be visible in the debug output but will also be used in the actual Solr request
// this dummy param will be visible in the debug output but will also be used in the actual Solr request
$
request
->
addParam
(
'dummyparam'
,
'dummyvalue'
);
$
event
->
getRequest
()
->
addParam
(
'dummyparam'
,
'dummyvalue'
);
$this
->
output
[]
=
'Request URI: '
.
$
request
->
getUri
();
$this
->
output
[]
=
'Request URI: '
.
$
event
->
getRequest
()
->
getUri
();
}
}
public
function
postExecuteRequest
(
$request
,
$response
)
public
function
postExecuteRequest
()
{
{
$this
->
timer
(
'postExecuteRequest'
);
$this
->
timer
(
'postExecuteRequest'
);
}
}
public
function
preCreateResult
(
$query
,
$response
)
public
function
preCreateResult
()
{
{
$this
->
timer
(
'preCreateResult'
);
$this
->
timer
(
'preCreateResult'
);
}
}
public
function
postCreateResult
(
$query
,
$response
,
$result
)
public
function
postCreateResult
()
{
{
$this
->
timer
(
'postCreateResult'
);
$this
->
timer
(
'postCreateResult'
);
}
}
public
function
preExecute
(
$query
)
public
function
preExecute
()
{
{
$this
->
timer
(
'preExecute'
);
$this
->
timer
(
'preExecute'
);
}
}
public
function
postExecute
(
$query
,
$result
)
public
function
postExecute
()
{
{
$this
->
timer
(
'postExecute'
);
$this
->
timer
(
'postExecute'
);
}
}
public
function
preCreateQuery
(
$type
,
$options
)
public
function
preCreateQuery
()
{
{
$this
->
timer
(
'preCreateResult'
);
$this
->
timer
(
'preCreateResult'
);
}
}
public
function
postCreateQuery
(
$type
,
$options
,
$query
)
public
function
postCreateQuery
()
{
{
$this
->
timer
(
'postCreateResult'
);
$this
->
timer
(
'postCreateResult'
);
}
}
...
...
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