From 005058277c5a2afa85fc1d59f97814f62409a8e8 Mon Sep 17 00:00:00 2001 From: Vasily Komrakov Date: Wed, 3 Feb 2016 22:26:53 +0300 Subject: [PATCH] #6 Add service provider for SphinxSearch (SphinxQL) --- common.php | 7 ++ composer.json | 3 +- composer.lock | 69 ++++++++++++++++++- library/config.php | 17 +++-- .../SphinxServiceProvider.php | 41 +++++++++++ 5 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 src/ServiceProviders/SphinxServiceProvider.php diff --git a/common.php b/common.php index b7787ee3c..217b79ba8 100644 --- a/common.php +++ b/common.php @@ -39,6 +39,10 @@ $di->register(new \TorrentPier\ServiceProviders\DbServiceProvider, [ 'config.db' => $di->config->db->toArray() ]); +$di->register(new \TorrentPier\ServiceProviders\SphinxServiceProvider, [ + 'config.sphinx' => $di->config->sphinx->toArray() +]); + $bb_cfg = $di->config->toArray(); $page_cfg = $di->config->page->toArray(); $tr_cfg = $di->config->tracker->toArray(); @@ -107,6 +111,9 @@ $DBS = new DBS([ 'db_alias' => $bb_cfg['db_alias'] ]); +/** + * @deprecated + */ function DB ($db_alias = 'db') { global $DBS; diff --git a/composer.json b/composer.json index 9d8be0b5c..358de9481 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ "zendframework/zend-mail": "^2.5", "zendframework/zend-session": "^2.5", "zendframework/zend-version": "^2.5", - "pimple/pimple": "^3.0" + "pimple/pimple": "^3.0", + "ripaclub/sphinxsearch": "^0.8.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index fe5f6c830..4c9c2f4dd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "e8a2d6011dd844e4be12323e4375f772", - "content-hash": "dc3c90480a0003746504276bfac71364", + "hash": "c254b55c3197ea827eb5e4a75b49e6a6", + "content-hash": "de4bc86e5ded359c5716096e4c795fc0", "packages": [ { "name": "container-interop/container-interop", @@ -125,6 +125,71 @@ ], "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", "version": "v1.0.0", diff --git a/library/config.php b/library/config.php index b3b199797..88bbf9312 100644 --- a/library/config.php +++ b/library/config.php @@ -61,7 +61,7 @@ if (!defined('BB_ROOT')) die(basename(__FILE__)); -$domain_name = 'torrentpier.me'; +$domain_name = 'tor.dev'; $config = [ // Increase number after changing js or css @@ -76,10 +76,19 @@ $config = [ // Database 'db' => [ 'driver' => 'Pdo_Mysql', - 'hostname' => 'localhost', + 'hostname' => '127.0.0.1', 'database' => 'tp_220', - 'username' => 'root', - 'password' => 'dev', + 'username' => 'user', + 'password' => 'pass', + 'charset' => 'utf8' + ], + + 'sphinx' => [ + 'driver' => 'Pdo_Mysql', + 'hostname' => '127.0.0.1', + 'username' => 'user', + 'password' => 'pass', + 'port' => 9306, 'charset' => 'utf8' ], diff --git a/src/ServiceProviders/SphinxServiceProvider.php b/src/ServiceProviders/SphinxServiceProvider.php new file mode 100644 index 000000000..216d2a011 --- /dev/null +++ b/src/ServiceProviders/SphinxServiceProvider.php @@ -0,0 +1,41 @@ +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; + }; + } +} \ No newline at end of file