From 49e242117161f611920d7b50d0ad832ede199bb3 Mon Sep 17 00:00:00 2001 From: Parziphal Date: Sun, 13 Oct 2013 21:45:38 -0500 Subject: [PATCH] nighty commit --- lib/Rails/ActionController/Base.php | 19 +- lib/Rails/ActionDispatch/Http/Parameters.php | 17 +- lib/Rails/ActionView/Helper/Methods/Tag.php | 12 +- .../WillPaginate.delete/AbstractRenderer.php | 168 ------------------ .../WillPaginate.delete/BootstrapRenderer.php | 52 ------ .../WillPaginate.delete/LegacyRenderer.php | 8 - lib/Rails/ActionView/Template.php | 7 + lib/Rails/ActionView/Xml.php | 4 +- .../Adapter/MySql/QueryBuilder.php | 10 +- lib/Rails/ArrayHelper/Base.php | 2 +- 10 files changed, 49 insertions(+), 250 deletions(-) delete mode 100755 lib/Rails/ActionView/Helper/WillPaginate.delete/AbstractRenderer.php delete mode 100755 lib/Rails/ActionView/Helper/WillPaginate.delete/BootstrapRenderer.php delete mode 100755 lib/Rails/ActionView/Helper/WillPaginate.delete/LegacyRenderer.php diff --git a/lib/Rails/ActionController/Base.php b/lib/Rails/ActionController/Base.php index a9c51ef..4e4dd0d 100755 --- a/lib/Rails/ActionController/Base.php +++ b/lib/Rails/ActionController/Base.php @@ -602,7 +602,7 @@ abstract class Base extends ActionController switch ($render_type) { case 'action': # 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()) // $path = implode('/', $route->namespaces()) . '/' . $path; @@ -611,7 +611,10 @@ abstract class Base extends ActionController # Fallthrough case 'template': + $respParams = []; + $layout = !empty($this->render_params['layout']) ? $this->render_params['layout'] : $this->layout; + $respParams['layout'] = $layout; $ext = pathinfo($main_param, PATHINFO_EXTENSION); @@ -621,8 +624,9 @@ abstract class Base extends ActionController if ($this->request()->format() == 'html') { $ext = 'php'; } else { - if ($this->request()->format() == 'xml') - $this->_response_params['is_xml'] = true; + if ($this->request()->format() == 'xml') { + $respParams['is_xml'] = true; + } $ext = [$this->request()->format(), 'php']; $this->response()->headers()->contentType($this->request()->format()); @@ -639,11 +643,10 @@ abstract class Base extends ActionController $template_name = $pinfo['dirname'] . '/' . $pinfo['filename']; } - $this->_response_params = [ - 'layout' => $layout, - 'template_name' => $template_name, - 'extension' => $ext - ]; + $respParams['template_name'] = $template_name; + $respParams['extension'] = $ext; + + $this->_response_params = $respParams; # Here we could choose a different responder according to extensions(?). $class = 'Rails\ActionController\Response\Template'; diff --git a/lib/Rails/ActionDispatch/Http/Parameters.php b/lib/Rails/ActionDispatch/Http/Parameters.php index a69722b..c7396a5 100755 --- a/lib/Rails/ActionDispatch/Http/Parameters.php +++ b/lib/Rails/ActionDispatch/Http/Parameters.php @@ -81,19 +81,20 @@ class Parameters implements \IteratorAggregate if ($var) { global ${$var}; - if (is_array(${$var}[$prop])) { + // if (is_array(${$var}[$prop])) { // if (isset($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 $this->$prop; - } elseif (is_object(${$var}[$prop])) { - $this->$prop = ${$var}[$prop]; - $ret = $this->$prop; - } else { + // return + // return $this->$prop; + // } elseif (is_object(${$var}[$prop])) { + // $this->$prop = ${$var}[$prop]; + // $ret = $this->$prop; + // } else { $ret = ${$var}[$prop]; - } + // } } else { if (isset($this->putVars[$prop])) $ret = $this->putVars[$prop]; diff --git a/lib/Rails/ActionView/Helper/Methods/Tag.php b/lib/Rails/ActionView/Helper/Methods/Tag.php index f84849f..2c2f46b 100755 --- a/lib/Rails/ActionView/Helper/Methods/Tag.php +++ b/lib/Rails/ActionView/Helper/Methods/Tag.php @@ -8,10 +8,20 @@ trait Tag 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) { 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); } diff --git a/lib/Rails/ActionView/Helper/WillPaginate.delete/AbstractRenderer.php b/lib/Rails/ActionView/Helper/WillPaginate.delete/AbstractRenderer.php deleted file mode 100755 index 322956d..0000000 --- a/lib/Rails/ActionView/Helper/WillPaginate.delete/AbstractRenderer.php +++ /dev/null @@ -1,168 +0,0 @@ -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' => '← ' . $this->helper->t('actionview.helper.will_paginate.previous'), - 'next_label' => $this->helper->t('actionview.helper.will_paginate.next') . ' →', - '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 ''; - } - - 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(); - } -} \ No newline at end of file diff --git a/lib/Rails/ActionView/Helper/WillPaginate.delete/BootstrapRenderer.php b/lib/Rails/ActionView/Helper/WillPaginate.delete/BootstrapRenderer.php deleted file mode 100755 index 66af10e..0000000 --- a/lib/Rails/ActionView/Helper/WillPaginate.delete/BootstrapRenderer.php +++ /dev/null @@ -1,52 +0,0 @@ -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('…', "#"), ['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']); - } -} \ No newline at end of file diff --git a/lib/Rails/ActionView/Helper/WillPaginate.delete/LegacyRenderer.php b/lib/Rails/ActionView/Helper/WillPaginate.delete/LegacyRenderer.php deleted file mode 100755 index 8c843c0..0000000 --- a/lib/Rails/ActionView/Helper/WillPaginate.delete/LegacyRenderer.php +++ /dev/null @@ -1,8 +0,0 @@ - file_name.xml.php + // * If null, no extra extension is appended. + // */ + // private $tplExtension; + /** * $render_params could be: * - A string, that will be taken as "file". diff --git a/lib/Rails/ActionView/Xml.php b/lib/Rails/ActionView/Xml.php index bde9bdc..c2183ab 100755 --- a/lib/Rails/ActionView/Xml.php +++ b/lib/Rails/ActionView/Xml.php @@ -45,10 +45,10 @@ class Xml if (is_string($content)) $this->_buffer .= $content; - elseif ($content instanceof Closure) + elseif ($content instanceof \Closure) $this->_buffer .= $content(); else - throw new Exception\InvalidArgumentError( + throw new Exception\InvalidArgumentException( sprintf('Expecting Closure or string as third argument, %s passed.', gettype($content)) ); diff --git a/lib/Rails/ActiveRecord/Adapter/MySql/QueryBuilder.php b/lib/Rails/ActiveRecord/Adapter/MySql/QueryBuilder.php index b89cd98..918b6d2 100755 --- a/lib/Rails/ActiveRecord/Adapter/MySql/QueryBuilder.php +++ b/lib/Rails/ActiveRecord/Adapter/MySql/QueryBuilder.php @@ -71,8 +71,14 @@ class QueryBuilder extends AbstractQueryBuilder # Case: ["foo" => $foo, "bar_baz" => $bar]; if (is_array($condition)) { foreach ($condition as $column => $value) { - $where[] = $column . ' = ?'; - $where_params[] = $value; + if (is_array($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 { if ($count = substr_count($condition, '?')) { diff --git a/lib/Rails/ArrayHelper/Base.php b/lib/Rails/ArrayHelper/Base.php index b4bf156..41d6cea 100755 --- a/lib/Rails/ArrayHelper/Base.php +++ b/lib/Rails/ArrayHelper/Base.php @@ -32,7 +32,7 @@ abstract class Base implements \ArrayAccess, \IteratorAggregate public function getIterator() { - return new ArrayIterator($this->_get_array()); + return new \ArrayIterator($this->_get_array()); } public function merge()