mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 22:33:55 -07:00
#6 Add service provider for SphinxSearch (SphinxQL)
This commit is contained in:
parent
89f5db1c50
commit
005058277c
5 changed files with 130 additions and 7 deletions
|
@ -39,6 +39,10 @@ $di->register(new \TorrentPier\ServiceProviders\DbServiceProvider, [
|
||||||
'config.db' => $di->config->db->toArray()
|
'config.db' => $di->config->db->toArray()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$di->register(new \TorrentPier\ServiceProviders\SphinxServiceProvider, [
|
||||||
|
'config.sphinx' => $di->config->sphinx->toArray()
|
||||||
|
]);
|
||||||
|
|
||||||
$bb_cfg = $di->config->toArray();
|
$bb_cfg = $di->config->toArray();
|
||||||
$page_cfg = $di->config->page->toArray();
|
$page_cfg = $di->config->page->toArray();
|
||||||
$tr_cfg = $di->config->tracker->toArray();
|
$tr_cfg = $di->config->tracker->toArray();
|
||||||
|
@ -107,6 +111,9 @@ $DBS = new DBS([
|
||||||
'db_alias' => $bb_cfg['db_alias']
|
'db_alias' => $bb_cfg['db_alias']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
function DB ($db_alias = 'db')
|
function DB ($db_alias = 'db')
|
||||||
{
|
{
|
||||||
global $DBS;
|
global $DBS;
|
||||||
|
|
|
@ -39,7 +39,8 @@
|
||||||
"zendframework/zend-mail": "^2.5",
|
"zendframework/zend-mail": "^2.5",
|
||||||
"zendframework/zend-session": "^2.5",
|
"zendframework/zend-session": "^2.5",
|
||||||
"zendframework/zend-version": "^2.5",
|
"zendframework/zend-version": "^2.5",
|
||||||
"pimple/pimple": "^3.0"
|
"pimple/pimple": "^3.0",
|
||||||
|
"ripaclub/sphinxsearch": "^0.8.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
69
composer.lock
generated
69
composer.lock
generated
|
@ -4,8 +4,8 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"hash": "e8a2d6011dd844e4be12323e4375f772",
|
"hash": "c254b55c3197ea827eb5e4a75b49e6a6",
|
||||||
"content-hash": "dc3c90480a0003746504276bfac71364",
|
"content-hash": "de4bc86e5ded359c5716096e4c795fc0",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "container-interop/container-interop",
|
"name": "container-interop/container-interop",
|
||||||
|
@ -125,6 +125,71 @@
|
||||||
],
|
],
|
||||||
"time": "2015-09-11 15:10:35"
|
"time": "2015-09-11 15:10:35"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "ripaclub/sphinxsearch",
|
||||||
|
"version": "0.8.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/ripaclub/sphinxsearch.git",
|
||||||
|
"reference": "f9d7550b6250519785e4db15c32b23865f2d49f3"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/ripaclub/sphinxsearch/zipball/f9d7550b6250519785e4db15c32b23865f2d49f3",
|
||||||
|
"reference": "f9d7550b6250519785e4db15c32b23865f2d49f3",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.5",
|
||||||
|
"zendframework/zend-db": "~2.4",
|
||||||
|
"zendframework/zend-servicemanager": "~2.4",
|
||||||
|
"zendframework/zend-stdlib": "~2.4"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "~4.3",
|
||||||
|
"satooshi/php-coveralls": "dev-master"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ripaclub/zf2-sphinxsearch": "ZF2 integration module for SphinxSearch library",
|
||||||
|
"ripaclub/zf2-sphinxsearch-tool": "Utility that provides a set of tools to create and handle Sphinx Search configs and sources"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"SphinxSearch\\": "library",
|
||||||
|
"SphinxSearchTest\\": "tests"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"BSD-2-Clause"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Leonardo Grasso",
|
||||||
|
"email": "me@leonardograsso.com",
|
||||||
|
"homepage": "http://github.com/leogr"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Leo Di Donato",
|
||||||
|
"email": "leodidonato@gmail.com",
|
||||||
|
"homepage": "http://github.com/leodido"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Sphinx Search library provides SphinxQL indexing and searching features",
|
||||||
|
"homepage": "https://github.com/ripaclub/sphinxsearch",
|
||||||
|
"keywords": [
|
||||||
|
"indexing",
|
||||||
|
"pdo",
|
||||||
|
"query builder",
|
||||||
|
"search",
|
||||||
|
"search engine",
|
||||||
|
"sphinx",
|
||||||
|
"sphinxql",
|
||||||
|
"zf2"
|
||||||
|
],
|
||||||
|
"time": "2015-06-22 18:12:29"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "rych/bencode",
|
"name": "rych/bencode",
|
||||||
"version": "v1.0.0",
|
"version": "v1.0.0",
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
|
|
||||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||||
|
|
||||||
$domain_name = 'torrentpier.me';
|
$domain_name = 'tor.dev';
|
||||||
|
|
||||||
$config = [
|
$config = [
|
||||||
// Increase number after changing js or css
|
// Increase number after changing js or css
|
||||||
|
@ -76,10 +76,19 @@ $config = [
|
||||||
// Database
|
// Database
|
||||||
'db' => [
|
'db' => [
|
||||||
'driver' => 'Pdo_Mysql',
|
'driver' => 'Pdo_Mysql',
|
||||||
'hostname' => 'localhost',
|
'hostname' => '127.0.0.1',
|
||||||
'database' => 'tp_220',
|
'database' => 'tp_220',
|
||||||
'username' => 'root',
|
'username' => 'user',
|
||||||
'password' => 'dev',
|
'password' => 'pass',
|
||||||
|
'charset' => 'utf8'
|
||||||
|
],
|
||||||
|
|
||||||
|
'sphinx' => [
|
||||||
|
'driver' => 'Pdo_Mysql',
|
||||||
|
'hostname' => '127.0.0.1',
|
||||||
|
'username' => 'user',
|
||||||
|
'password' => 'pass',
|
||||||
|
'port' => 9306,
|
||||||
'charset' => 'utf8'
|
'charset' => 'utf8'
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
41
src/ServiceProviders/SphinxServiceProvider.php
Normal file
41
src/ServiceProviders/SphinxServiceProvider.php
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TorrentPier\ServiceProviders;
|
||||||
|
|
||||||
|
use Pimple\Container;
|
||||||
|
use Pimple\ServiceProviderInterface;
|
||||||
|
use SphinxSearch\Db\Adapter\Driver\Pdo\Statement;
|
||||||
|
use SphinxSearch\Db\Adapter\Exception\UnsupportedDriverException;
|
||||||
|
use SphinxSearch\Db\Adapter\Platform\SphinxQL;
|
||||||
|
use Zend\Db\Adapter\Adapter;
|
||||||
|
use Zend\Db\Adapter\Driver\Mysqli\Mysqli;
|
||||||
|
use Zend\Db\Adapter\Driver\Pdo\Pdo;
|
||||||
|
|
||||||
|
class SphinxServiceProvider implements ServiceProviderInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function register(Container $container)
|
||||||
|
{
|
||||||
|
$container['sphinx'] = function($container) {
|
||||||
|
$platform = new SphinxQL();
|
||||||
|
$adapter = new Adapter($container['config.sphinx']);
|
||||||
|
|
||||||
|
$driver = $adapter->getDriver();
|
||||||
|
// Check driver
|
||||||
|
if ($driver instanceof Pdo && $driver->getDatabasePlatformName(Pdo::NAME_FORMAT_CAMELCASE) == 'Mysql' ) {
|
||||||
|
$driver->registerStatementPrototype(new Statement());
|
||||||
|
} elseif (!$driver instanceof Mysqli) {
|
||||||
|
$class = get_class($driver);
|
||||||
|
throw new UnsupportedDriverException(
|
||||||
|
$class . ' not supported. Use Zend\Db\Adapter\Driver\Pdo\Pdo or Zend\Db\Adapter\Driver\Mysqli\Mysqli'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$platform->setDriver($adapter->getDriver());
|
||||||
|
unset($container['config.sphinx']);
|
||||||
|
return $adapter;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue