nighty commit

This commit is contained in:
Parziphal 2013-10-13 21:45:38 -05:00
parent 02d189bec8
commit 49e2421171
10 changed files with 49 additions and 250 deletions

View File

@ -602,7 +602,7 @@ abstract class Base extends ActionController
switch ($render_type) { switch ($render_type) {
case 'action': case 'action':
# Cut the 'Controller' part of the class name. # Cut the 'Controller' part of the class name.
$path = Rails::services()->get('inflector')->underscore(substr(get_called_class(), 0, -10)) . '/' . $main_param . '.php'; $path = Rails::services()->get('inflector')->underscore(substr(get_called_class(), 0, -10)) . '/' . $main_param;
// if ($route->namespaces()) // if ($route->namespaces())
// $path = implode('/', $route->namespaces()) . '/' . $path; // $path = implode('/', $route->namespaces()) . '/' . $path;
@ -611,7 +611,10 @@ abstract class Base extends ActionController
# Fallthrough # Fallthrough
case 'template': case 'template':
$respParams = [];
$layout = !empty($this->render_params['layout']) ? $this->render_params['layout'] : $this->layout; $layout = !empty($this->render_params['layout']) ? $this->render_params['layout'] : $this->layout;
$respParams['layout'] = $layout;
$ext = pathinfo($main_param, PATHINFO_EXTENSION); $ext = pathinfo($main_param, PATHINFO_EXTENSION);
@ -621,8 +624,9 @@ abstract class Base extends ActionController
if ($this->request()->format() == 'html') { if ($this->request()->format() == 'html') {
$ext = 'php'; $ext = 'php';
} else { } else {
if ($this->request()->format() == 'xml') if ($this->request()->format() == 'xml') {
$this->_response_params['is_xml'] = true; $respParams['is_xml'] = true;
}
$ext = [$this->request()->format(), 'php']; $ext = [$this->request()->format(), 'php'];
$this->response()->headers()->contentType($this->request()->format()); $this->response()->headers()->contentType($this->request()->format());
@ -639,11 +643,10 @@ abstract class Base extends ActionController
$template_name = $pinfo['dirname'] . '/' . $pinfo['filename']; $template_name = $pinfo['dirname'] . '/' . $pinfo['filename'];
} }
$this->_response_params = [ $respParams['template_name'] = $template_name;
'layout' => $layout, $respParams['extension'] = $ext;
'template_name' => $template_name,
'extension' => $ext $this->_response_params = $respParams;
];
# Here we could choose a different responder according to extensions(?). # Here we could choose a different responder according to extensions(?).
$class = 'Rails\ActionController\Response\Template'; $class = 'Rails\ActionController\Response\Template';

View File

@ -81,19 +81,20 @@ class Parameters implements \IteratorAggregate
if ($var) { if ($var) {
global ${$var}; global ${$var};
if (is_array(${$var}[$prop])) { // if (is_array(${$var}[$prop])) {
// if (isset($this->files[$prop])) { // if (isset($this->files[$prop])) {
// ${$var}[$prop] = array_merge(${$var}[$prop], $this->files[$prop]); // ${$var}[$prop] = array_merge(${$var}[$prop], $this->files[$prop]);
// } // }
$this->$prop = new GlobalVar(${$var}[$prop], $var, $prop); // $this->$prop = new GlobalVar(${$var}[$prop], $var, $prop);
# Return here. # Return here.
return $this->$prop; // return
} elseif (is_object(${$var}[$prop])) { // return $this->$prop;
$this->$prop = ${$var}[$prop]; // } elseif (is_object(${$var}[$prop])) {
$ret = $this->$prop; // $this->$prop = ${$var}[$prop];
} else { // $ret = $this->$prop;
// } else {
$ret = ${$var}[$prop]; $ret = ${$var}[$prop];
} // }
} else { } else {
if (isset($this->putVars[$prop])) if (isset($this->putVars[$prop]))
$ret = $this->putVars[$prop]; $ret = $this->putVars[$prop];

View File

@ -8,10 +8,20 @@ trait Tag
return '<' . $name . ' ' . $this->_options($options, $escape) . ($open ? '>' : ' />'); return '<' . $name . ' ' . $this->_options($options, $escape) . ($open ? '>' : ' />');
} }
/**
* $content could be a Closure that can either return a string or
* echo the contents itself.
*/
public function contentTag($name, $content, array $options = array(), $escape = false) public function contentTag($name, $content, array $options = array(), $escape = false)
{ {
if ($content instanceof \Closure) { if ($content instanceof \Closure) {
$content = $content($this->view()); ob_start();
$tmpContent = $content();
$content = ob_get_clean();
if ($tmpContent !== null) {
$content = $tmpContent;
unset($tmpContent);
}
} }
return $this->_content_tag_string($name, $content, $options, $escape); return $this->_content_tag_string($name, $content, $options, $escape);
} }

View File

@ -1,168 +0,0 @@
<?php
namespace Rails\ActionView\Helper\WillPaginate;
use Rails;
use Rails\ActiveRecord\Collection;
abstract class AbstractRenderer
{
protected $collection;
protected $options;
protected $helper;
protected $pages;
protected $page;
protected $url;
public function __construct($helper, Collection $collection, array $options = [])
{
$this->collection = $collection;
$this->helper = $helper;
$this->options = array_merge($this->defaultOptions(), $options);
}
public function toHtml()
{
$html = implode(array_map(function($item){
if (is_int($item))
return $this->pageNumber($item);
else
return $this->$item();
}, $this->pagination()), $this->options['link_separator']);
return $this->options['container'] ? $this->htmlContainer($html) : $html;
}
protected function defaultOptions()
{
return [
'previous_label' => '&#8592; ' . $this->helper->t('actionview.helper.will_paginate.previous'),
'next_label' => $this->helper->t('actionview.helper.will_paginate.next') . ' &#8594;',
'container' => true,
'link_separator' => ' '
];
}
protected function pageNumber($page)
{
if ($page != $this->collection->currentPage())
return $this->link($page, $page, ['rel' => $this->relValue($page)]);
else
return $this->tag('span', $page, ['class' => 'current']);
}
protected function gap()
{
return '<span class="gap">&hellip;</span>';
}
protected function previousPage()
{
$num = $this->collection->currentPage() > 1 ?
$this->collection->currentPage() - 1 : false;
return $this->previousOrNextPage($num, $this->options['previous_label'], 'previousPage');
}
protected function nextPage()
{
$num = $this->collection->currentPage() < $this->collection->totalPages() ?
$this->collection->currentPage() + 1 : false;
return $this->previousOrNextPage($num, $this->options['next_label'], 'nextPage');
}
protected function previousOrNextPage($page, $text, $classname)
{
if ($page)
return $this->link($text, $page, ['class' => $classname]);
else
return $this->tag('span', $text, ['class' => $classname . ' disabled']);
}
protected function htmlContainer($html)
{
return $this->tag('div', $html, $this->containerAttributes());
}
protected function containerAttributes()
{
return ['class' => 'pagination'];
}
protected function relValue($page)
{
if ($this->collection->currentPage() - 1 == $page)
return 'prev' . ($page == 1 ? ' start' : '');
elseif ($this->collection->currentPage() + 1 == $page)
return 'next';
elseif ($page == 1)
return 'start';
}
protected function pagination()
{
$pages = $this->collection->totalPages();
$page = $this->collection->currentPage();
$pagination = [];
$pagination[] = 'previousPage';
$pagination[] = 1;
if ($pages < 10){
for ($i = 2; $i <= $pages; $i++){
$pagination[] = $i;
}
} elseif ($page > ($pages - 4)) {
$pagination[] = 'gap';
for ($i = ($pages - 4); $i < ($pages); $i++) {
$pagination[] = $i;
}
} elseif ($page > 4) {
$pagination[] = 'gap';
for ($i = ($page - 1); $i <= ($page + 2); $i++) {
$pagination[] = $i;
}
$pagination[] = 'gap';
} else {
if ($page >= 3){
for ($i = 2; $i <= $page+2; $i++) {
$pagination[] = $i;
}
} else {
for ($i = 2; $i <= 5; $i++) {
$pagination[] = $i;
}
}
$pagination[] = 'gap';
}
if ($pages >= 10) {
if ($pages == $page)
$pagination[] = $i;
else
$pagination[] = $pages;
}
$pagination[] = 'nextPage';
return $pagination;
}
protected function link($text, $page, array $attrs = [])
{
return $this->helper->linkTo($text, array_merge(['#index'], $this->params()->query_parameters(), ['page' => $page]), $attrs);
}
protected function tag($type, $content, array $attrs = [])
{
return $this->helper->contentTag($type, $content, $attrs);
}
protected function params()
{
return Rails::application()->dispatcher()->parameters();
}
}

View File

@ -1,52 +0,0 @@
<?php
namespace Rails\ActionView\Helper\WillPaginate;
class BootstrapRenderer extends AbstractRenderer
{
public function toHtml()
{
$html = implode(array_map(function($item){
if (is_int($item))
return $this->pageNumber($item);
else
return $this->$item();
}, $this->pagination()), $this->options['link_separator']);
return $this->htmlContainer($this->tag('ul', $html));
}
protected function pageNumber($page)
{
if ($page != $this->collection->currentPage())
return $this->tag('li', $this->link($page, $page, ['rel' => $this->relValue($page)]));
else
return $this->tag('li', $this->tag('span', $page), ['class' => 'current']);
}
protected function gap()
{
return $this->tag('li', $this->link('&hellip;', "#"), ['class' => 'disabled']);
}
protected function previousPage()
{
$num = $this->collection->currentPage() > 1 ?
$this->collection->currentPage() - 1 : false;
return $this->previousOrNextPage($num, $this->options['previous_label'], 'prev');
}
protected function nextPage()
{
$num = $this->collection->currentPage() < $this->collection->totalPages() ?
$this->collection->currentPage() + 1 : false;
return $this->previousOrNextPage($num, $this->options['next_label'], 'next');
}
protected function previousOrNextPage($page, $text, $classname)
{
if ($page)
return $this->tag('li', $this->link($text, $page), ['class' => $classname]);
else
return $this->tag('li', $this->tag('span', $text), ['class' => $classname . ' disabled']);
}
}

View File

@ -1,8 +0,0 @@
<?php
namespace Rails\ActionView\Helper\WillPaginate;
use Rails\ActiveRecord\Collection;
class LegacyRenderer extends AbstractRenderer
{
}

View File

@ -52,6 +52,13 @@ class Template extends Base
private $_lambda; private $_lambda;
// /**
// * Template Extension to search for.
// * Eg: xml => file_name.xml.php
// * If null, no extra extension is appended.
// */
// private $tplExtension;
/** /**
* $render_params could be: * $render_params could be:
* - A string, that will be taken as "file". * - A string, that will be taken as "file".

View File

@ -45,10 +45,10 @@ class Xml
if (is_string($content)) if (is_string($content))
$this->_buffer .= $content; $this->_buffer .= $content;
elseif ($content instanceof Closure) elseif ($content instanceof \Closure)
$this->_buffer .= $content(); $this->_buffer .= $content();
else else
throw new Exception\InvalidArgumentError( throw new Exception\InvalidArgumentException(
sprintf('Expecting Closure or string as third argument, %s passed.', gettype($content)) sprintf('Expecting Closure or string as third argument, %s passed.', gettype($content))
); );

View File

@ -71,8 +71,14 @@ class QueryBuilder extends AbstractQueryBuilder
# Case: ["foo" => $foo, "bar_baz" => $bar]; # Case: ["foo" => $foo, "bar_baz" => $bar];
if (is_array($condition)) { if (is_array($condition)) {
foreach ($condition as $column => $value) { foreach ($condition as $column => $value) {
$where[] = $column . ' = ?'; if (is_array($value)) {
$where_params[] = $value; $k = 1;
$where[] = '`' . $column . '` IN (' . implode(', ', array_fill(0, count($value), '?')) . ')';
$where_params = array_merge($where_params, $value);
} else {
$where[] = '`' . $column . '` = ?';
$where_params[] = $value;
}
} }
} else { } else {
if ($count = substr_count($condition, '?')) { if ($count = substr_count($condition, '?')) {

View File

@ -32,7 +32,7 @@ abstract class Base implements \ArrayAccess, \IteratorAggregate
public function getIterator() public function getIterator()
{ {
return new ArrayIterator($this->_get_array()); return new \ArrayIterator($this->_get_array());
} }
public function merge() public function merge()