Created
October 8, 2015 09:11
-
-
Save gong023/9d25d3bddc3c180e40b2 to your computer and use it in GitHub Desktop.
magicSpirce fake
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
<?php | |
trait EntityTrait | |
{ | |
public function __construct(array $properties = []) | |
{ | |
foreach ($properties as $k => $v) { | |
$this->{$k} = $v; | |
} | |
} | |
/** | |
* @return int|null | |
*/ | |
private function getInt() | |
{ | |
static $property_name; | |
if ($property_name === null) { | |
$property_name = $this->getCalledPropertyName(); | |
} | |
return isset($this->{$property_name}) ? (int)$this->{$property_name} : null; | |
} | |
/** | |
* @return float|null | |
*/ | |
private function getFloat() | |
{ | |
static $property_name; | |
if ($property_name === null) { | |
$property_name = $this->getCalledPropertyName(); | |
} | |
return isset($this->{$property_name}) ? (float)$this->{$property_name} : null; | |
} | |
/** | |
* @return string|null | |
*/ | |
private function getString() | |
{ | |
static $property_name; | |
if ($property_name === null) { | |
$property_name = $this->getCalledPropertyName(); | |
} | |
return isset($this->{$property_name}) ? (string)$this->{$property_name} : null; | |
} | |
/* | |
* @return string | |
*/ | |
protected function getCalledPropertyName() | |
{ | |
return strtolower(preg_replace( | |
'/[A-Z]/', | |
'_$0', | |
lcfirst(preg_replace('/^(get|set)/', '', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'])) | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment