<?php
class Profile_Model_Profile
{
protected $_userId;
protected $_email;
protected $_firstName;
protected $_lastName;
protected $_midName;
/**
* @var Core_Model_File
*/
protected $_cvFile;
/**
* @var Profile_Model_Affil
*/
protected $_affil;
public function __isset($key)
{
return isset($this->{'_' . self::toCamelCase($key)});
}
public function __get($key)
{
$property = '_' . self::toCamelCase($key);
if (property_exists($this, $property)) {
return $property;
}
throw new RuntimeException(sprintf('Invalid property: %s', $property));
}
public function __set($key, $value)
{
$key = self::toCamelCase($key);
$setter = 'set' . $key;
if (method_exists($this, $setter)) {
return $this->{$setter}($value);
}
$property = '_' . $key;
if (property_exists($this, $property)) {
$this->{$property} = $value;
return;
}
throw new RuntimeException(sprintf('Invalid property: %s', $property));
}
/**
* Transform given string to camel-case.
*
* @param string $str
* @return string
*/
public static function toCamelCase($str)
{
if (is_array($str) && isset($str[1])) {
return strtoupper($str[1]);
}
return preg_replace_callback(
'/_(\w)/', array(__CLASS__, __FUNCTION__), (string) $str
);
}
}
echo Profile_Model_Profile::toCamelCase('to_jest_dupa_blada_html'), "\n";
echo Profile_Model_Profile::toCamelCase('to_jest_dupa_bladaHTML');
preferences:
35.23 ms | 402 KiB | 5 Q