From e649e829f5a25273f1a87b183404c35bb1452cb1 Mon Sep 17 00:00:00 2001 From: Erik Amaru Ortiz Date: Tue, 11 Mar 2014 18:05:50 -0400 Subject: [PATCH] More performance changes --- gulliver/core/Autoloader.php | 2 +- gulliver/system/class.bootstrap.php | 4 +- src/ProcessMaker/Core/SplClassLoader.php | 157 +++++++++++++++++++++++ src/ProcessMaker/WebApplication.php | 7 +- workflow/public_html/app.php | 12 +- 5 files changed, 170 insertions(+), 12 deletions(-) create mode 100644 src/ProcessMaker/Core/SplClassLoader.php diff --git a/gulliver/core/Autoloader.php b/gulliver/core/Autoloader.php index 813a3eca0..8bff595db 100644 --- a/gulliver/core/Autoloader.php +++ b/gulliver/core/Autoloader.php @@ -77,7 +77,7 @@ class Autoloader $classname = strtolower($classname); if (! file_exists($includeFile)) { - throw new Exception("Error, Autoloader can't register a inexisten file: " . $includeFile); + throw new Exception("Error, Autoloader can't register a non exists file: " . $includeFile); } if (strpos($classname, '*') !== false) { diff --git a/gulliver/system/class.bootstrap.php b/gulliver/system/class.bootstrap.php index a84c70b1b..d2f82000c 100644 --- a/gulliver/system/class.bootstrap.php +++ b/gulliver/system/class.bootstrap.php @@ -21,12 +21,12 @@ class Bootstrap { $className = strtolower($class); - if (array_key_exists($className, BootStrap::$includeClassPaths)) { + if (isset(BootStrap::$includeClassPaths[$className])) { require_once BootStrap::$includeClassPaths[$className]; return true; } - + return false; $classHasNamespaceSeparator = strpos($class, '\\') !== false ? true : false; foreach (BootStrap::$includePaths as $path) { diff --git a/src/ProcessMaker/Core/SplClassLoader.php b/src/ProcessMaker/Core/SplClassLoader.php new file mode 100644 index 000000000..eb018702b --- /dev/null +++ b/src/ProcessMaker/Core/SplClassLoader.php @@ -0,0 +1,157 @@ +. + */ + +/** + * SplClassLoader implementation that implements the technical interoperability + * standards for PHP 5.3 namespaces and class names. + * + * http://groups.google.com/group/php-standards/web/psr-0-final-proposal?pli=1 + * + * // Example which loads classes for the Doctrine Common package in the + * // Doctrine\Common namespace. + * $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine'); + * $classLoader->register(); + * + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @author Jonathan H. Wage + * @author Roman S. Borschel + * @author Matthew Weier O'Phinney + * @author Kris Wallsmith + * @author Fabien Potencier + */ +class SplClassLoader +{ + private $_fileExtension = '.php'; + private $_namespace; + private $_includePath; + private $_namespaceSeparator = '\\'; + + /** + * Creates a new SplClassLoader that loads classes of the + * specified namespace. + * + * @param string $ns The namespace to use. + */ + public function __construct($ns = null, $includePath = null) + { + $this->_namespace = $ns; + $this->_includePath = $includePath; + } + + /** + * Sets the namespace separator used by classes in the namespace of this class loader. + * + * @param string $sep The separator to use. + */ + public function setNamespaceSeparator($sep) + { + $this->_namespaceSeparator = $sep; + } + + /** + * Gets the namespace seperator used by classes in the namespace of this class loader. + * + * @return string + */ + public function getNamespaceSeparator() + { + return $this->_namespaceSeparator; + } + + /** + * Sets the base include path for all class files in the namespace of this class loader. + * + * @param string $includePath + */ + public function setIncludePath($includePath) + { + $this->_includePath = $includePath; + } + + /** + * Gets the base include path for all class files in the namespace of this class loader. + * + * @return string $includePath + */ + public function getIncludePath() + { + return $this->_includePath; + } + + /** + * Sets the file extension of class files in the namespace of this class loader. + * + * @param string $fileExtension + */ + public function setFileExtension($fileExtension) + { + $this->_fileExtension = $fileExtension; + } + + /** + * Gets the file extension of class files in the namespace of this class loader. + * + * @return string $fileExtension + */ + public function getFileExtension() + { + return $this->_fileExtension; + } + + /** + * Installs this class loader on the SPL autoload stack. + */ + public function register() + { + spl_autoload_register(array($this, 'loadClass')); + } + + /** + * Uninstalls this class loader from the SPL autoloader stack. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $className The name of the class to load. + * @return void + */ + public function loadClass($className) + { + if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) { + $fileName = ''; + $namespace = ''; + + if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) { + $namespace = substr($className, 0, $lastNsPos); + $className = substr($className, $lastNsPos + 1); + $fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; + } + + $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension; + + require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName; + } + } +} \ No newline at end of file diff --git a/src/ProcessMaker/WebApplication.php b/src/ProcessMaker/WebApplication.php index 27e5474a9..873f4f108 100644 --- a/src/ProcessMaker/WebApplication.php +++ b/src/ProcessMaker/WebApplication.php @@ -67,6 +67,7 @@ class WebApplication case self::SERVICE_API: $request = $this->parseApiRequestUri(); $this->loadEnvironment($request["workspace"]); + Util\Logger::log("API::Dispatching ".$_SERVER["REQUEST_METHOD"]." ".$request["uri"]); $this->dispatchApiRequest($request["uri"], $request["version"]); Util\Logger::log("API::End Dispatching ".$_SERVER["REQUEST_METHOD"]." ".$request["uri"]); @@ -279,10 +280,10 @@ class WebApplication \Bootstrap::registerClass('XmlForm_Field_SimpleText', PATH_GULLIVER . "class.xmlformExtension.php"); \Bootstrap::registerClass('XmlForm_Field', PATH_GULLIVER . "class.xmlform.php"); - \Bootstrap::registerDir('model', PATH_CORE . 'classes' . PATH_SEP . 'model'); - \Bootstrap::registerDir('rbac/model', PATH_RBAC_HOME . 'engine' . PATH_SEP . 'classes' . PATH_SEP . 'model'); + //\Bootstrap::registerDir('model', PATH_CORE . 'classes' . PATH_SEP . 'model'); + //\Bootstrap::registerDir('rbac/model', PATH_RBAC_HOME . 'engine' . PATH_SEP . 'classes' . PATH_SEP . 'model'); - \Bootstrap::LoadThirdParty("smarty/libs", "Smarty.class"); + //\Bootstrap::LoadThirdParty("smarty/libs", "Smarty.class"); \Bootstrap::registerSystemClasses(); diff --git a/workflow/public_html/app.php b/workflow/public_html/app.php index f87d59034..54c1ac6ab 100644 --- a/workflow/public_html/app.php +++ b/workflow/public_html/app.php @@ -32,16 +32,17 @@ try { /** @var Composer\Autoload\ClassLoader $loader */ $loader = include $rootDir . "vendor" . DIRECTORY_SEPARATOR . "autoload.php"; - $loader->add('', $rootDir . 'src/'); - $loader->add('', $rootDir . 'workflow/engine/src/'); - - \ProcessMaker\Util\Logger::log("---/Starts at: " . date("H:i:s:u")); + $loader->add("", $rootDir . 'src/'); + $loader->add("", $rootDir . 'workflow/engine/src/'); + $loader->add("", $rootDir . 'workflow/engine/classes/model/'); $app = new ProcessMaker\WebApplication(); + $app->setRootDir($rootDir); $app->setRequestUri($_SERVER['REQUEST_URI']); + $stat = $app->route(); - switch ($app->route()) + switch ($stat) { case ProcessMaker\WebApplication::RUNNING_WORKFLOW: include "sysGeneric.php"; @@ -51,7 +52,6 @@ try { break; } - \ProcessMaker\Util\Logger::log("--//End at: " . date("H:i:s:u")); } catch (Exception $e) { die($e->getMessage()); }