more changes

This commit is contained in:
Parziphal 2013-10-04 19:10:33 -05:00
parent 6d4004ae33
commit b2a546f2bc
5 changed files with 80 additions and 46 deletions

View File

@ -14,5 +14,16 @@
"psr-0": { "psr-0": {
"Rails\\": "lib/" "Rails\\": "lib/"
} }
},
"extra": {
"ZF2/library": [
"zendframework/zend-validator",
"zendframework/zend-log",
"zendframework/zend-mail",
"zendframework/zend-console"
// "symfony/yaml"
// "leafo/scssphp"
// "toopay/assetic-minifier"
]
} }
} }

View File

@ -167,7 +167,7 @@ class Parameters implements \IteratorAggregate
$obj_vars = get_object_vars($this); $obj_vars = get_object_vars($this);
unset($obj_vars['deleteVars'], $obj_vars['putVars'], $obj_vars['_json_params_error'], $obj_vars['patchVars'], $obj_vars['other_params'], $obj_vars['files']); unset($obj_vars['deleteVars'], $obj_vars['putVars'], $obj_vars['_json_params_error'], $obj_vars['patchVars'], $obj_vars['other_params'], $obj_vars['files']);
$ret = array_merge_recursive($_POST, $_GET, $obj_vars, $this->deleteVars, $this->putVars, $this->patchVars, $this->other_params/*, $this->files*/); $ret = array_merge($_POST, $_GET, $obj_vars, $this->deleteVars, $this->putVars, $this->patchVars, $this->other_params/*, $this->files*/);
return $ret; return $ret;
} }

View File

