nighty commit

This commit is contained in:
Parziphal 2013-10-21 03:07:58 -05:00
parent 9d747d6d0d
commit 3190e22c97
5 changed files with 82 additions and 42 deletions

View File

@ -15,7 +15,7 @@ class Inline extends Base
$layout = !empty($this->_params['layout']) ? $this->_params['layout'] : false;
# Create a template so we can call render_inline;
$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();
}

View File

@ -273,8 +273,6 @@ abstract class Base
*/
public function __get($prop)
{
# See Config/default_config.php for more info.
// if (!Rails::config()->ar2) {
if (static::isAttribute($prop)) {
return $this->getAttribute($prop);
} elseif ($this->getAssociation($prop) !== null) {
@ -284,9 +282,6 @@ abstract class Base
throw new Exception\RuntimeException(
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();
if (is_int(strpos($attrName, '_'))) {
$inflector = Rails::services()->get('inflector');
$getter = 'get' . $inflector->camelize($attrName);
} else {
$getter = 'get' . ucfirst($attrName);
}
return null;
}
private function setterExists($attrName)
{
$inflector = Rails::services()->get('inflector');
$reflection = self::getReflection();
$setter = 'set' . $inflector->camelize($attrName);
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);
} else {
$setter = 'set' . ucfirst($attrName);
}
$reflection = self::getReflection();
if ($reflection->hasMethod($setter) && $reflection->getMethod($setter)->isPublic()) {
return $setter;
} else {
false;
return false;
}
}
}

View File

@ -77,6 +77,56 @@ trait AttributeMethods
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
*/
@ -164,22 +214,7 @@ trait AttributeMethods
// $reflection = new \ReflectionClass(get_called_class());
foreach ($attrs as $attrName => $value) {
if (self::isAttribute($attrName)) {
$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())
);
}
}
$this->setProperty($attrName, $value);
}
}

View File

@ -105,7 +105,7 @@ class Validator extends RailsValidation
if ($this->_model->$property === null)
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()

View File

@ -29,7 +29,7 @@ class MemCachedStore extends AbstractStore
{
$value = $this->connection->get($key);
if (!$value) {
if ($value === false) {
if ($this->connection->getResultCode() == Memcached::RES_NOTFOUND) {
return null;
} else {
@ -47,10 +47,11 @@ class MemCachedStore extends AbstractStore
if (isset($params['expires_in'])) {
if (!ctype_digit((string)$params['expires_in']))
$expires_in = strtotime('+' . $params['expires_in']);
} else
} else {
$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)