Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
990643c
commit 934ce8d
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* This file is part of Properties package. | ||
* | ||
* @author Serafim <nesk@xakep.ru> | ||
* @date 14.04.2016 17:07 | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Serafim\Properties; | ||
|
||
use Serafim\Properties\Support\Registry; | ||
use Serafim\Properties\Support\Strings as Str; | ||
|
||
/** | ||
* Class Properties | ||
* @package Serafim\Properties | ||
*/ | ||
trait Properties | ||
{ | ||
use Getters, Setters; | ||
|
||
/** | ||
* @param $name | ||
* @return bool | ||
*/ | ||
public function __isset($name) | ||
{ | ||
// Try to call `getProperty` method | ||
$getter = Str::getGetter($name); | ||
if (method_exists($this, $getter)) { | ||
return true; | ||
} | ||
|
||
return Registry::get($this)->has($name); | ||
} | ||
|
||
/** | ||
* @param $name | ||
* @return bool | ||
*/ | ||
public function __unset($name) | ||
{ | ||
$registry = Registry::get($this); | ||
|
||
$reflection = new \ReflectionClass($this); | ||
|
||
if ($registry->has($name) && $reflection->hasProperty($name)) { | ||
$property = $reflection->getProperty($name); | ||
|
||
if ($property->isProtected() || $property->isPublic()) { | ||
unset($this->$name); | ||
return true; | ||
} | ||
|
||
} | ||
|
||
return false; | ||
} | ||
} |