-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Damian Mooyman
committed
Feb 16, 2018
0 parents
commit 9850a12
Showing
5 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
Name: proxydb-mysql | ||
After: '#databaseconnectors' | ||
--- | ||
SilverStripe\Core\Injector\Injector: | ||
MySQLDatabase: | ||
factory: TractorCow\SilverStripeProxyDB\ProxyDBFactory | ||
MySQLPDODatabase: | ||
factory: TractorCow\SilverStripeProxyDB\ProxyDBFactory | ||
--- | ||
Name: proxydb-postgresql | ||
After: '#postgresqlconnectors' | ||
--- | ||
SilverStripe\Core\Injector\Injector: | ||
PostgrePDODatabase: | ||
factory: TractorCow\SilverStripeProxyDB\ProxyDBFactory | ||
PostgreSQLDatabase: | ||
factory: TractorCow\SilverStripeProxyDB\ProxyDBFactory | ||
|
||
--- | ||
Name: proxydb-sqlite | ||
After: '#sqlite3connectors' | ||
--- | ||
SilverStripe\Core\Injector\Injector: | ||
SQLite3PDODatabase: | ||
factory: TractorCow\SilverStripeProxyDB\ProxyDBFactory | ||
SQLite3Database: | ||
factory: TractorCow\SilverStripeProxyDB\ProxyDBFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "tractorcow/silverstripe-proxy-db", | ||
"type": "silverstripe-vendormodule", | ||
"license": "BSD-3-Clause", | ||
"keywords": [ | ||
"silverstripe", | ||
"db", | ||
"proxy" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Damian Mooyman", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"silverstripe/framework": "^4@dev", | ||
"silverstripe/vendor-plugin": "^1.0", | ||
"tractorcow/classproxy": "^0.1.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"TractorCow\\SilverStripeProxyDB\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Database proxy | ||
|
||
Ok, so you want to proxy the database. | ||
|
||
Install this module, and decorate the factory with code you want to extend | ||
|
||
``` | ||
--- | ||
Name: myproxydb | ||
After: '#proxydb' | ||
--- | ||
TractorCow\SilverStripeProxyDB\ProxyDBFactory: | ||
extensions: | ||
- ProxyDBExtension | ||
``` | ||
|
||
Then in your code you can do this | ||
|
||
``` | ||
<?php | ||
use SilverStripe\Core\Extension; | ||
use TractorCow\ClassProxy\Generators\ProxyGenerator; | ||
class ProxyDBExtension extends Extension | ||
{ | ||
public function updateProxy(ProxyGenerator &$proxy) | ||
{ | ||
$proxy = $proxy->addMethod('manipulate', function ($args, $next) { | ||
SearchManipulator::manipulate($args[0]); | ||
return $next(...$args); | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
You can chain methods; All addMethod() calls on the same method name will | ||
form a set of middleware. First methods registered are executed first. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace TractorCow\SilverStripeProxyDB; | ||
|
||
use SilverStripe\Core\Extensible; | ||
use SilverStripe\Core\Injector\Factory; | ||
use TractorCow\ClassProxy\ProxyFactory; | ||
|
||
class ProxyDBFactory implements Factory | ||
{ | ||
use Extensible; | ||
|
||
/** | ||
* Creates a new service instance. | ||
* | ||
* @param string $service The class name of the service. | ||
* @param array $params The constructor parameters. | ||
* @return object The created service instances. | ||
*/ | ||
public function create($service, array $params = array()) | ||
{ | ||
$proxy = ProxyFactory::create($service); | ||
$this->extend('updateProxy', $proxy); | ||
$instance = $proxy->instance($params); | ||
$this->extend('updateInstance', $instance); | ||
return $instance; | ||
} | ||
} |