Skip to content

Commit

Permalink
updated twig
Browse files Browse the repository at this point in the history
removed reference class
events calling the template syntax class should work now.
  • Loading branch information
danielkerr committed Jun 25, 2018
1 parent 3701155 commit c705bc4
Show file tree
Hide file tree
Showing 602 changed files with 11,139 additions and 9,613 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -24,6 +24,6 @@
"klarna/kco_rest": "^2.2",
"php": ">=5.4.0",
"zoujingli/wechat-php-sdk": ">=1.3.10",
"twig/twig": "1.24.2"
"twig/twig": "^2.4.8"
}
}
125 changes: 93 additions & 32 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion upload/catalog/controller/common/home.php
Expand Up @@ -14,4 +14,4 @@ public function index() {

$this->response->setOutput($this->load->view('common/home', $data));
}
}
}
21 changes: 12 additions & 9 deletions upload/catalog/controller/event/theme.php
@@ -1,5 +1,7 @@
<?php
class ControllerEventTheme extends Controller {
public $lambda = array();

public function index(&$route, &$args, &$template) {
if (!$this->config->get('theme_' . $this->config->get('config_theme') . '_status')) {
exit('Error: A theme has not been assigned to this store!');
Expand All @@ -18,24 +20,25 @@ public function index(&$route, &$args, &$template) {
$this->config->set('template_directory', 'default/template/');
}

// If you want to modify the output of the template we add a
$proxy = new Proxy();

// Attach to the template
$template->addFilter($proxy);
$template->addFilter('theme-override-' . $this->config->get('config_store_id'), $this);

$proxy->callback = function ($code) use ($route, $args, $directory) {
// If you want to modify the output of the template we add a
$this->lambda = function (&$code) use (&$route, &$args, &$directory) {
// If there is a theme override we should get it
$this->load->model('design/theme');

$theme_info = $this->model_design_theme->getTheme($route, $directory);

if ($theme_info) {
return html_entity_decode($theme_info['code'], ENT_QUOTES, 'UTF-8');
} else {
// Because we are using a proxy the arguments will always be an array.
return $code[0];
$code = html_entity_decode($theme_info['code'], ENT_QUOTES, 'UTF-8');
}
};
}

// Ridiculous we have to use these work around's because magic methods can not pass by reference!
public function callback(&$code) {
// Genius
($this->lambda)($code);
}
}
4 changes: 2 additions & 2 deletions upload/catalog/controller/event/translation.php
Expand Up @@ -2,9 +2,9 @@
class ControllerEventTranslation extends Controller {
public function index(&$route, &$key) {
$this->load->model('design/translation');

$results = $this->model_design_translation->getTranslations($route);

foreach ($results as $result) {
if (!$key) {
$this->language->set($result['key'], $result['value']);
Expand Down
4 changes: 2 additions & 2 deletions upload/system/config/catalog.php
Expand Up @@ -48,8 +48,8 @@
'event/language/after'
),
'view/*/before' => array(
500 => 'event/theme',
998 => 'event/language'
500 => 'event/theme',
998 => 'event/language'
),
'language/*/after' => array(
'event/translation'
Expand Down
22 changes: 12 additions & 10 deletions upload/system/engine/loader.php
@@ -1,10 +1,10 @@
<?php
/**
* @package OpenCart
* @author Daniel Kerr
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
* @license https://opensource.org/licenses/GPL-3.0
* @link https://www.opencart.com
* @package OpenCart
* @author Daniel Kerr
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
* @license https://opensource.org/licenses/GPL-3.0
* @link https://www.opencart.com
*/

/**
Expand Down Expand Up @@ -218,8 +218,9 @@ public function language($route, $key = '') {
}

protected function callback($route) {
return function ($args) use ($route) {
static $model;
return function () use ($route) {
// Grab args using function because we don't know the number of args being passed.
$args = func_get_args();

$route = preg_replace('/[^a-zA-Z0-9_\/]/', '', (string)$route);

Expand All @@ -237,13 +238,14 @@ protected function callback($route) {
// Store the model object
$key = substr($route, 0, strrpos($route, '/'));

if (!isset($model[$key])) {
$model[$key] = new $class($this->registry);
// Check if the model has already been initialised or not
if (!$this->registry->has($key)) {
$this->registry->set($key, new $class($this->registry));
}

$method = substr($route, strrpos($route, '/') + 1);

$callable = array($model[$key], $method);
$callable = array($this->registry->get($key), $method);

if (is_callable($callable)) {
$output = call_user_func_array($callable, $args);
Expand Down
14 changes: 2 additions & 12 deletions upload/system/engine/proxy.php
Expand Up @@ -31,18 +31,8 @@ public function __set($key, $value) {
}

public function __call($key, $args) {
$arg_data = array();

foreach ($args as $arg) {
if ($arg instanceof Reference) {
$arg_data[] = &$arg->getValue();
} else {
$arg_data[] = $arg;
}
}

if (isset($this->{$key})) {
return call_user_func_array($this->{$key}, array($args));
if (isset($this->{$key})) {
return call_user_func_array($this->{$key}, $args);
} else {
$trace = debug_backtrace();

Expand Down

0 comments on commit c705bc4

Please sign in to comment.