2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
2012-10-09 13:26:07 -04:00
|
|
|
|
2017-08-11 17:10:14 -04:00
|
|
|
class TriggerLibrary
|
|
|
|
|
{
|
|
|
|
|
private $_aTriggerClasses_ = array();
|
|
|
|
|
private static $instance = null;
|
2012-10-09 13:26:07 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* __construct
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2017-08-11 17:10:14 -04:00
|
|
|
public function __construct()
|
2012-10-09 13:26:07 -04:00
|
|
|
{
|
|
|
|
|
//Initialize the Library and register the Default
|
2017-08-11 17:10:14 -04:00
|
|
|
$this->registerFunctionsFileToLibrary(PATH_CORE . "classes" . PATH_SEP . "class.pmFunctions.php", "ProcessMaker Functions");
|
2012-10-09 13:26:07 -04:00
|
|
|
|
|
|
|
|
//Register all registered PLugin Functions
|
2017-08-11 17:10:14 -04:00
|
|
|
if (class_exists('folderData')) {
|
2017-08-01 12:16:06 -04:00
|
|
|
$oPluginRegistry = PluginRegistry::loadSingleton();
|
2012-10-09 13:26:07 -04:00
|
|
|
$aAvailablePmFunctions = $oPluginRegistry->getPmFunctions();
|
2016-01-28 17:53:31 -04:00
|
|
|
$oPluginRegistry->setupPlugins(); //Get and setup enabled plugins
|
2012-10-09 13:26:07 -04:00
|
|
|
foreach ($aAvailablePmFunctions as $key => $class) {
|
|
|
|
|
$filePlugin = PATH_PLUGINS . $class . PATH_SEP . 'classes' . PATH_SEP . 'class.pmFunctions.php';
|
|
|
|
|
|
2017-08-11 17:10:14 -04:00
|
|
|
if (file_exists($filePlugin) && !is_dir($filePlugin)) {
|
|
|
|
|
$this->registerFunctionsFileToLibrary($filePlugin, "ProcessMaker Functions");
|
2012-10-09 13:26:07 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Add External Triggers
|
2017-08-11 17:10:14 -04:00
|
|
|
$dir = G::ExpandPath("classes") . 'triggers';
|
|
|
|
|
$filesArray = array();
|
|
|
|
|
|
|
|
|
|
if (file_exists($dir)) {
|
|
|
|
|
if ($handle = opendir($dir)) {
|
|
|
|
|
while (false !== ($file = readdir($handle))) {
|
|
|
|
|
if ($file != "." && $file != ".." && !is_dir($dir . PATH_SEP . $file)) {
|
|
|
|
|
$this->registerFunctionsFileToLibrary($dir . PATH_SEP . $file, "ProcessMaker External Functions");
|
2012-10-09 13:26:07 -04:00
|
|
|
}
|
|
|
|
|
}
|
2017-08-11 17:10:14 -04:00
|
|
|
closedir($handle);
|
2012-10-09 13:26:07 -04:00
|
|
|
}
|
2011-12-22 10:39:01 -04:00
|
|
|
}
|
2012-10-09 13:26:07 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-10-09 13:26:07 -04:00
|
|
|
/**
|
|
|
|
|
* &getSingleton
|
|
|
|
|
*
|
|
|
|
|
* @return self::$instance;
|
|
|
|
|
*/
|
2017-08-11 17:10:14 -04:00
|
|
|
public function &getSingleton()
|
2012-10-09 13:26:07 -04:00
|
|
|
{
|
2017-08-11 17:10:14 -04:00
|
|
|
if (self::$instance == null) {
|
|
|
|
|
self::$instance = new TriggerLibrary();
|
2012-10-09 13:26:07 -04:00
|
|
|
}
|
|
|
|
|
return self::$instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* serializeInstance
|
|
|
|
|
*
|
|
|
|
|
* @return serialize ( self::$instance );
|
|
|
|
|
*/
|
2017-08-11 17:10:14 -04:00
|
|
|
public function serializeInstance()
|
2012-10-09 13:26:07 -04:00
|
|
|
{
|
2017-08-11 17:10:14 -04:00
|
|
|
return serialize(self::$instance);
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 13:26:07 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* unSerializeInstance
|
|
|
|
|
*
|
|
|
|
|
* @param integer $serialized
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2017-08-11 17:10:14 -04:00
|
|
|
public function unSerializeInstance($serialized)
|
2012-10-09 13:26:07 -04:00
|
|
|
{
|
2017-08-11 17:10:14 -04:00
|
|
|
if (self::$instance == null) {
|
2017-08-10 12:10:42 -04:00
|
|
|
self::$instance = new PluginRegistry();
|
2011-12-22 10:39:01 -04:00
|
|
|
}
|
2012-10-09 13:26:07 -04:00
|
|
|
|
2017-08-11 17:10:14 -04:00
|
|
|
$instance = unserialize($serialized);
|
2012-10-09 13:26:07 -04:00
|
|
|
self::$instance = $instance;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 13:26:07 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* registerFunctionsFileToLibrary
|
|
|
|
|
*
|
|
|
|
|
* @param string $filePath
|
|
|
|
|
* @param string $libraryName
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2017-08-11 17:10:14 -04:00
|
|
|
public function registerFunctionsFileToLibrary($filePath, $libraryName)
|
2012-10-09 13:26:07 -04:00
|
|
|
{
|
2017-08-11 17:10:14 -04:00
|
|
|
$aLibrary = $this->getMethodsFromLibraryFile($filePath);
|
2012-10-09 13:26:07 -04:00
|
|
|
$aLibrary->libraryFile = $filePath;
|
|
|
|
|
$aLibrary->libraryName = $libraryName;
|
2017-08-11 17:10:14 -04:00
|
|
|
if (isset($aLibrary->info['className'])) {
|
2012-10-09 13:26:07 -04:00
|
|
|
$this->_aTriggerClasses_[$aLibrary->info['className']] = $aLibrary;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* getMethodsFromLibraryFile
|
|
|
|
|
*
|
|
|
|
|
* @param string $file
|
|
|
|
|
* @return object(PHPClass) $parsedLibrary
|
|
|
|
|
*/
|
2017-08-11 17:10:14 -04:00
|
|
|
public function getMethodsFromLibraryFile($file)
|
2012-10-09 13:26:07 -04:00
|
|
|
{
|
|
|
|
|
// parse class comments from file
|
|
|
|
|
$parsedLibrary = new PHPClass();
|
2017-08-11 17:10:14 -04:00
|
|
|
$success = $parsedLibrary->parseFromFile($file);
|
2012-10-09 13:26:07 -04:00
|
|
|
|
|
|
|
|
return $parsedLibrary;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 13:26:07 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* getRegisteredClasses
|
|
|
|
|
*
|
|
|
|
|
* @return array ($this->_aTriggerClasses_)
|
|
|
|
|
*/
|
2017-08-11 17:10:14 -04:00
|
|
|
public function getRegisteredClasses()
|
2012-10-09 13:26:07 -04:00
|
|
|
{
|
|
|
|
|
return ($this->_aTriggerClasses_);
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-09 13:26:07 -04:00
|
|
|
/**
|
|
|
|
|
* getLibraryDefinition
|
|
|
|
|
*
|
|
|
|
|
* @param string $libraryClassName
|
|
|
|
|
* @return array ($this->_aTriggerClasses_[$libraryClassName])
|
|
|
|
|
*/
|
2017-08-11 17:10:14 -04:00
|
|
|
public function getLibraryDefinition($libraryClassName)
|
2012-10-09 13:26:07 -04:00
|
|
|
{
|
|
|
|
|
return ($this->_aTriggerClasses_[$libraryClassName]);
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-09 13:26:07 -04:00
|
|
|
/**
|
|
|
|
|
* __destruct
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2017-08-11 17:10:14 -04:00
|
|
|
public function __destruct()
|
2012-10-09 13:26:07 -04:00
|
|
|
{
|
|
|
|
|
//TODO - Insert your code here
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|