Merge branch 'performance'

Conflicts:
	workflow/public_html/sysGeneric.php
This commit is contained in:
Erik Amaru Ortiz
2014-03-12 18:33:22 -04:00
19 changed files with 2826 additions and 888 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,82 @@
<?php
namespace Maveriks\Pattern\Mvc;
class PhtmlView extends View
{
public static $blocks = array();
private static $instance;
private static $extend = '';
public function __construct($tpl = '')
{
parent::__construct($tpl);
}
//Wrapped
public function render()
{
self::$instance = $this;
$tplFile = $this->getTpl();
if (empty($tplFile)) {
throw new \Exception('ERROR: template file was not set!');
}
foreach ($this->getTemplateDir() as $dir) {
if (file_exists($dir . DIRECTORY_SEPARATOR . $tplFile)) {
$tplFile = $dir . DIRECTORY_SEPARATOR . $tplFile;
break;
}
}
if (! file_exists($tplFile)) {
throw new \Exception('ERROR: template file '.$tplFile.' does not exist!');
}
extract($this->data);
include $tplFile;
if (! empty(self::$extend)) {
$tplFile = ''; //$this->getTemplateDir() . DIRECTORY_SEPARATOR . self::$extend . '.phtml';
foreach ($this->getTemplateDir() as $dir) {
if (file_exists($dir . DIRECTORY_SEPARATOR . self::$extend . '.phtml')) {
$tplFile = $dir . DIRECTORY_SEPARATOR . self::$extend . '.phtml';
break;
}
}
if (! file_exists($tplFile)) {
throw new \Exception('ERROR: Layout template file '.$tplFile.' does not exist!');
}
extract($this->data);
include $tplFile;
}
}
static public function extend($name)
{
self::$extend = $name;
}
static public function block($name, $default = '')
{
if (is_string($default)) {
if (array_key_exists($name, self::$blocks)) {
$callback = self::$blocks[$name];
$callback();
} else {
return $default;
}
return;
} elseif ($default instanceof \Closure) {
self::$blocks[$name] = $default;
}
}
}

View File

