nighty commit
This commit is contained in:
parent
9d747d6d0d
commit
3190e22c97
@ -15,7 +15,7 @@ class Inline extends Base
|
|||||||
$layout = !empty($this->_params['layout']) ? $this->_params['layout'] : false;
|
$layout = !empty($this->_params['layout']) ? $this->_params['layout'] : false;
|
||||||
# Create a template so we can call render_inline;
|
# Create a template so we can call render_inline;
|
||||||
$this->_template = new ActionView\Template(['inline' => $this->_params['code']], ['layout' => $layout]);
|
$this->_template = new ActionView\Template(['inline' => $this->_params['code']], ['layout' => $layout]);
|
||||||
$this->_template->setLocals(Rails::application()->controller()->vars());
|
$this->_template->setLocals(\Rails::application()->controller()->vars());
|
||||||
$this->_template->renderContent();
|
$this->_template->renderContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,8 +273,6 @@ abstract class Base
|
|||||||
*/
|
*/
|
||||||
public function __get($prop)
|
public function __get($prop)
|
||||||
{
|
{
|
||||||
# See Config/default_config.php for more info.
|
|
||||||
// if (!Rails::config()->ar2) {
|
|
||||||
if (static::isAttribute($prop)) {
|
if (static::isAttribute($prop)) {
|
||||||
return $this->getAttribute($prop);
|
return $this->getAttribute($prop);
|
||||||
} elseif ($this->getAssociation($prop) !== null) {
|
} elseif ($this->getAssociation($prop) !== null) {
|
||||||
@ -284,9 +282,6 @@ abstract class Base
|
|||||||
throw new Exception\RuntimeException(
|
throw new Exception\RuntimeException(
|
||||||
sprintf("Tried to get unknown property %s::$%s", get_called_class(), $prop)
|
sprintf("Tried to get unknown property %s::$%s", get_called_class(), $prop)
|
||||||
);
|
);
|
||||||
// }
|
|
||||||
// # Force error/default behaviour
|
|
||||||
// return $this->$prop;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -948,30 +943,39 @@ abstract class Base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _getter_for($prop)
|
protected function getterExists($attrName)
|
||||||
{
|
|
||||||
$camelized = Rails::services()->get('inflector')->camelize($prop);
|
|
||||||
$method = 'get' . ucfirst($camelized);
|
|
||||||
|
|
||||||
if (method_exists($this, $method)) {
|
|
||||||
return $this->$method();
|
|
||||||
} elseif (method_exists($this, $camelized)) {
|
|
||||||
return $this->$camelized();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function setterExists($attrName)
|
|
||||||
{
|
{
|
||||||
|
if (is_int(strpos($attrName, '_'))) {
|
||||||
$inflector = Rails::services()->get('inflector');
|
$inflector = Rails::services()->get('inflector');
|
||||||
|
$getter = 'get' . $inflector->camelize($attrName);
|
||||||
|
} else {
|
||||||
|
$getter = 'get' . ucfirst($attrName);
|
||||||
|
}
|
||||||
|
|
||||||
$reflection = self::getReflection();
|
$reflection = self::getReflection();
|
||||||
|
|
||||||
|
if ($reflection->hasMethod($getter) && $reflection->getMethod($getter)->isPublic()) {
|
||||||
|
return $getter;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setterExists($attrName)
|
||||||
|
{
|
||||||
|
if (is_int(strpos($attrName, '_'))) {
|
||||||
|
$inflector = Rails::services()->get('inflector');
|
||||||
$setter = 'set' . $inflector->camelize($attrName);
|
$setter = 'set' . $inflector->camelize($attrName);
|
||||||
|
} else {
|
||||||
|
$setter = 'set' . ucfirst($attrName);
|
||||||
|
}
|
||||||
|
|
||||||
|
$reflection = self::getReflection();
|
||||||
|
|
||||||
if ($reflection->hasMethod($setter) && $reflection->getMethod($setter)->isPublic()) {
|
if ($reflection->hasMethod($setter) && $reflection->getMethod($setter)->isPublic()) {
|
||||||
return $setter;
|
return $setter;
|
||||||
} else {
|
} else {
|
||||||
false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,56 @@ trait AttributeMethods
|
|||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is similar to setAttribute, but goes beyond attributes.
|
||||||
|
* Cheks if the property named $propName is either an attribute,
|
||||||
|
* or a setter exists for it, or it's a public property.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throw Rails\ActiveRecord\Exception\RuntimeException
|
||||||
|
*/
|
||||||
|
public function setProperty($propName, $value)
|
||||||
|
{
|
||||||
|
if (self::isAttribute($propName)) {
|
||||||
|
$this->setAttribute($propName, $value);
|
||||||
|
} else {
|
||||||
|
if ($setterName = $this->setterExists($propName)) {
|
||||||
|
$this->$setterName($value);
|
||||||
|
} elseif (self::hasPublicProperty($propName)) {
|
||||||
|
$this->$propName = $value;
|
||||||
|
} else {
|
||||||
|
throw new Exception\RuntimeException(
|
||||||
|
sprintf("Can't write unknown attribute '%s' for model %s", $propName, get_called_class())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is similar to getAttribute, but goes beyond attributes.
|
||||||
|
* Cheks if the property named $propName is either an attribute,
|
||||||
|
* or a getter exists for it, or it's a public property.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
* @throw Rails\ActiveRecord\Exception\RuntimeException
|
||||||
|
*/
|
||||||
|
public function getProperty($propName)
|
||||||
|
{
|
||||||
|
if (self::isAttribute($propName)) {
|
||||||
|
return $this->getAttribute($propName);
|
||||||
|
} else {
|
||||||
|
if ($getterName = $this->getterExists($propName)) {
|
||||||
|
return $this->$getterName();
|
||||||
|
} elseif (self::hasPublicProperty($propName)) {
|
||||||
|
return $this->$propName;
|
||||||
|
} else {
|
||||||
|
throw new Exception\RuntimeException(
|
||||||
|
sprintf("Can't read unknown attribute '%s' for model %s", $propName, get_called_class())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throw Exception\InvalidArgumentException
|
* @throw Exception\InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
@ -164,22 +214,7 @@ trait AttributeMethods
|
|||||||
// $reflection = new \ReflectionClass(get_called_class());
|
// $reflection = new \ReflectionClass(get_called_class());
|
||||||
|
|
||||||
foreach ($attrs as $attrName => $value) {
|
foreach ($attrs as $attrName => $value) {
|
||||||
if (self::isAttribute($attrName)) {
|
$this->setProperty($attrName, $value);
|
||||||
$this->setAttribute($attrName, $value);
|
|
||||||
} else {
|
|
||||||
if ($setterName = $this->setterExists($attrName)) {
|
|
||||||
$this->$setterName($value);
|
|
||||||
// $setter = 'set' . $inflector->camelize($attrName);
|
|
||||||
} elseif (self::hasPublicProperty($attrName)) {
|
|
||||||
$this->$attrName = $value;
|
|
||||||
// if ($reflection->hasMethod($setter) && $reflection->getMethod($setter)->isPublic()) {
|
|
||||||
// $this->$setter($value);
|
|
||||||
} else {
|
|
||||||
throw new Exception\RuntimeException(
|
|
||||||
sprintf("Can't write unknown attribute '%s' for model %s", $attrName, get_called_class())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class Validator extends RailsValidation
|
|||||||
if ($this->_model->$property === null)
|
if ($this->_model->$property === null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return (string)$this->_model->getAttribute($this->_property) == (string)$this->_model->$property;
|
return (string)$this->_model->getProperty($this->_property) == (string)$this->_model->$property;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _validate_acceptance()
|
protected function _validate_acceptance()
|
||||||
|
@ -29,7 +29,7 @@ class MemCachedStore extends AbstractStore
|
|||||||
{
|
{
|
||||||
$value = $this->connection->get($key);
|
$value = $this->connection->get($key);
|
||||||
|
|
||||||
if (!$value) {
|
if ($value === false) {
|
||||||
if ($this->connection->getResultCode() == Memcached::RES_NOTFOUND) {
|
if ($this->connection->getResultCode() == Memcached::RES_NOTFOUND) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
@ -47,10 +47,11 @@ class MemCachedStore extends AbstractStore
|
|||||||
if (isset($params['expires_in'])) {
|
if (isset($params['expires_in'])) {
|
||||||
if (!ctype_digit((string)$params['expires_in']))
|
if (!ctype_digit((string)$params['expires_in']))
|
||||||
$expires_in = strtotime('+' . $params['expires_in']);
|
$expires_in = strtotime('+' . $params['expires_in']);
|
||||||
} else
|
} else {
|
||||||
$expires_in = 0;
|
$expires_in = 0;
|
||||||
|
}
|
||||||
|
|
||||||
$resp = $this->connection->add($key, $val, $expires_in);
|
return $this->connection->set($key, $val, $expires_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete($key, array $params)
|
public function delete($key, array $params)
|
||||||
|
Reference in New Issue
Block a user