@ -37,22 +37,20 @@ class Template extends Base
/** /**
* Template file. * Template file.
*/ */
protected $template_file; private $_templateFile;
/** /**
* Full template path. * Full template path.
*/ */
protected $template_filename; private $_templateFilename;
protected $type; private $_type;
protected $params; private $_contents;
protected $contents; private $inline_code;
protected $inline_code; private $_lambda;
protected $lambda;
/** /**
* $render_params could be: * $render_params could be:
@ -69,11 +67,11 @@ class Template extends Base
$render_params = ['file' => $render_params]; $render_params = ['file' => $render_params];
} }
$this->type = key($render_params); $this->_type = key($render_params);
switch ($this->type) { switch ($this->_type) {
case 'file': case 'file':
$this->template_file = array_shift($render_params); $this->_templateFile = array_shift($render_params);
break; break;
/** /**
@ -81,7 +79,7 @@ class Template extends Base
* no processing is needed. It will just be added to the layout, if any. * no processing is needed. It will just be added to the layout, if any.
*/ */
case 'contents': case 'contents':
$this->contents = array_shift($render_params); $this->_contents = array_shift($render_params);
break; break;
/** /**
@ -92,10 +90,10 @@ class Template extends Base
break; break;
case 'lambda': case 'lambda':
$this->lambda = array_shift($render_params); $this->_lambda = array_shift($render_params);
break; break;
} }
$this->params = $params; $this->_params = $params;
if (isset($params['locals'])) { if (isset($params['locals'])) {
$locals = $params['locals']; $locals = $params['locals'];
@ -171,13 +169,13 @@ class Template extends Base
} }
if (strpos($name, '.') === 0) { if (strpos($name, '.') === 0) {
if (is_int(strpos($this->template_filename, Rails::config()->paths->views->toString()))) { if (is_int(strpos($this->_templateFilename, Rails::config()->paths->views->toString()))) {
$parts = array(); $parts = array();
$path = substr( $path = substr(
$this->template_filename, strlen(Rails::config()->paths->views) + 1, $this->_templateFilename, strlen(Rails::config()->paths->views) + 1,
strlen(pathinfo($this->template_filename, PATHINFO_BASENAME)) * -1 strlen(pathinfo($this->_templateFilename, PATHINFO_BASENAME)) * -1
) )
. pathinfo($this->template_filename, PATHINFO_FILENAME); . pathinfo($this->_templateFilename, PATHINFO_FILENAME);
foreach (explode('/', $path) as $part) { foreach (explode('/', $path) as $part) {
$parts[] = ltrim($part, '_'); $parts[] = ltrim($part, '_');
@ -191,34 +189,34 @@ class Template extends Base
protected function _init_render() protected function _init_render()
{ {
$layout_wrap = !empty($this->params['layout']); $layout_wrap = !empty($this->_params['layout']);
if ($layout_wrap) { if ($layout_wrap) {
$layout_file = $this->resolve_layout_file($this->params['layout']); $layout_file = $this->resolve_layout_file($this->_params['layout']);
if (!is_file($layout_file)) if (!is_file($layout_file))
throw new Exception\LayoutMissingException( throw new Exception\LayoutMissingException(
sprintf("Missing layout '%s' [ file => %s ]", sprintf("Missing layout '%s' [ file => %s ]",
$this->params['layout'], $layout_file) $this->_params['layout'], $layout_file)
); );
ob_start(); ob_start();
} }
switch ($this->type) { switch ($this->_type) {
case 'file': case 'file':
$this->build_template_filename(); $this->build_template_filename();
if (!is_file($this->template_filename)) { if (!is_file($this->_templateFilename)) {
throw new Exception\TemplateMissingException( throw new Exception\TemplateMissingException(
sprintf("Missing template file %s", $this->template_filename) sprintf("Missing template file %s", $this->_templateFilename)
); );
} }
require $this->template_filename; require $this->_templateFilename;
break; break;
case 'contents': case 'contents':
echo $this->contents; echo $this->_contents;
break; break;
case 'inline': case 'inline':
@ -226,8 +224,8 @@ class Template extends Base
break; break;
case 'lambda': case 'lambda':
$lambda = $this->lambda; $lambda = $this->_lambda;
$this->lambda = null; $this->_lambda = null;
$lambda = $lambda->bindTo($this); $lambda = $lambda->bindTo($this);
$lambda(); $lambda();
break; break;
@ -268,14 +266,14 @@ class Template extends Base
private function build_template_filename() private function build_template_filename()
{ {
$template = $this->template_file; $template = $this->_templateFile;
if (strpos($template, '/') === 0 || preg_match('/^[A-Za-z]:(?:\\\|\/)/', $template)) if (strpos($template, '/') === 0 || preg_match('/^[A-Za-z]:(?:\\\|\/)/', $template))
$this->template_filename = $template; $this->_templateFilename = $template;
else { else {
if (is_int(strpos($template, '.'))) { if (is_int(strpos($template, '.'))) {
$this->template_filename = Rails::config()->paths->views . '/' . $template; $this->_templateFilename = Rails::config()->paths->views . '/' . $template;
} else { } else {
$this->template_filename = Rails::config()->paths->views . '/' . $template . '.php'; $this->_templateFilename = Rails::config()->paths->views . '/' . $template . '.php';
} }
} }
} }

View File

@ -0,0 +1,35 @@
<?php
namespace Rails\ActionView\Template;
class Renderer
{
private $template;
private $file;
public function __construct($template, $file)
{
$this->template = $template;
$this->file = $file;
}
public function __get($prop)
{
return $this->getLocal($prop);
}
public function __set($prop, $value)
{
$this->setLocal($prop);
}
public function getLocal($prop)
{
return $this->template->getLocal($prop);
}
public function setLocal($prop, $value)
{
$this->template->setLocal($prop);
}
}

View File

@ -77,21 +77,11 @@ $config->active_record = [
$config->action_view = [ $config->action_view = [
'layout' => 'application', 'layout' => 'application',
'suffix' => 'phtml', 'suffix' => 'phtml'
'helpers' => [
// 'will_paginate' => [
// /**
// * Sets a default custom renderer class.
// * Built-in renderers are Bootstrap and Legacy.
// * A custom renderer class can be created, extending
// * Rails\ActionView\Helper\WillPaginate\AbstractRenderer.
// */
// 'renderer' => 'bootstrap',
// 'always_show' => false # Show pagination even if there's only 1 page
// ]
]
]; ];
$config->plugins = [];
$config->action_mailer = [ $config->action_mailer = [
/** /**
* Allows "sendmail", "smtp" or "file". * Allows "sendmail", "smtp" or "file".