Passed
Pull Request — master (#208)
by
unknown
02:17
created

ProxyDBExtension::updateProxy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\FullTextSearch\Search\Extensions;
4
5
use SilverStripe\Core\Extension;
6
use TractorCow\ClassProxy\Generators\ProxyGenerator;
7
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
8
9
/**
10
 * Class ProxyDBExtension
11
 * @package SilverStripe\FullTextSearch\Search\Extensions
12
 *
13
 * This database connector proxy will allow {@link SearchUpdater::handle_manipulation} to monitor database schema
14
 * changes that may need to be propagated through to search indexes.
15
 *
16
 */
17
class ProxyDBExtension extends Extension
18
{
19
    /**
20
     * @param ProxyGenerator $proxy
21
     *
22
     * Ensure the search index is kept up to date by monitoring SilverStripe database manipulations
23
     */
24
    public function updateProxy(ProxyGenerator &$proxy)
25
    {
26
        $proxy = $proxy->addMethod('manipulate', function ($args, $next) {
27
            $manipulation = $args[0];
28
            SearchUpdater::handle_manipulation($manipulation);
29
            return $next(...$args);
30
        });
31
    }
32
}
33