mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-09 01:27:20 +08:00
Sphinx extensions skeleton created.
This commit is contained in:
32
extensions/sphinx/LICENSE.md
Normal file
32
extensions/sphinx/LICENSE.md
Normal file
@ -0,0 +1,32 @@
|
||||
The Yii framework is free software. It is released under the terms of
|
||||
the following BSD License.
|
||||
|
||||
Copyright © 2008-2013 by Yii Software LLC (http://www.yiisoft.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Yii Software LLC nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
42
extensions/sphinx/README.md
Normal file
42
extensions/sphinx/README.md
Normal file
@ -0,0 +1,42 @@
|
||||
Yii 2.0 Public Preview - Sphinx Extension
|
||||
=========================================
|
||||
|
||||
Thank you for choosing Yii - a high-performance component-based PHP framework.
|
||||
|
||||
If you are looking for a production-ready PHP framework, please use
|
||||
[Yii v1.1](https://github.com/yiisoft/yii).
|
||||
|
||||
Yii 2.0 is still under heavy development. We may make significant changes
|
||||
without prior notices. **Yii 2.0 is not ready for production use yet.**
|
||||
|
||||
[](http://travis-ci.org/yiisoft/yii2)
|
||||
|
||||
This is the yii2-sphinx extension.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
|
||||
|
||||
Either run
|
||||
```
|
||||
php composer.phar require yiisoft/yii2-sphinx "*"
|
||||
```
|
||||
|
||||
or add
|
||||
```
|
||||
"yiisoft/yii2-sphinx": "*"
|
||||
```
|
||||
to the require section of your composer.json.
|
||||
|
||||
|
||||
*Note: You might have to run `php composer.phar selfupdate`*
|
||||
|
||||
|
||||
Usage & Documentation
|
||||
---------------------
|
||||
|
||||
This extension adds [Sphinx](http://sphinxsearch.com/docs) full text search engine extension for the Yii framework.
|
||||
This extension interact with Sphinx search daemon using MySQL protocol and [SphinxQL](http://sphinxsearch.com/docs/current.html#sphinxql) query language.
|
||||
|
||||
27
extensions/sphinx/composer.json
Normal file
27
extensions/sphinx/composer.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "yiisoft/yii2-sphinx",
|
||||
"description": "Sphinx full text search engine extension for the Yii framework",
|
||||
"keywords": ["yii", "sphinx", "search", "fulltext"],
|
||||
"type": "yii2-extension",
|
||||
"license": "BSD-3-Clause",
|
||||
"support": {
|
||||
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
|
||||
"forum": "http://www.yiiframework.com/forum/",
|
||||
"wiki": "http://www.yiiframework.com/wiki/",
|
||||
"irc": "irc://irc.freenode.net/yii",
|
||||
"source": "https://github.com/yiisoft/yii2"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Paul Klimov",
|
||||
"email": "klimov.paul@gmail.com"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"yiisoft/yii2": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "yii\\sphinx\\": "" }
|
||||
}
|
||||
}
|
||||
19
extensions/sphinx/yii/sphinx/Connection.php
Normal file
19
extensions/sphinx/yii/sphinx/Connection.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace yii\sphinx;
|
||||
|
||||
/**
|
||||
* Class Connection
|
||||
*
|
||||
* @author Paul Klimov <klimov.paul@gmail.com>
|
||||
* @since 2.0
|
||||
*/
|
||||
class Connection extends \yii\db\Connection
|
||||
{
|
||||
//
|
||||
}
|
||||
42
tests/unit/extensions/sphinx/ConnectionTest.php
Normal file
42
tests/unit/extensions/sphinx/ConnectionTest.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace yiiunit\extensions\sphinx;
|
||||
|
||||
use yii\sphinx\Connection;
|
||||
|
||||
/**
|
||||
* @group sphinx
|
||||
*/
|
||||
class ConnectionTest extends SphinxTestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$connection = $this->getConnection(false);
|
||||
$params = $this->sphinxConfig;
|
||||
|
||||
$this->assertEquals($params['dsn'], $connection->dsn);
|
||||
$this->assertEquals($params['username'], $connection->username);
|
||||
$this->assertEquals($params['password'], $connection->password);
|
||||
}
|
||||
|
||||
public function testOpenClose()
|
||||
{
|
||||
$connection = $this->getConnection(false, false);
|
||||
|
||||
$this->assertFalse($connection->isActive);
|
||||
$this->assertEquals(null, $connection->pdo);
|
||||
|
||||
$connection->open();
|
||||
$this->assertTrue($connection->isActive);
|
||||
$this->assertTrue($connection->pdo instanceof \PDO);
|
||||
|
||||
$connection->close();
|
||||
$this->assertFalse($connection->isActive);
|
||||
$this->assertEquals(null, $connection->pdo);
|
||||
|
||||
$connection = new Connection;
|
||||
$connection->dsn = 'unknown::memory:';
|
||||
$this->setExpectedException('yii\db\Exception');
|
||||
$connection->open();
|
||||
}
|
||||
}
|
||||
101
tests/unit/extensions/sphinx/SphinxTestCase.php
Normal file
101
tests/unit/extensions/sphinx/SphinxTestCase.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace yiiunit\extensions\sphinx;
|
||||
|
||||
use yii\helpers\FileHelper;
|
||||
use yii\sphinx\Connection;
|
||||
use Yii;
|
||||
use yiiunit\TestCase as TestCase;
|
||||
|
||||
/**
|
||||
* Base class for the Sphinx test cases.
|
||||
*/
|
||||
class SphinxTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var array Sphinx connection configuration.
|
||||
*/
|
||||
protected $sphinxConfig = [
|
||||
'dsn' => 'mysql:host=127.0.0.1;port=9306;',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
];
|
||||
/**
|
||||
* @var Connection
|
||||
*/
|
||||
protected $sphinx;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
static::loadClassMap();
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
//$this->sphinxConfig = $this->getParam('sphinx');
|
||||
if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) {
|
||||
$this->markTestSkipped('pdo and pdo_mysql extension are required.');
|
||||
}
|
||||
$this->mockApplication();
|
||||
static::loadClassMap();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if ($this->sphinx) {
|
||||
$this->sphinx->close();
|
||||
}
|
||||
$this->destroyApplication();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds sphinx extension files to [[Yii::$classPath]],
|
||||
* avoiding the necessity of usage Composer autoloader.
|
||||
*/
|
||||
protected static function loadClassMap()
|
||||
{
|
||||
$baseNameSpace = 'yii/sphinx';
|
||||
$basePath = realpath(__DIR__. '/../../../../extensions/sphinx/yii/sphinx');
|
||||
$files = FileHelper::findFiles($basePath);
|
||||
foreach ($files as $file) {
|
||||
$classRelativePath = str_replace($basePath, '', $file);
|
||||
$classFullName = str_replace(['/', '.php'], ['\\', ''], $baseNameSpace . $classRelativePath);
|
||||
Yii::$classMap[$classFullName] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $reset whether to clean up the test database
|
||||
* @param bool $open whether to open and populate test database
|
||||
* @return \yii\db\Connection
|
||||
*/
|
||||
public function getConnection($reset = true, $open = true)
|
||||
{
|
||||
if (!$reset && $this->sphinx) {
|
||||
return $this->sphinx;
|
||||
}
|
||||
$db = new \yii\db\Connection;
|
||||
$db->dsn = $this->sphinxConfig['dsn'];
|
||||
if (isset($this->sphinxConfig['username'])) {
|
||||
$db->username = $this->sphinxConfig['username'];
|
||||
$db->password = $this->sphinxConfig['password'];
|
||||
}
|
||||
if (isset($this->sphinxConfig['attributes'])) {
|
||||
$db->attributes = $this->sphinxConfig['attributes'];
|
||||
}
|
||||
if ($open) {
|
||||
$db->open();
|
||||
if (!empty($this->sphinxConfig['fixture'])) {
|
||||
$lines = explode(';', file_get_contents($this->sphinxConfig['fixture']));
|
||||
foreach ($lines as $line) {
|
||||
if (trim($line) !== '') {
|
||||
$db->pdo->exec($line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->sphinx = $db;
|
||||
return $db;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user