This commit is contained in:
Parziphal 2013-10-26 10:53:37 -05:00
parent 3190e22c97
commit a70f9cbfdb
13 changed files with 48 additions and 35 deletions

View File

@ -621,15 +621,18 @@ abstract class Base extends ActionController
if (!$ext) { if (!$ext) {
$template_name = $main_param; $template_name = $main_param;
if ($this->request()->format() == 'html') { # Unknown routes don't have format.
$format = $this->request()->format();
if (!$format || $format == 'html') {
$ext = 'php'; $ext = 'php';
} else { } else {
if ($this->request()->format() == 'xml') { if ($format == 'xml') {
$respParams['is_xml'] = true; $respParams['is_xml'] = true;
} }
$ext = [$this->request()->format(), 'php']; $ext = [$format, 'php'];
$this->response()->headers()->contentType($this->request()->format()); $this->response()->headers()->contentType($format);
} }
} else { } else {
$pinfo = pathinfo($main_param); $pinfo = pathinfo($main_param);

View File

@ -7,7 +7,9 @@ use Rails\ActionController\Base;
/** /**
* Basic use: * Basic use:
* Create a class that extends this one. * Create a class that extends this one.
* According to Exception or status, change the value of $template * According to Exception or status, change the value of $template by
* overriding handle(). Although this isn't needed for basic handling,
* default setup should work fine.
* The system will render that template. * The system will render that template.
*/ */
abstract class ExceptionHandler extends Base abstract class ExceptionHandler extends Base

View File

@ -73,13 +73,12 @@ class Template extends Base
private function build_template_file_name() private function build_template_file_name()
{ {
$views_path = Rails::config()->paths->views;
if (is_array($this->_params['extension'])) if (is_array($this->_params['extension']))
$ext = implode('.', $this->_params['extension']); $ext = implode('.', $this->_params['extension']);
else else
$ext = $this->_params['extension']; $ext = $this->_params['extension'];
$views_path = Rails::config()->paths->views;
$this->template_file_name = $views_path . DIRECTORY_SEPARATOR . $this->_params['template_name'] . '.' . $ext; $this->template_file_name = $views_path . DIRECTORY_SEPARATOR . $this->_params['template_name'] . '.' . $ext;
} }
} }

View File

