<?php /** * @file config.php * @author Alejandro Dario Simi */ // // Loading basic definitions. require_once dirname(__DIR__) . "/includes/define.php"; require_once dirname(__DIR__) . "/includes/loader.php"; // // Workflows defaults. $WKFLDefaults = array(); // // Knwon item factories. $WKFLDefaults[WKFL_DEFAULTS_FACTORIES] = array(); // // Paths. $WKFLDefaults[WKFL_DEFAULTS_PATHS] = array(WKFL_DEFAULTS_PATH_STEPS => '/workflows/steps', WKFL_DEFAULTS_PATH_WORKFLOWS => '/workflows'); $WKFLDefaults[WKFL_DEFAULTS_GRAPHS_PATH] = \TooBasic\Sanitizer::DirPath("{$Directories[GC_DIRECTORIES_CACHE]}/wkflgraphs"); // // Log configurations. $LoggerDefaults[LGGR_TYPES_BY_LOG]['workflows'] = LGGR_LOG_TYPE_PREFIXED; $LoggerDefaults[LGGR_PFXDLOG_PREFIXES]['workflows'] = ['workflow' => [LGGR_AFIELD_PREFIX => 'WF', LGGR_AFIELD_DEFAULT => '']];
/** * This method returns a list of absolute paths containing the location of * images that inlustrate a specific workflow. Such images are generated * each workflow specification. * If any requested image is not present or if it's older than the * workflow's configuration file, all images for such workflow are * generated. * * @warning This method requires GraphViz. * * @param string $workflowName Workflow name to look for. * @return string[string] Returns a list of paths containing these keys: * WKFL_AFIELD_FILE, WKFL_AFIELD_THUMB (these are defined constants). */ public function graphPath($workflowName) { // // Defautl values. $out = false; // // Checking and including library. if (@(require_once 'Image/GraphViz.php')) { // // Checking required directories permissions. $this->checkGraphsDirectories(); // // Global dependencies. global $WKFLDefaults; // // Default values. $generateIt = false; // // Retrieving the workflow. $workflow = $this->getWorkflow($workflowName); // // Guessing paths. $graphPath = Sanitizer::DirPath("{$WKFLDefaults[WKFL_DEFAULTS_GRAPHS_PATH]}/{$workflowName}.png"); $graphThumbPath = Sanitizer::DirPath("{$WKFLDefaults[WKFL_DEFAULTS_GRAPHS_PATH]}/{$workflowName}-256px.png"); // // Checking paths existence. if (!$generateIt && (!is_file($graphPath) || !is_file($graphThumbPath))) { $generateIt = true; } // // Checking paths' last modification dates. if (!$generateIt) { $workflowTime = filemtime($workflow->path()); $generateIt = filemtime($graphPath) < $workflowTime || filemtime($graphThumbPath) < $workflowTime; } // // Do these images have to be generated? if ($generateIt) { // // Logging pre-generation information. $this->_log->log(LGGR_LOG_LEVEL_INFO, "Gereating graph for '{$workflowName}'."); $this->_log->log(LGGR_LOG_LEVEL_DEBUG, "Workflow '{$workflowName}' graph path: '{$graphPath}'"); $this->_log->log(LGGR_LOG_LEVEL_DEBUG, " thumb path: '{$graphThumbPath}'"); // // Creating an image. $graph = new \Image_GraphViz(); // // Addind begining node. $graph->addNode('BEGIN', ['shape' => 'circle', 'label' => '', 'color' => 'black']); // // Configuration shortcut. $workflowConfig = $workflow->config(); // // Creating a squared node for each step. foreach ($workflowConfig->steps as $stepName => $step) { $graph->addNode($stepName, array('label' => $stepName, 'shape' => 'box')); } // // Addind ending node. $graph->addNode('END', ['shape' => 'circle', 'label' => '', 'color' => 'black', 'style' => 'filled']); // // Linking the beginning node to the first step. $graph->addEdge(['BEGIN' => $workflowConfig->startsAt]); // // Linking all steps based on connections // confiugrations. foreach ($workflowConfig->steps as $stepName => $step) { // // Checking each connection for current // step. foreach ($step->connections as $connName => $conn) { // // Checking if this connection // either changes the flow status // or sets the next step. if (isset($conn->status)) { // // Checking what change is taking. switch ($conn->status) { case WKFL_ITEM_FLOW_STATUS_FAILED: case WKFL_ITEM_FLOW_STATUS_DONE: // // These statuses link to the end. $graph->addEdge([$stepName => 'END'], ['label' => $connName, 'fontcolor' => 'brown', 'color' => 'brown']); break; case WKFL_ITEM_FLOW_STATUS_WAIT: // // Basic attributes for each link. $attrs = ['label' => "{$connName}\n[wait]", 'color' => 'orange', 'fontcolor' => 'orange', 'style' => 'dashed']; // // Checking if this waiting has some extra // configuration. if (isset($conn->wait)) { // // This status creates a vitual node // representing the waiting step. $nodeName = "wait_{$stepName}"; $graph->addNode($nodeName, ['shape' => 'box', 'label' => "wait:{$stepName}", 'fontcolor' => 'orange', 'color' => 'orange']); // // Linking the current step to this // virtual node. $graph->addEdge([$stepName => $nodeName], $attrs); // // Linking the virtual node to the current // one for less attempts than a limit. $attrs['label'] = "{$connName}\n[wait<={$conn->wait->attempts}]"; $graph->addEdge([$nodeName => $stepName], $attrs); // // Linking the virtual node something else // for more attempts than a limit. $attrs['label'] = "{$connName}\n[wait>{$conn->wait->attempts}]"; if (isset($conn->wait->status)) { // // Linking to the end. $graph->addEdge([$nodeName => 'END'], $attrs); } elseif (isset($conn->wait->step)) { // // Linking to another step. $graph->addEdge([$nodeName => $conn->wait->step], $attrs); } } else { $nextStep = isset($conn->step) ? $conn->step : $stepName; $graph->addEdge([$stepName => $nextStep], $attrs); } break; } } elseif (isset($conn->step)) { // // Linking this step to // the next one. $graph->addEdge([$stepName => $conn->step], ['label' => $connName, 'fontcolor' => 'darkgreen', 'color' => 'darkgreen']); } } } // // Saving the generated graphic in two locations, // one for the actual image and other for 256 // pixels thumbnail. file_put_contents($graphPath, $graph->fetch('png')); file_put_contents($graphThumbPath, $graph->fetch('png')); // // Croping thumbnail. self::CropImage($graphThumbPath, 256); } // // Building the returning information. $out = array(WKFL_AFIELD_FILE => $graphPath, WKFL_AFIELD_THUMB => $graphThumbPath); } else { // // Logging the error of not having the proper library. $this->_log->log(LGGR_LOG_LEVEL_ERROR, "Pear GraphViz plugin hasn't been installed."); } return $out; }
/** * @file config.php * @author Alejandro Dario Simi */ // // Loading basic definitions. require_once dirname(__DIR__) . "/includes/define.php"; require_once dirname(__DIR__) . "/includes/loader.php"; // // Logger configuration descriptor. $LoggerDefaults = array(); // // Levels configuration. $LoggerDefaults[LGGR_LEVELS] = array(LGGR_LOG_LEVEL_DISABLED => -1000, LGGR_LOG_LEVEL_FATAL => -100, LGGR_LOG_LEVEL_ERROR => -50, LGGR_LOG_LEVEL_INFO => 0, LGGR_LOG_LEVEL_DEBUG => 50); $LoggerDefaults[LGGR_LEVELS_BY_LOG] = array(); $LoggerDefaults[LGGR_LEVEL] = LGGR_LOG_LEVEL_INFO; // // Paths configuration. $LoggerDefaults[LGGR_LOGS_PATH] = \TooBasic\Sanitizer::DirPath("{$Directories[GC_DIRECTORIES_CACHE]}/logs"); // // Types configuration. $LoggerDefaults[LGGR_TYPES] = array(LGGR_LOG_TYPE_BASIC => '\\TooBasic\\Logs\\Log', LGGR_LOG_TYPE_PREFIXED => '\\TooBasic\\Logs\\PrefixedLog'); $LoggerDefaults[LGGR_DEFAULT_TYPE] = LGGR_LOG_TYPE_BASIC; $LoggerDefaults[LGGR_TYPES_BY_LOG] = array(); // // MagicProp configuration. $MagicProps[GC_MAGICPROP_PROPERTIES][LGGR_MAGICPROP_PROP] = '\\TooBasic\\Logs\\Logger'; // // Configurations for prefixed logs. $LoggerDefaults[LGGR_PFXDLOG_PREFIXES] = array();
/** * This method generates and checks this log's file path. * * @throws \TooBasic\Logs\LoggerException */ protected function checkPath() { // // Global dependencies. global $LoggerDefaults; // // Generating a proper file path. $path = Sanitizer::DirPath("{$LoggerDefaults[LGGR_LOGS_PATH]}/" . date("Y-m-d") . ".{$this->_name}.log"); // // Checking availability. if (!is_file($path) || is_readable($path)) { $this->_path = $path; } else { throw new LoggerException("Unable to open an use log file '{$path}'."); } }