@@ -0,0 +1,299 @@
<?php
namespace Maveriks\Pattern\Mvc;
/**
* View
*
* This is the parent class to support view at MVC Pattern
* (Adapted version from PhpAlchemy project)
*
* @version 1.0
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com>
* @link https://github.com/phpalchemy/phpalchemy
* @copyright Copyright 2012 Erik Amaru Ortiz
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @package Maveriks\Pattern\Mvc
*/
abstract class View
{
/**
* Contains all variables that are available on template file
*
* @var array
*/
protected $data = array();
/**
* Contains the absolute paths where templates are stored
*
* @var array
*/
protected $templateDir = array();
/**
* Contains the absolute path where the engine store the cache files
*
* @var string
*/
protected $cacheDir = '';
/**
* String to store the output string that is sent by http response
*
* @var string
*/
protected $content = '';
/**
* Relative path of template file
*
* @var string
*/
protected $tpl = '';
/**
* Cache flag to specify if templating cache is enabled or not
*
* @var string
*/
protected $cache = false;
/**
* Charset Encodig
*
* @var string
*/
protected $charset = 'UTF-8';
/**
* Debug flag to indicate to template engine is a debug environment
* Defaults false
*
* @var bool
*/
public $debug = false;
/**
* @param string $tpl template file
*/
public function __construct($tpl = '')
{
$this->tpl = $tpl;
}
/**
* Sets template file path (absolute or partial path)
*
* @param string $tpl contains the path of template file
*/
public function setTpl($tpl)
{
$this->tpl = $tpl;
}
/**
* Gets template file
*/
public function getTpl()
{
return $this->tpl;
}
/**
* Sets the base path where the engine can be find all templates
*
* @param string $path contains the absolute path where templates are stored
*/
public function setTemplateDir($path)
{
$this->templateDir[] = $path;
}
/**
* Gets the templates files base path
*
* @return array returns the templates base path
*/
public function getTemplateDir()
{
return $this->templateDir;
}
/**
* Sets cache directory path
*
* @param string $path cache directory path
*/
public function setCacheDir($dir)
{
$this->cacheDir = $dir;
if (! is_dir($this->cacheDir)) {
$this->createDir($this->cacheDir);
}
}
/**
* Gets cache directory path
*
* @return string contains cache directory path
*/
public function getCacheDir()
{
return $this->cacheDir;
}
/**
* Enable/Disable templating cache
*
* @param bool $value boolean value to enable or not cache
*/
public function enableCache($value)
{
$this->cache = $value ? true: false;
}
/**
* Enable/Disable debug mode of template engine
*
* @param bool $value boolean value to enable or not debug mode
*/
public function enableDebug($value)
{
$this->debug = $value ? true: false;
}
/**
* Sets charset encoding for template engine
* @param string $charset conatins a valid charset like UTF-8, ISO-8859-1 (latin), etc.
*/
public function setCharset($charset)
{
$this->charset = $charset;
}
/**
* Gets charset encoding
*
* @return string charset encoding
*/
public function getCharset()
{
return $this->charset;
}
/**
* Alias of method assign()
*
* @param string $name name or key to store teh value passed
* @param string $value variable value
*/
public function set($name, $value = null)
{
$this->assign($name, $value);
}
/**
* Assings a variable to the template file
*
* @param string $name name or key to store teh value passed
* @param string $value variable value
*/
public function assign($name, $value = null)
{
if (is_string($name)) {
return $this->data[$name] = $value;
}
if (is_array($name)) {
$this->assignFromArray($name);
return null;
}
throw new \InvalidArgumentException("Invalid data type for key, '" .gettype($name) . "' given.");
}
/**
* Gets a variable that was previously assigned
*
* @param string $name name or key to store teh value passed
* @param string $value variable value
*/
public function get($name)
{
if (!isset($this->data[$name])) {
throw new \InvalidArgumentException("Variable '$name' doesn't exist.");
}
return $this->data[$name];
}
public function exists($name)
{
return array_key_exists($name, $this->data);
}
/**
* Gets final template parsed output string
*
* @return string parsed output
*/
public function getOutput()
{
$output = '';
\ob_start();
$this->render();
$output = \ob_get_contents();
\ob_end_clean();
return $output;
}
/**
* Render the output string (To override by child class)
*/
abstract public function render();
/**
* Multiple variable assignment
*
* @param array $data associative array conatining variables, the keys are used as variables names
*/
protected function assignFromArray($data)
{
if (! is_array($data)) {
throw new \InvalidArgumentException(
"Invalid data type: argument should be array, '" .gettype($data) . "' given."
);
}
foreach ($data as $key => $value) {
$this->assign($key, $value);
}
}
protected function createDir($strPath, $rights = 0777)
{
$folderPath = array($strPath);
$oldumask = umask(0);
while (!@is_dir(dirname(end($folderPath)))
&& dirname(end($folderPath)) != '/'
&& dirname(end($folderPath)) != '.'
&& dirname(end($folderPath)) != ''
) {
array_push($folderPath, dirname(end($folderPath)));
}
while ($parentFolderPath = array_pop($folderPath)) {
if (! @is_dir($parentFolderPath)) {
if (! @mkdir($parentFolderPath, $rights)) {
throw new \Exception("Templating Engine Error: Can't create folder '$parentFolderPath'");
}
}
}
umask($oldumask);
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace Maveriks\Util;
class ClassLoader
{
private static $includePath = array();
private static $includePathNs = array();
protected static $instance;
/**
* Creates a new <tt>SplClassLoader</tt> that loads classes of the
* specified namespace.
*
* @param string $ns The namespace to use.
*/
public function __construct()
{
defined("DS") || define("DS", DIRECTORY_SEPARATOR);
defined("NS") || define("NS", "\\");
spl_autoload_register(array($this, 'loadClass'));
}
/**
* @return \Maveriks\Util\ClassLoader
*/
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Gets the base include path for all class files in the namespace of this class loader.
*
* @return string $includePath
*/
public function getIncludePaths()
{
return self::$includePath;
}
/**
* Uninstalls this class loader from the SPL autoloader stack.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
public function add($sourceDir, $namespace = "")
{
if (empty($namespace)) {
self::$includePath[] = $sourceDir . (substr($sourceDir, -1) == DS ? "" : DS);
} else {
self::$includePathNs[$namespace] = $sourceDir . (substr($sourceDir, -1) == DS ? "" : DS);
}
}
function loadClass($className)
{
$classPath = str_replace(NS, DS, $className);
if (false !== strpos($className, NS)) {// has namespace?
$lastPos = strpos($className, NS);
$mainNs = substr($className, 0, $lastPos);
if (isset(self::$includePathNs[$mainNs])) {
if (file_exists(self::$includePathNs[$mainNs] . $classPath . ".php")) {
require self::$includePathNs[$mainNs] . $classPath . ".php";
return true;
} else {
return false;
}
}
}
foreach (self::$includePath as $path) {
$filename = $path . $classPath . ".php";
//var_dump($filename);
if (file_exists($filename)) {
require $filename;
return true;
}
}
return false;
}
/**
* Loads the given class or interface.
*
* @param string $className The name of the class to load.
* @return void
*/
public function loadClass2($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;
}
}
}

View File

@@ -0,0 +1,128 @@
<?php
namespace Maveriks\Util;
class Common
{
/**
* Recursive version of glob php standard function
*
* @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmail.com>
* @param string $pattern pattern for native glob function
* @param int|string $flags any valid flag for glob function
* @param bool $onlyFiles to filter return array with only matched files, or all matched results
* @return array array containing the recursive glob results
*
* Example:
*
* Common::rglob("/example/path/*");
*
* it will returns:
*
* Array
* (
* [0] => /example/path/README.txt
* [1] => /example/path/composer.json
* [4] => /example/path/one/one_text.txt
* [6] => /example/path/two/two_text.txt
* [7] => /example/path/two/two_one/two_one_text.txt
* [8] => /example/path/two/two_one/build.json
* )
*
* Example 2:
*
* Common::rglob("/example/path/*.json");
*
* It will returns:
*
* Array
* (
* [0] => /example/path/composer.json
* [1] => /example/path/two/two_one/build.json
* )
*/
public static function rglob($pattern, $flags = 0, $onlyFiles = false)
{
$singlePattern = basename($pattern);
if (strpos($singlePattern, "*") !== false) {
$path = rtrim(str_replace($singlePattern, "", $pattern), DIRECTORY_SEPARATOR);
} else {
$singlePattern = "";
$path = $pattern;
}
$files = glob("$path/$singlePattern", $flags);
$dirs = glob("$path/*", GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT);
foreach ($dirs as $dir) {
$files = array_merge($files, self::rglob("$dir/$singlePattern", $flags));
}
if ($onlyFiles) {
$files = array_filter($files, function($v) { return is_dir($v) ? false : true;});
}
return $files;
}
/**
* Returns the last version given a pattern of file name
*
* @param string $pattern a valid pattern for glob(...) native function
* @param int $flag php flags for glob(...) native function
* @return int|string
*
* Example:
* - Given the following files inside a directory:
* /example/path/myApplication-v1.tar
* /example/path/myApplication-v2.tar
* /example/path/myApplication-v3.tar
* /example/path/myApplication-v5.tar
* /example/path/myApplication-v7.tar
*
* $lastVer = ProcessMaker\Util\Common::getLastVersion("/example/path/myApplication-*.tar");
*
* It will returns: 7
*/
public static function getLastVersion($pattern, $flag = 0)
{
$files = glob($pattern, $flag);
$maxVersion = 0;
$pattern = str_replace("*", '([0-9\.]+)', basename($pattern));
foreach ($files as $file) {
$filename = basename($file);
if (preg_match('/'.$pattern.'/', $filename, $match)) {
if ($maxVersion < $match[1]) {
$maxVersion = $match[1];
}
}
}
return $maxVersion;
}
public static function parseIniFile($filename)
{
$data = @parse_ini_file($filename, true);
$result = array();
if ($data === false) {
throw new \Exception("Error parsing ini file: $filename");
}
foreach ($data as $key => $value) {
if (strpos($key, ':') !== false) {
list($key, $subSection) = explode(':', $key);
$result[trim($key)][trim($subSection)] = $value;
} else {
$result[$key] = $value;
}
}
return $result;
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace Maveriks\Util;
/**
* Singleton Class Logger
*
* This Utility is useful to log local messages
* @package ProcessMaker\Util
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com, erik@colosa.com>
*/
class Logger
{
private static $instance;
private $logFile;
private $fp;
protected function __construct()
{
$this->logFile = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'processmaker.log';
if (! file_exists($this->logFile)) {
if (! touch($this->logFile)) {
error_log("ProcessMaker Log file can't be created!");
}
chmod($this->logFile, 0777);
}
$this->fp = fopen($this->logFile, "a+");
}
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new Logger();
}
return self::$instance;
}
public function setLogLine()
{
$args = func_get_args();
$this->setLog(date('Y-m-d H:i:s') . " ");
foreach ($args as $str) {
$this->setLog((is_string($str) ? $str : var_export($str, true)) . PHP_EOL);
}
}
public function setLogInline()
{
$args = func_get_args();
$this->setLog(date('Y-m-d H:i:s') . " ");
foreach ($args as $str) {
$this->setLog((is_string($str) ? $str : var_export($str, true)) . " ");
}
}
public function setLog($str)
{
fwrite($this->fp, $str);
}
public static function log()
{
$me = Logger::getInstance();
$args = func_get_args();
call_user_func_array(array($me, 'setLogLine'), $args);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,88 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="robots" content="noindex,nofollow" />
<title>Runtime Exception.</title>
<style>
/* Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html */
html{ color:#000;background:#FFF; }body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{ margin:0;padding:0; }table{ border-collapse:collapse;border-spacing:0; }fieldset,img{ border:0; }address,caption,cite,code,dfn,em,strong,th,var{ font-style:normal;font-weight:normal; }li{ list-style:none; }caption,th{ text-align:left; }h1,h2,h3,h4,h5,h6{ font-size:100%;font-weight:normal; }q:before,q:after{ content:''; }abbr,acronym{ border:0;font-variant:normal; }sup{ vertical-align:text-top; }sub{ vertical-align:text-bottom; }input,textarea,select{ font-family:inherit;font-size:inherit;font-weight:inherit; }input,textarea,select{ *font-size:100%; }legend{ color:#000; }
html { background: #eee; padding: 10px }
body { font: 11px Verdana, Arial, sans-serif; color: #333 }
img { border: 0; }
.clear { clear:both; height:0; font-size:0; line-height:0; }
.clear_fix:after { display:block; height:0; clear:both; visibility:hidden; }
.clear_fix { display:inline-block; }
* html .clear_fix { height:1%; }
.clear_fix { display:block; }
#content { width:970px; margin:0 auto; }
.sf-exceptionreset, .sf-exceptionreset .block { margin: auto }
.sf-exceptionreset abbr { border-bottom: 1px dotted #000; cursor: help; }
.sf-exceptionreset p { font-size:14px; line-height:20px; color:#868686; padding-bottom:20px }
.sf-exceptionreset strong { font-weight:bold; }
.sf-exceptionreset a { color:#6c6159; }
.sf-exceptionreset a img { border:none; }
.sf-exceptionreset a:hover { text-decoration:underline; }
.sf-exceptionreset em { font-style:italic; }
.sf-exceptionreset h1, .sf-exceptionreset h2 { font: 20px Georgia, "Times New Roman", Times, serif }
.sf-exceptionreset h2 span { background-color: #fff; color: #333; padding: 6px; float: left; margin-right: 10px; }
.sf-exceptionreset .traces li { font-size:12px; padding: 2px 4px; list-style-type:decimal; margin-left:20px; }
.sf-exceptionreset .block { background-color:#FFFFFF; padding:10px 28px; margin-bottom:20px;
-webkit-border-bottom-right-radius: 16px;
-webkit-border-bottom-left-radius: 16px;
-moz-border-radius-bottomright: 16px;
-moz-border-radius-bottomleft: 16px;
border-bottom-right-radius: 16px;
border-bottom-left-radius: 16px;
border-bottom:1px solid #ccc;
border-right:1px solid #ccc;
border-left:1px solid #ccc;
}
.sf-exceptionreset .block_exception { background-color:#ddd; color: #333; padding:20px;
-webkit-border-top-left-radius: 16px;
-webkit-border-top-right-radius: 16px;
-moz-border-radius-topleft: 16px;
-moz-border-radius-topright: 16px;
border-top-left-radius: 16px;
border-top-right-radius: 16px;
border-top:1px solid #ccc;
border-right:1px solid #ccc;
border-left:1px solid #ccc;
}
.sf-exceptionreset li a { background:none; color:#868686; text-decoration:none; }
.sf-exceptionreset li a:hover { background:none; color:#313131; text-decoration:underline; }
.sf-exceptionreset ol { padding: 10px 0; }
.sf-exceptionreset h1 { background-color:#FFFFFF; padding: 15px 28px; margin-bottom: 20px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<div id="content" class="sf-exceptionreset">
<h1>System Exception.</h1>
<div class="block_exception clear_fix">
<h2>
<abbr title="RuntimeException">RuntimeException</abbr>:
<?php echo $message?>
</h2>
</div>
<div class="block">
<ol class="traces list_exception">
<?php foreach ($exception->getTrace() as $line ) {
if (isset($line['class'])) {
echo '<li>At ' . $line['class'].$line['type'].$line['function']
. '()</b> <br/>in '.$line['file'].' line '.$line['line'].'</li>';
} else{
echo '<li>At ' . $line['function'] . '() in '.$line['file'].' line '.$line['line'].'</li>';
}
} ?>
</ol>
</div>
</div>
</body>
</html>

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -0,0 +1,111 @@
<?php
namespace ProcessMaker\Core;
class ClassLoader
{
private static $includePath;
protected static $instance;
/**
* Creates a new <tt>SplClassLoader</tt> that loads classes of the
* specified namespace.
*
* @param string $ns The namespace to use.
*/
public function __construct()
{
defined("DS") || define("DS", DIRECTORY_SEPARATOR);
defined("NS") || define("NS", "\\");
spl_autoload_register(array($this, 'loadClass'));
}
/**
* @return \ProcessMaker\Core\ClassLoader
*/
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Gets the base include path for all class files in the namespace of this class loader.
*
* @return string $includePath
*/
public function getIncludePaths()
{
return self::$includePath;
}
/**
* Uninstalls this class loader from the SPL autoloader stack.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
public function add($namespace, $sourceDir)
{
if (empty($namespace)) {
self::$includePath[] = $sourceDir . (substr($sourceDir, -1) == DS ? "" : DS);
} else {
self::$includePath[$namespace] = $sourceDir . (substr($sourceDir, -1) == DS ? "" : DS);
}
}
function loadClass($className)
{
var_dump(self::$includePath); die;
$className = ltrim($className, NS);
foreach (self::$includePath as $path) {
if ($lastPos = strrpos($className, NS)) {
$namespace = substr($className, 0, $lastPos);
var_dump($namespace);
$className = substr($className, $lastPos + 1);
$subpath = str_replace(NS, DS, $namespace) . DS;
}
$filename = $path . $subpath . $className . ".php";
var_dump($filename);
if (file_exists($filename)) {
require $filename . ".php";
return true;
}
}
return false;
}
/**
* Loads the given class or interface.
*
* @param string $className The name of the class to load.
* @return void
*/
public function loadClass2($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;
}
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace ProcessMaker\Util;
/**
* Singleton Class Logger
*
* This Utility is useful to log local messages
* @package ProcessMaker\Util
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com, erik@colosa.com>
*/
class Logger
{
private static $instance;
private $logFile;
private $fp;
protected function __construct()
{
$this->logFile = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'processmaker.log';
if (! file_exists($this->logFile)) {
if (! touch($this->logFile)) {
error_log("ProcessMaker Log file can't be created!");
}
chmod($this->logFile, 0777);
}
$this->fp = fopen($this->logFile, "a+");
}
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new Logger();
}
return self::$instance;
}
public function setLogLine()
{
$args = func_get_args();
$this->setLog(date('Y-m-d H:i:s') . " ");
foreach ($args as $str) {
$this->setLog((is_string($str) ? $str : var_export($str, true)) . PHP_EOL);
}
}
public function setLogInline()
{
$args = func_get_args();
$this->setLog(date('Y-m-d H:i:s') . " ");
foreach ($args as $str) {
$this->setLog((is_string($str) ? $str : var_export($str, true)) . " ");
}
}
public function setLog($str)
{
fwrite($this->fp, $str);
}
public static function log()
{
$me = Logger::getInstance();
$args = func_get_args();
call_user_func_array(array($me, 'setLogLine'), $args);
}
}

File diff suppressed because it is too large Load Diff

19
virtualhost.conf.example Normal file
View File

@@ -0,0 +1,19 @@
<VirtualHost *:80>
ServerName 127.0.0.1
DocumentRoot /example/path/to/processmaker/workflow/public_html
<Directory /example/path/to/processmaker/workflow/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
ExpiresActive On
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
</Directory>
</VirtualHost>

View File

@@ -1,6 +1,7 @@
<?php
global $RBAC;
$result = new StdClass();
switch ($_POST['action']) {
case 'countryList':

View File

@@ -1,107 +1,6 @@
<?php
namespace ProcessMaker\Util;
class Common
class Common extends \Maveriks\Util\Common
{
/**
* Recursive version of glob php standard function
*
* @author Erik Amaru Ortiz <erik@colosa.com, aortiz.erik@gmail.com>
* @param string $pattern pattern for native glob function
* @param int|string $flags any valid flag for glob function
* @param bool $onlyFiles to filter return array with only matched files, or all matched results
* @return array array containing the recursive glob results
*
* Example:
*
* Common::rglob("/example/path/*");
*
* it will returns:
*
* Array
* (
* [0] => /example/path/README.txt
* [1] => /example/path/composer.json
* [4] => /example/path/one/one_text.txt
* [6] => /example/path/two/two_text.txt
* [7] => /example/path/two/two_one/two_one_text.txt
* [8] => /example/path/two/two_one/build.json
* )
*
* Example 2:
*
* Common::rglob("/example/path/*.json");
*
* It will returns:
*
* Array
* (
* [0] => /example/path/composer.json
* [1] => /example/path/two/two_one/build.json
* )
*/
public static function rglob($pattern, $flags = 0, $onlyFiles = false)
{
$singlePattern = basename($pattern);
if (strpos($singlePattern, "*") !== false) {
$path = rtrim(str_replace($singlePattern, "", $pattern), DIRECTORY_SEPARATOR);
} else {
$singlePattern = "";
$path = $pattern;
}
$files = glob("$path/$singlePattern", $flags);
$dirs = glob("$path/*", GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT);
foreach ($dirs as $dir) {
$files = array_merge($files, self::rglob("$dir/$singlePattern", $flags));
}
if ($onlyFiles) {
$files = array_filter($files, function($v) { return is_dir($v) ? false : true;});
}
return $files;
}
/**
* Returns the last version given a pattern of file name
*
* @param string $pattern a valid pattern for glob(...) native function
* @param int $flag php flags for glob(...) native function
* @return int|string
*
* Example:
* - Given the following files inside a directory:
* /example/path/myApplication-v1.tar
* /example/path/myApplication-v2.tar
* /example/path/myApplication-v3.tar
* /example/path/myApplication-v5.tar
* /example/path/myApplication-v7.tar
*
* $lastVer = ProcessMaker\Util\Common::getLastVersion("/example/path/myApplication-*.tar");
*
* It will returns: 7
*/
public static function getLastVersion($pattern, $flag = 0)
{
$files = glob($pattern, $flag);
$maxVersion = 0;
$pattern = str_replace("*", '([0-9\.]+)', basename($pattern));
foreach ($files as $file) {
$filename = basename($file);
if (preg_match('/'.$pattern.'/', $filename, $match)) {
if ($maxVersion < $match[1]) {
$maxVersion = $match[1];
}
}
}
return $maxVersion;
}
}

View File

@@ -8,66 +8,7 @@ namespace ProcessMaker\Util;
* @package ProcessMaker\Util
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com, erik@colosa.com>
*/
class Logger
class Logger extends \Maveriks\Util\Logger
{
private static $instance;
private $logFile;
private $fp;
protected function __construct()
{
$this->logFile = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'processmaker.log';
if (! file_exists($this->logFile)) {
if (! touch($this->logFile)) {
error_log("ProcessMaker Log file can't be created!");
}
chmod($this->logFile, 0777);
}
$this->fp = fopen($this->logFile, "a+");
}
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new Logger();
}
return self::$instance;
}
public function setLogLine()
{
$args = func_get_args();
$this->setLog(date('Y-m-d H:i:s') . " ");
foreach ($args as $str) {
$this->setLog((is_string($str) ? $str : var_export($str, true)) . PHP_EOL);
}
}
public function setLogInline()
{
$args = func_get_args();
$this->setLog(date('Y-m-d H:i:s') . " ");
foreach ($args as $str) {
$this->setLog((is_string($str) ? $str : var_export($str, true)) . " ");
}
}
public function setLog($str)
{
fwrite($this->fp, $str);
}
public static function log()
{
$me = Logger::getInstance();
$args = func_get_args();
call_user_func_array(array($me, 'setLogLine'), $args);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/*
* ProcessMaker Web Application Bootstrap
*/
try {
$rootDir = realpath(__DIR__ . "/../../") . DIRECTORY_SEPARATOR;
if (! is_dir($rootDir . 'vendor')) {
if (file_exists($rootDir . 'composer.phar')) {
throw new Exception(
"ERROR: Vendors are missing!" . PHP_EOL .
"Please execute the following command to install vendors:" .PHP_EOL.PHP_EOL.
"$>php composer.phar install"
);
} else {
throw new Exception(
"ERROR: Vendors are missing!" . PHP_EOL .
"Please execute the following commands to prepare/install vendors:" .PHP_EOL.PHP_EOL.
"$>curl -sS https://getcomposer.org/installer | php" . PHP_EOL .
"$>php composer.phar install"
);
}
}
if (! file_exists($rootDir . 'vendor' . DIRECTORY_SEPARATOR . "autoload.php")) {
throw new Exception(
"ERROR: Problems with Vendors!" . PHP_EOL .
"Please execute the following command to repair vendors:" .PHP_EOL.PHP_EOL.
"$>php composer.phar update"
);
}
require $rootDir . "framework/src/Maveriks/Util/ClassLoader.php";
$loader = Maveriks\Util\ClassLoader::getInstance();
$loader->add($rootDir . 'framework/src/', "Maveriks");
$loader->add($rootDir . 'workflow/engine/src/', "ProcessMaker");
$loader->add($rootDir . 'workflow/engine/src/');
$loader->add($rootDir . 'workflow/engine/classes/model/');
// and vendors to autoloader
$loader->add($rootDir . 'vendor/luracast/restler/vendor', "Luracast");
$loader->add($rootDir . 'vendor/bshaffer/oauth2-server-php/src/', "OAuth2");
$app = new Maveriks\WebApplication();
$app->setRootDir($rootDir);
$app->setRequestUri($_SERVER['REQUEST_URI']);
$stat = $app->route();
switch ($stat)
{
case Maveriks\WebApplication::RUNNING_WORKFLOW:
include "sysGeneric.php";
break;
case Maveriks\WebApplication::RUNNING_API:
$app->run(Maveriks\WebApplication::SERVICE_API);
break;
}
} catch (Exception $e) {
$view = new Maveriks\Pattern\Mvc\PhtmlView($rootDir . "framework/src/templates/Exception.phtml");
$view->set("message", $e->getMessage());
$view->set("exception", $e);
$response = new Maveriks\Http\Response($view->getOutput(), 503);
$response->send();
}

File diff suppressed because it is too large Load Diff