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
f10a5969
Commit
f10a5969
authored
Nov 10, 2014
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'toArray' of github.com:ehime/solarium into develop
parents
170fb52f
2ee31129
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
1 deletion
+28
-1
library/Solarium/Core/Configurable.php
library/Solarium/Core/Configurable.php
+28
-1
No files found.
library/Solarium/Core/Configurable.php
View file @
f10a5969
...
...
@@ -83,6 +83,8 @@ class Configurable implements ConfigurableInterface
* If $options is an object, it will be converted into an array by calling
* its toArray method. This is compatible with the Zend_Config classes in
* Zend Framework, but can also easily be implemented in any other object.
* If $options does not have the toArray method, the internal method will
* be used instead.
*
* @throws InvalidArgumentException
* @param array|\Zend_Config $options
...
...
@@ -97,7 +99,7 @@ class Configurable implements ConfigurableInterface
// first convert to array if needed
if
(
!
is_array
(
$options
))
{
if
(
is_object
(
$options
))
{
$options
=
$options
->
toArray
(
);
$options
=
(
!
method_exists
(
$options
,
'toArray'
)
?
$this
->
toArray
(
$options
)
:
$options
->
toArray
()
);
}
else
{
throw
new
InvalidArgumentException
(
'Options value given to the setOptions() method must be an array or a Zend_Config object'
...
...
@@ -177,4 +179,29 @@ class Configurable implements ConfigurableInterface
{
return
$this
->
options
;
}
/**
* Turns an object array into an associative multidimensional array.
*
* @param $object
* @return array|object
*/
protected
function
toArray
(
$object
)
{
if
(
is_object
(
$object
))
{
// get_object_vars() does not handle recursive objects well,
// so use set-type without scope operator instead
settype
(
$object
,
'array'
);
}
/*
* Return array converted to object
* Using __METHOD__ (Magic constant)
* for recursive call
*/
if
(
is_array
(
$object
))
return
array_map
(
__METHOD__
,
$object
);
return
$object
;
}
}
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