nighty commit

This commit is contained in:
Parziphal 2013-10-13 02:50:03 -05:00
parent f26182f567
commit 02d189bec8
13 changed files with 78 additions and 35 deletions

View File

@ -4,26 +4,40 @@ namespace Rails\ActionController\Response;
use Rails\ActionView;
# TODO
class ActionController_Response_Partial extends Base
class Partial extends Base
{
private $_template;
public function _render_view()
{
$params = [$this->_params['partial']];
if (isset($this->_params['locals']))
$params = array_merge($params, [$this->_params['locals']]);
# Include helpers.
ActionView\ViewHelpers::load();
$layout = !empty($this->_params['layout']) ? $this->_params['layout'] : false;
$partial = $this->_params['partial'];
$locals = (array)\Rails::application()->controller()->locals();
$this->_template = new ActionView\Template(['lambda' => function() use ($partial, $locals) {
echo $this->partial($partial, $locals);
}], ['layout' => $layout]);
// $this->_template->setLocals();
$this->_template->renderContent();
// $params = [$this->_params['partial']];
// if (isset($this->_params['locals']))
// $params = array_merge($params, [$this->_params['locals']]);
# Include helpers.
// ActionView\ViewHelpers::load();
# Create a template so we can call render_partial.
# This shouldn't be done this way.
$template = new ActionView\Template([]);
$this->_body = call_user_func_array([$template, 'render_partial'], $params);
// $template = new ActionView\Template([]);
// vpe($this);
// $this->_body = call_user_func_array([$template, 'renderContent'], $params);
}
public function _print_view()
{
return $this->_body;
return $this->_template->content();
}
}
}

View File

@ -1,6 +0,0 @@
<?php
namespace Rails\Http\Exception;
interface ExceptionInterface
{
}

View File

@ -1,6 +0,0 @@
<?php
namespace Rails\Http\Exception;
class InvalidArgumentException extends \Rails\Exception\InvalidArgumentException implements ExceptionInterface
{
}

View File

@ -1,6 +0,0 @@
<?php
namespace Rails\Http\Exception;
class LogicException extends \Rails\Exception\LogicException implements ExceptionInterface
{
}

View File

@ -2,6 +2,7 @@
namespace Rails\ActionDispatch\Http;
use Rails;
use Rails\ActionDispatch\Exception;
class Headers
{

View File

@ -20,7 +20,10 @@ class Table/* extends AbstractTable*/
$table_data = $table_indexes = $pri = $uni = [];
foreach ($rows as $row) {
$data = ['type' => $row['Type']];
$data = [
'type' => $row['Type'],
'default' => $row['Default']
];
if (strpos($row['Type'], 'enum') === 0) {
$enum_values = [];
@ -52,4 +55,4 @@ class Table/* extends AbstractTable*/
return [$table_data, $table_indexes];
}
}
}

View File

@ -24,7 +24,10 @@ class Table/* extends AbstractTable*/
];
foreach ($rows as $row) {
$data = ['type' => $row['type']];
$data = [
'type' => $row['type'],
'default' => $row['default']
];
$table_data[$row['name']] = $data;
if ($row['pk'])
@ -33,4 +36,4 @@ class Table/* extends AbstractTable*/
return [$table_data, $table_indexes];
}
}
}

View File

@ -30,6 +30,11 @@ abstract class Base
*/
static private $preventInit = false;
/**
* Flag to prevent setting default attributes.
*/
static private $skipDefaultAttributes = false;
/**
* ActiveModel\Errors instance.
*/
@ -205,6 +210,7 @@ abstract class Base
static private function _create_model(array $data)
{
self::$preventInit = true;
self::$skipDefaultAttributes = true;
$model = new static();
$model->attributes = $data;
@ -243,6 +249,12 @@ abstract class Base
public function __construct(array $attrs = [])
{
if (!self::$skipDefaultAttributes) {
$this->setDefaultAttributes();
} else {
self::$skipDefaultAttributes = true;
}
$this->assignAttributes($attrs);
if (!self::$preventInit) {
$this->init();

View File

@ -282,4 +282,9 @@ trait AttributeMethods
$attributes = array_diff_key($attributes, array_fill_keys($attrs, true));
}
}
}
private function setDefaultAttributes()
{
$this->attributes = self::table()->columnDefaults();
}
}

View File

@ -17,6 +17,8 @@ class ModelSchema
protected $primaryKey;
protected $columnDefaults;
public function __construct($name, Connection $connection)
{
$this->name = $name;
@ -104,6 +106,19 @@ class ModelSchema
return !empty($this->columns[$column_name]);
}
public function columnDefaults()
{
if ($this->columnDefaults === null) {
$this->columnDefaults = [];
foreach ($this->columns as $name => $data) {
if ($data['default'] !== null) {
$this->columnDefaults[$name] = $data['default'];
}
}
}
return $this->columnDefaults;
}
public function enumValues($column_name)
{
if (!isset($this->columns[$column_name])) {

View File

@ -4,4 +4,4 @@ namespace Rails\Exception;
class LogicException extends \LogicException implements ExceptionInterface
{
use ExceptionTrait;
}
}

View File

@ -74,6 +74,14 @@ class I18n
return false;
}
/**
* When adding new translations with the same name, since the arrays are
* recursively merged, the result will not be a string, but an array.
* If this is the case, the latter value will be used.
*/
if (is_array($tr))
$tr = array_pop($tr);
if (is_int(strpos($tr, '%{'))) {
foreach ($params as $k => $param) {
$tr = str_replace('%{'.$k.'}', $param, $tr);

View File

@ -50,4 +50,4 @@ class DbTools
}
}
}
}
}