Update AbstractData.php
Ability to set default return values when a property is not available in the probe results
This commit is contained in:
parent
c8949fe3df
commit
7bbd06876c
1 changed files with 5 additions and 1 deletions
|
|
@ -37,13 +37,17 @@ abstract class AbstractData implements \Countable
|
|||
* Returns the property value given its name.
|
||||
*
|
||||
* @param string $property
|
||||
* @param mixed $default [optional]
|
||||
* @return mixed
|
||||
*
|
||||
* @throws InvalidArgumentException In case the data does not have the property
|
||||
*/
|
||||
public function get($property)
|
||||
public function get($property, $default = null)
|
||||
{
|
||||
if (!isset($this->properties[$property])) {
|
||||
if(!is_null($default)){
|
||||
return $default;
|
||||
}
|
||||
throw new InvalidArgumentException(sprintf('Invalid property `%s`.', $property));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue