mirror of
https://github.com/webmasterskaya/joomla-oauth-server.git
synced 2024-11-24 02:44:51 +03:00
Добавил Trait для работы с protected полями
This commit is contained in:
parent
a48a9b3a2f
commit
6de591a03d
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Webmasterskaya\Component\OauthServer\Administrator\Table;
|
||||||
|
|
||||||
|
use Webmasterskaya\Component\OauthServer\Administrator\Helper\CasesHelper;
|
||||||
|
|
||||||
|
trait PropertyManagerTrait
|
||||||
|
{
|
||||||
|
public function __get($name)
|
||||||
|
{
|
||||||
|
// All protected properties names must start with _
|
||||||
|
if (str_starts_with($name, '_')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If class has getter for property
|
||||||
|
$getterName = 'get' . CasesHelper::camelize($name, true);
|
||||||
|
if (method_exists($this, $getterName)) {
|
||||||
|
return call_user_func([$this, $getterName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->$name)) {
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __set($name, $value)
|
||||||
|
{
|
||||||
|
// All protected properties names must start with _
|
||||||
|
if (str_starts_with($name, '_')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If class has setter for property
|
||||||
|
$setterName = 'set' . CasesHelper::camelize($name, true);
|
||||||
|
if (method_exists($this, $setterName)) {
|
||||||
|
call_user_func([$this, $setterName], $value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->$name)) {
|
||||||
|
$this->$name = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user