Skip to content

Commit a801ec9

Browse files
committed
initial import
0 parents  commit a801ec9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+5292
-0
lines changed

COPYING

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright 2011 Bas de Nooijer. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without modification, are
4+
permitted provided that the following conditions are met:
5+
6+
1. Redistributions of source code must retain the above copyright notice, this list of
7+
conditions and the following disclaimer.
8+
9+
2. Redistributions in binary form must reproduce the above copyright notice, this list
10+
of conditions and the following disclaimer in the documentation and/or other materials
11+
provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
15+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
16+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
21+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22+
23+
The views and conclusions contained in the software and documentation are those of the
24+
authors and should not be interpreted as representing official policies, either expressed
25+
or implied, of the copyright holder.

README

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Solarium is a PHP Solr client that not only facilitates Solr communication but
2+
also tries to accurately model Solr concepts.
3+
4+
For Docs, License, Issues, and pre-packed downloads, see:
5+
http://github.com/basdenooijer/solarium
6+
7+
Contributors:
8+
http://github.com/basdenooijer/solarium/contributors

build.xml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<project name="solarium" default="build" basedir=".">
2+
<target name="clean">
3+
<!-- Clean up -->
4+
<delete dir="build"/>
5+
6+
<!-- Create build directories -->
7+
<mkdir dir="${basedir}/build/api"/>
8+
<mkdir dir="${basedir}/build/code-browser"/>
9+
<mkdir dir="${basedir}/build/coverage"/>
10+
<mkdir dir="${basedir}/build/logs"/>
11+
<mkdir dir="${basedir}/build/pdepend"/>
12+
</target>
13+
14+
<!-- Run unit tests and generate junit.xml and clover.xml
15+
(This is done in the phpunit.xml.dist,
16+
you could also write the switches here)
17+
-->
18+
<target name="phpunit">
19+
<exec executable="phpunit" failonerror="true" />
20+
</target>
21+
22+
<!-- Run pdepend, phpmd, phpcpd, and phpcs in parallel -->
23+
<target name="parallelTasks">
24+
<parallel>
25+
<antcall target="pdepend"/>
26+
<antcall target="phpmd"/>
27+
<antcall target="phpcpd"/>
28+
<antcall target="phpcs"/>
29+
<antcall target="phpdoc"/>
30+
</parallel>
31+
</target>
32+
33+
<!-- Generate jdepend.xml and software metrics charts -->
34+
<target name="pdepend">
35+
<exec executable="pdepend">
36+
<arg line="--jdepend-xml=${basedir}/build/logs/jdepend.xml libraru" />
37+
</exec>
38+
</target>
39+
40+
<!-- Generate pmd.xml -->
41+
<target name="phpmd">
42+
<exec executable="phpmd">
43+
<arg line="library xml codesize,unusedcode --reportfile ${basedir}/build/logs/pmd.xml" />
44+
</exec>
45+
</target>
46+
47+
<!-- Generate pmd-cpd.xml -->
48+
<target name="phpcpd">
49+
<exec executable="phpcpd">
50+
<arg line="--log-pmd ${basedir}/build/logs/pmd-cpd.xml library" />
51+
</exec>
52+
</target>
53+
54+
<!-- Generate checkstyle.xml -->
55+
<target name="phpcs">
56+
<exec executable="phpcs" output="/dev/null">
57+
<arg line="--report=checkstyle --report-file=${basedir}/build/logs/checkstyle.xml --standard=Zend library" />
58+
</exec>
59+
</target>
60+
61+
<!-- Generate API documentation -->
62+
<target name="phpdoc">
63+
<exec executable="phpdoc">
64+
<arg line="-d library -t build/api" />
65+
</exec>
66+
</target>
67+
68+
<target name="phpcb">
69+
<exec executable="phpcb">
70+
<arg line="--log ${basedir}/build/logs --source ${basedir}/library --output ${basedir}/build/code-browser" />
71+
</exec>
72+
</target>
73+
74+
<target name="build" depends="clean,phpunit,parallelTasks,phpcb"/>
75+
</project>

library/Solarium/Client.php

