Post by straightlight » Mon Oct 06, 2014 12:01 am

I took a look in the system/engine/event.php and system/engine/action.php file,

The event engine file uses a new instance to call the Action method in a loop statement. This methodology is not suggested to use.

Here's my version of the event engine file:

Code: Select all

<?php
class Event {
	private $data = array();
	private $registry;

	public function __construct($registry) {
		$this->registry = $registry;
	}

	public function register($key, $action) {
		$this->data[$key][] = $action;
	}

	public function unregister($key, $action) {
		unset($this->data[$key]);
	}

	public function trigger($key, &$arg = array()) {
		if (isset($this->data[$key])) {
			$action = new Action($this->data[$key], $arg, $this->registry);
		}
	}
}
The $arg array is still being parameted without manipulation from the same method other than passing the array into the Action's construct method. The $registry object has also not been defined from the event file which could definitely cause an error on Windows IIS events. As for the Action method $route parameter, it should rather be passed as an array than a string in this case. Obviously, each Action method being called would require changes from string to array as the first parameter.

The $this->registry has also been passed has a third parameter in my modification so to avoid using a loop statement twice for the same action.

Here are the modifications:

Code: Select all

<?php
final class Action {
	private $file;
	private $class;
	private $method;
	private $args = array();	

	public function __construct($routes, $args = array(), $registry) {
		if (is_array($routes)) {
			foreach ($routes as $route) {
				$path = '';

				// Break apart the route
				$parts = explode('/', str_replace('../', '', (string)$route));

				foreach ($parts as $part) {
					$path .= $part;

					if (is_dir(DIR_APPLICATION . 'controller/' . $path)) {
						$path .= '/';

						array_shift($parts);

						continue;
					}

					$file = DIR_APPLICATION . 'controller/' . str_replace(array('../', '..\\', '..'), '', $path) . '.php';

					if (is_file($file)) {
						$this->file = $file;

						$this->class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $path);

						array_shift($parts);

						break;
					}
				}
				
				$this->execute($registry);
			}
		}

		if ($args) {
			$this->args = $args;
		}

		$method = array_shift($parts);

		if ($method) {
			$this->method = $method;
		} else {
			$this->method = 'index';
		}
	}

	public function execute($registry) {
		// Stop any magical methods being called
		if (substr($this->method, 0, 2) == '__') {
			return false;
		}

		if (is_file($this->file)) {
			include_once($this->file);

			$class = $this->class;

			$controller = new $class($registry);

			if (is_callable(array($controller, $this->method))) {
				return call_user_func(array($controller, $this->method), $this->args);
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
}
The action construct method still executes the execute method with the registry object passed on the third parameter of the Action method. Of course, the $registry object could also be removed from the methods below in the Action engine file by, still, defining the $registry object from the top of the constructor. However, I will let the OC team reflect on that one since both methodology, by passing a parameter to another method or to re-call the same object would be the same logic in this case.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by JNeuhoff » Mon Oct 06, 2014 5:47 am

What exactly are you trying to accomplish?

Can you break it down in clearer to understand portions?

And why would anyone use an IIS server on Windows?

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am

Who is online

Users browsing this forum: No registered users and 5 guests