Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
3b520517
Commit
3b520517
authored
Apr 09, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added multivalue support to __set magic method (set field value by property)
- updated ReadWrite unittest
parent
af7e6f04
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
library/Solarium/Document/ReadWrite.php
library/Solarium/Document/ReadWrite.php
+12
-2
tests/Solarium/Document/ReadWriteTest.php
tests/Solarium/Document/ReadWriteTest.php
+22
-0
No files found.
library/Solarium/Document/ReadWrite.php
View file @
3b520517
...
...
@@ -112,7 +112,8 @@ class Solarium_Document_ReadWrite extends Solarium_Document_ReadOnly
/**
* Set a field value
*
* If a field already has a value it will be overwritten.
* If a field already has a value it will be overwritten. You cannot use
* this method for a multivalue field.
* If you supply NULL as the value the field will be removed
*
* @param string $key
...
...
@@ -208,6 +209,8 @@ class Solarium_Document_ReadWrite extends Solarium_Document_ReadOnly
* object, by field name.
*
* If you supply NULL as the value the field will be removed
* If you supply an array a multivalue field will be created.
* In all cases any existing (multi)value will be overwritten.
*
* @param string $name
* @param string|null $value
...
...
@@ -215,8 +218,15 @@ class Solarium_Document_ReadWrite extends Solarium_Document_ReadOnly
*/
public
function
__set
(
$name
,
$value
)
{
if
(
is_array
(
$value
))
{
$this
->
removeField
(
$name
);
// remove any existing value(s)
foreach
(
$value
AS
$multival
)
{
$this
->
addField
(
$name
,
$multival
);
}
}
else
{
$this
->
setField
(
$name
,
$value
);
}
}
/**
* Unset field value
...
...
tests/Solarium/Document/ReadWriteTest.php
View file @
3b520517
...
...
@@ -212,6 +212,28 @@ class Solarium_Document_ReadWriteTest extends PHPUnit_Framework_TestCase
);
}
public
function
testSetAndGetMultivalueFieldByProperty
()
{
$values
=
array
(
'test1'
,
'test2'
,
'test3'
);
$this
->
_doc
->
multivaluefield
=
$values
;
$this
->
assertEquals
(
$values
,
$this
->
_doc
->
multivaluefield
);
}
public
function
testSetAndGetMultivalueFieldByPropertyOverwrite
()
{
$values
=
array
(
'test1'
,
'test2'
,
'test3'
);
$this
->
_doc
->
name
=
$values
;
$this
->
assertEquals
(
$values
,
$this
->
_doc
->
name
);
}
public
function
testUnsetFieldByProperty
()
{
unset
(
$this
->
_doc
->
name
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment