public static function handle() { $which = implode('/', array_slice(\Core\Router::$uriParts, 1)); $base = realpath(BASEPATH . 'js') . DIRECTORY_SEPARATOR; $file = $base . $which; if (strpos(realpath($file), $base) !== 0 || !file_exists($file) || !preg_match('/.js$/', $file)) { http_response_code(404) && exit; } \Core\Headers::cache('text/javascript; charset=utf-8'); readfile($file); }
public static function handle() { if (!isset(\Core\Router::$uriParts[1])) { http_response_code(404) && exit; } $models = explode('-', \Core\Router::$uriParts[1]); \Core\Headers::cache('text/javascript; charset=utf-8'); ?> 'use strict'; var Models = Models || {}; <?php foreach ($models as $model) { if (!file_exists(BASEPATH . 'models/' . $model . '.php')) { continue; } $name = ucfirst($model); $class = '\\Models\\' . $name; ?> Models.<?php echo $name; ?> = Backbone.Model.extend({ idAttribute: "<?php echo call_user_func($class . '::PK'); ?> ", urlRoot: "<?php echo $model; ?> ", defaults: {<?php foreach ($class::$columns as $column => $attrs) { ?> "<?php echo $column; ?> ": null, <?php } ?> "<?php echo call_user_func($class . '::PK'); ?> ": null} }); <?php } }