@ -155,8 +155,9 @@ class Request
public function format() public function format()
{ {
if ($route = \Rails::application()->dispatcher()->router()->route()) if ($route = \Rails::application()->dispatcher()->router()->route()) {
return $route->format; return $route->format;
}
} }
/** /**

View File

@ -277,6 +277,8 @@ abstract class Base
return $this->getAttribute($prop); return $this->getAttribute($prop);
} elseif ($this->getAssociation($prop) !== null) { } elseif ($this->getAssociation($prop) !== null) {
return $this->loadedAssociations[$prop]; return $this->loadedAssociations[$prop];
} elseif ($getter = $this->getterExists($prop)) {
return $this->$getter();
} }
throw new Exception\RuntimeException( throw new Exception\RuntimeException(
@ -969,7 +971,6 @@ abstract class Base
} else { } else {
$setter = 'set' . ucfirst($attrName); $setter = 'set' . ucfirst($attrName);
} }
$reflection = self::getReflection(); $reflection = self::getReflection();
if ($reflection->hasMethod($setter) && $reflection->getMethod($setter)->isPublic()) { if ($reflection->hasMethod($setter) && $reflection->getMethod($setter)->isPublic()) {

View File

@ -194,6 +194,8 @@ trait AttributeMethods
if (!$attrs) { if (!$attrs) {
return; return;
} }
// if (get_called_class() == 'TagImplication')
// vpe('a', $attrs);
if (empty($options['without_protection'])) { if (empty($options['without_protection'])) {
$this->filterProtectedAttributes($attrs); $this->filterProtectedAttributes($attrs);
@ -210,6 +212,7 @@ trait AttributeMethods
// return; // return;
// } // }
// if (get_called_class() == 'TagImplication' && !in_array($propName, ['reason', 'creator_id', 'is_pending']))
// $inflector = Rails::services()->get('inflector'); // $inflector = Rails::services()->get('inflector');
// $reflection = new \ReflectionClass(get_called_class()); // $reflection = new \ReflectionClass(get_called_class());

View File

@ -6,9 +6,7 @@ use Rails\ActiveRecord\ActiveRecord;
/** /**
* This class is supposed to store all the * This class is supposed to store all the
* models created. Since they're objects, this * models created.
* serves as cache. We will save up memory and
* sql queries. This is supposed to be great.
*/ */
class Registry class Registry
{ {
@ -84,6 +82,7 @@ class Registry
public function search($id) public function search($id)
{ {
return;
$id = (string)$id; $id = (string)$id;
if (isset($this->_reg[$this->connection()][$this->_current_model]) && isset($this->_reg[$this->connection()][$this->_current_model][$id])) if (isset($this->_reg[$this->connection()][$this->_current_model]) && isset($this->_reg[$this->connection()][$this->_current_model][$id]))
return $this->_reg[$this->connection()][$this->_current_model][$id]; return $this->_reg[$this->connection()][$this->_current_model][$id];
@ -91,6 +90,7 @@ class Registry
public function register($model) public function register($model)
{ {
return;
$cn = get_class($model); $cn = get_class($model);
if (!$cn::table()->primaryKey()) { if (!$cn::table()->primaryKey()) {

View File

@ -75,11 +75,16 @@ class Base
$paths = Rails::config()->paths; $paths = Rails::config()->paths;
$paths->application->setPath($basePath)->setBasePaths([]); $paths->application->setPath($basePath)->setBasePaths([]);
$trait = $basePath . '/traits/AdminController.php'; $trait = $basePath . '/traits/AdminController.php';
require_once $trait; require_once $trait;
$trait = $basePath . '/traits/ApplicationController.php'; $trait = $basePath . '/traits/ApplicationController.php';
require_once $trait; require_once $trait;
$panelAppController = $basePath . '/controllers/ApplicationController.php';
require_once $panelAppController;
$panelController = $basePath . '/controllers/AdminController.php';
require_once $panelController;
Rails::loader()->addPaths([ Rails::loader()->addPaths([
$paths->helpers->toString(), $paths->helpers->toString(),
@ -176,8 +181,9 @@ class Base
if ($this->dispatcher()->router()->route()->assets_route()) { if ($this->dispatcher()->router()->route()->assets_route()) {
Rails::assets()->server()->dispatch_request(); Rails::assets()->server()->dispatch_request();
} else { } else {
if ($this->dispatcher()->router()->route()->rails_admin()) if ($this->dispatcher()->router()->route()->rails_admin()) {
$this->setPanelConfig(); self::setPanelConfig();
}
$this->_load_controller(); $this->_load_controller();
$this->controller()->run_request_action(); $this->controller()->run_request_action();
} }

View File

@ -54,7 +54,9 @@ class File
if (preg_match('/^\w:/', $path) || strpos($path, '/') === 0) { if (preg_match('/^\w:/', $path) || strpos($path, '/') === 0) {
$path = str_replace('\\', '/', $path); $path = str_replace('\\', '/', $path);
foreach ($this->assets_paths() as $asset_path) { foreach ($this->assets_paths() as $asset_path) {
$asset_path = str_replace('\\', '/', $asset_path);
if (strpos($path, $asset_path) === 0) { if (strpos($path, $asset_path) === 0) {
$this->baseDir = $asset_path; $this->baseDir = $asset_path;
$path = substr($path, strlen($asset_path) + 1); $path = substr($path, strlen($asset_path) + 1);
@ -223,4 +225,4 @@ class File
$this->subDirs = $subDirs; $this->subDirs = $subDirs;
} }
} }

View File

@ -77,7 +77,7 @@ $config->active_record = [
$config->action_view = [ $config->action_view = [
'layout' => 'application', 'layout' => 'application',
'suffix' => 'phtml' // 'suffix' => 'phtml'
]; ];
$config->plugins = []; $config->plugins = [];

View File

@ -81,21 +81,16 @@ class AdminController extends ApplicationController
Rails::assets()->compileFile($file); Rails::assets()->compileFile($file);
} }
} catch (Rails\Assets\Parser\Javascript\ClosureApi\Exception\ErrorsOnCodeException $e) { } catch (Rails\Assets\Parser\Javascript\ClosureApi\Exception\ErrorsOnCodeException $e) {
if ($e instanceof Rails\Assets\Parser\Javascript\ClosureApi\Exception\ErrorsOnCodeException) { Rails::log()->error(
Rails::log()->error( sprintf(
sprintf( "[%s] Asset compilation error for file %s\n%s",
"[%s] Asset compilation error for file %s\n%s", date('Y-m-d H:i:s'),
date('Y-m-d H:i:s'), $file_path . '.' . $ext,
$file_path . '.' . $ext, $e->getMessage()
$e->getMessage() )
) );
); $message = sprintf("ClosureAPI reported an error - JS file was saved to %s for verfications, error was logged.<br /><pre>%s</pre>",
$message = sprintf("ClosureAPI reported an error - JS file was saved to %s for verfications, error was logged.<br /><pre>%s</pre>", Rails\Assets\Parser\Javascript\ClosureApi\ClosureApi::errorFile(), $e->getMessage());
Rails\Assets\Parser\Javascript\ClosureApi\ClosureApi::errorFile(), $e->getMessage());
} else {
// throw $e;
// $message = sprintf('%s raised: %s', get_class($e), $e->getMessage());
}
$this->error = $message; $this->error = $message;
} }

View File

@ -16,7 +16,7 @@ class SystemExit
public function unregister($name) public function unregister($name)
{ {
if (isset($this->callbacks[$name])) { if (isset($this->callbacks[$name])) {
unset($this->callbacks[$name]; unset($this->callbacks[$name]);
return true; return true;
} else { } else {
return false; return false;
@ -29,4 +29,4 @@ class SystemExit
call_user_func($callback); call_user_func($callback);
} }
} }
} }

View File

@ -12,8 +12,9 @@ use FilesystemIterator;
abstract class FileTools abstract class FileTools
{ {
/** /**
* Deletes all files directories recursively from a directory. * Deletes all files and directories recursively from a directory.
* Note that existance of the dir must be previously checked. * Note that existance of the dir must be previously checked.
* The directory isn't deleted.
* SO.com:1407338 * SO.com:1407338
*/ */
static public function emptyDir($dirpath) static public function emptyDir($dirpath)