+242
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
<?php
2+
/**
3+
* Copyright 2011 Bas de Nooijer. All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
*
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this listof conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
16+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25+
* POSSIBILITY OF SUCH DAMAGE.
26+
*
27+
* The views and conclusions contained in the software and documentation are
28+
* those of the authors and should not be interpreted as representing official
29+
* policies, either expressed or implied, of the copyright holder.
30+
*/
31+
32+
/**
33+
* The Solarium Client is the main accesspoint for interaction with Solr
34+
*/
35+
class Solarium_Client extends Solarium_Configurable
36+
{
37+
38+
/**
39+
* Default options
40+
*
41+
* @var array
42+
*/
43+
protected $_options = array(
44+
'host' => '127.0.0.1',
45+
'port' => 80,
46+
'path' => '/solr',
47+
'core' => null,
48+
'adapter' => 'Solarium_Client_Adapter_Stream',
49+
);
50+
51+
/**
52+
* Adapter instance
53+
*
54+
* @var Solarium_Client_Adapter
55+
*/
56+
protected $_adapter;
57+
58+
/**
59+
* Init options array. Some options might need some extra checks or setup
60+
* work.
61+
*
62+
* @return void
63+
*/
64+
protected function _init()
65+
{
66+
foreach ($this->_options AS $name => $value) {
67+
switch ($name) {
68+
case 'path':
69+
$this->setPath($value);
70+
break;
71+
}
72+
}
73+
}
74+
75+
/**
76+
* Set an option
77+
*
78+
* @param string $name
79+
* @param mixed $value
80+
* @return void
81+
*/
82+
protected function _setOption($name, $value)
83+
{
84+
parent::_setOption($name, $value);
85+
86+
if (null !== $this->_adapter) {
87+
$this->_adapter->setOptions($this->_options);
88+
}
89+
90+
return $this;
91+
}
92+
93+
/**
94+
* Set host option
95+
*
96+
* @param string $host
97+
* @return Solarium_Client Provides fluent interface
98+
*/
99+
public function setHost($host)
100+
{
101+
return $this->_setOption('host', $host);
102+
}
103+
104+
/**
105+
* Get host option
106+
*
107+
* @return string
108+
*/
109+
public function getHost()
110+
{
111+
return $this->getOption('host');
112+
}
113+
114+
/**
115+
* Set port option
116+
*
117+
* @param int $port
118+
* @return Solarium_Client Provides fluent interface
119+
*/
120+
public function setPort($port)
121+
{
122+
return $this->_setOption('port', $port);
123+
}
124+
125+
/**
126+
* Get port option
127+
* @return int
128+
*/
129+
public function getPort()
130+
{
131+
return $this->getOption('port');
132+
}
133+
134+
/**
135+
* Set path option
136+
*
137+
* @param string $path
138+
* @return Solarium_Client Provides fluent interface
139+
*/
140+
public function setPath($path)
141+
{
142+
// remove trailing slashes
143+
if (substr($path, -1) == '/') $path = substr($path, 0, -1);
144+
145+
return $this->_setOption('path', $path);
146+
}
147+
148+
/**
149+
* Get path option
150+
*
151+
* @return void
152+
*/
153+
public function getPath()
154+
{
155+
return $this->getOption('path');
156+
}
157+
158+
/**
159+
* Set core option
160+
*
161+
* @param string $core
162+
* @return Solarium_Client Provides fluent interface
163+
*/
164+
public function setCore($core)
165+
{
166+
return $this->_setOption('core', $core);
167+
}
168+
169+
/**
170+
* Get core option
171+
*
172+
* @return string
173+
*/
174+
public function getCore()
175+
{
176+
return $this->getOption('core');
177+
}
178+
179+
/**
180+
* Set the adapter
181+
*
182+
* @param string|Solarium_Client_Adapter $adapter
183+
* @return Solarium_Client Provides fluent interface
184+
*/
185+
public function setAdapter($adapter)
186+
{
187+
if (is_string($adapter)) {
188+
$adapter = new $adapter;
189+
}
190+
191+
$adapter->setOptions($this->_options);
192+
$this->_adapter = $adapter;
193+
return $this;
194+
}
195+
196+
/**
197+
* Get the adapter instance
198+
*
199+
* @return Solarium_Client_Adapter
200+
*/
201+
public function getAdapter()
202+
{
203+
if (null === $this->_adapter) {
204+
$this->setAdapter($this->_options['adapter']);
205+
}
206+
207+
return $this->_adapter;
208+
}
209+
210+
/**
211+
* Execute a ping query
212+
*
213+
* @param Solarium_Query_Ping $query
214+
* @return Solarium_Result_Ping
215+
*/
216+
public function ping($query)
217+
{
218+
return $this->getAdapter()->ping($query);
219+
}
220+
221+
/**
222+
* Execute an update query
223+
*
224+
* @param Solarium_Query_Update $query
225+
* @return Solarium_Result_Select
226+
*/
227+
public function update($query)
228+
{
229+
return $this->getAdapter()->update($query);
230+
}
231+
232+
/**
233+
* Execute a select query
234+
*
235+
* @param Solarium_Query_Select $query
236+
* @return Solarium_Result_Select
237+
*/
238+
public function select($query)
239+
{
240+
return $this->getAdapter()->select($query);
241+
}
242+
}

0 commit comments

Comments
 (0)