<commit_before><?php
/**
 * This class gives access to workflow and statuses stored as PHP files.
 * Following attributes can be initialized when the component is configured:
 * <ul>
 * <li><b>basePath</b> (string) : the base path alias where all workflow are stored.By default, it is set to
 * application.models.workflows (folder  "protected/models/workflows").
 * </li>
 * <li><b>definitionType</b> (string) :  Defines the type of PHP file to load. A Workflow can be defined in
 * a PHP file that contains a simple array definition (definitionType = 'array'), or by a
 * class (definitionType = 'class'). By default this attribute is set to 'array'.
 * </li>
 * </ul>
 */
class SWPhpWorkflowSource extends SWWorkflowSource {
	/**
	 * @var string the base path alias where all workflow are stored.By default, it is set to
	 * application.models.workflows (folder  "protected/models/workflows").
	 */
	public $basePath = 'application.models.workflows';
	/**
	 * @var string Definition type for workflow. Allowed values are : class, array. Default is 'array'
	 */
	public $definitionType = 'array';
	
	private $_workflow;	// workflow definition collection
	private $_workflowBasePath;
	/**
	 * Initialize the component with configured values. To preload workflows, set configuration
	 * setting 'preload' to an array containing all workflows to preload. If no preload is set
	 * workflows are loaded on demand.
	 *
	 * @see SWWorkflowSource
	 */
	public function init()
	{
		parent::init();
		$this->_workflowBasePath = Yii::getPathOfAlias($this->basePath);
		if( is_array($this->preload) and count($this->preload)!=0){
			foreach ( $this->preload as $wfId ) {
				Yii::t('simpleWorkflow','preloading workflow : {name}',array('{name}'=>$wfId));
				$this->_load($wfId,true);
			}
		}
		if( $this->definitionType == 'class'){
			Yii::import($this->basePath.'.*');
		}
		Yii::trace(Yii::t('simpleWorkflow','SWWorkflowSource initialized - basePath : '.$this->basePath),'application.simpleWorkflow');
	}
	
	//
	///////////////////////////////////////////////////////////////////////////////////
	// private methods
		
	/**
	 * Loads a workflow from a php source file into the $this->_workflow
	 * associative array. A call to reset() will unload all workflows.
	 */
	private function _load($wfId, $forceReload)
	{
		if( !is_string($wfId) or empty($wfId))
		{
			throw new SWException(Yii::t('simpleWorkflow','failed to load workflow - invalid workflow Id : {workflowId}',
				array('{workflowId}'=>$wfId)),
				SWException::SW_ERR_WORKFLOW_ID);
		}
		
		if( !isset($this->_workflow[$wfId]) or $forceReload==true)
		{
			
			if($this->definitionType == 'class')
			{
				$wo = new $wfId;
				$this->_workflow[$wfId] = $this->_createWorkflow($wo->getDefinition(),$wfId);
			}
			elseif( $this->definitionType == 'array')
			{
				$fname=$this->_workflowBasePath.DIRECTORY_SEPARATOR.$wfId.'.php';
				if( file_exists($fname)==false){
					throw new SWException(Yii::t('simpleWorkflow','workflow definition file not found : {file}',
						array('{file}'=>$fname)),
						SWException::SW_ERR_WORKFLOW_NOT_FOUND
					);
				}
				
				Yii::trace(
					Yii::t('simpleWorkflow','loading workflow {wfId} from file {file}',
						array('{wfId}'=>$wfId,'{file}'=>$fname)
					),
					'application.simpleWorkflow'
				);
								
				$this->_workflow[$wfId] = $this->_createWorkflow(require($fname),$wfId);
			}
		}
		return $this->_workflow[$wfId];
	}
	/**
	 * @param array $wf workflow definition
	 * @param string $wfId workflow Id
	 */
	private function _createWorkflow($wf,$wfId)
	{
		if(!is_array($wf) || empty($wfId)){
			throw new SWException(Yii::t('simpleWorkflow','invalid argument'));
		}
		$wfDefinition=array();
		
		if( !isset($wf['initial'])) {
			throw new SWException(Yii::t('simpleWorkflow','missing initial status for workflow {workflow}',
				array('{workflow}'=>$wfId)),
				SWException::SW_ERR_IN_WORKFLOW
			);
		}
			
		// load node list
		$nodeIds = array();
		foreach($wf['node'] as $rnode)
		{
			$node=new SWNode($rnode,$wfId);
			
			if(in_array($node->getId(),$nodeIds )){
				throw new SWException(Yii::t('simpleWorkflow','duplicate node id {nodeId}',
					array('{nodeId}'=>$node->getId())),
					SWException::SW_ERR_IN_WORKFLOW
				);
			}else{
				$nodeIds[] = $node->getId();
			}
			
			$wfDefinition[$node->getId()]=$node;
			if($node->getId()==$wf['initial']){
				$wfDefinition['swInitialNode']= $node;
			}
		}
		// checks that initialnode is set
		 
		if(!isset($wfDefinition['swInitialNode']))
			throw new SWException(Yii::t('simpleWorkflow','missing initial status for workflow {workflow}',
				array('{workflow}'=>$wfId)),<commit_msg>initial status defined as absolute Id<commit_after><?php
/**
 * This class gives access to workflow and statuses stored as PHP files.
 * Following attributes can be initialized when the component is configured:
 * <ul>
 * <li><b>basePath</b> (string) : the base path alias where all workflow are stored.By default, it is set to
 * application.models.workflows (folder  "protected/models/workflows").
 * </li>
 * <li><b>definitionType</b> (string) :  Defines the type of PHP file to load. A Workflow can be defined in
 * a PHP file that contains a simple array definition (definitionType = 'array'), or by a
 * class (definitionType = 'class'). By default this attribute is set to 'array'.
 * </li>
 * </ul>
 */
class SWPhpWorkflowSource extends SWWorkflowSource {
	/**
	 * @var string the base path alias where all workflow are stored.By default, it is set to
	 * application.models.workflows (folder  "protected/models/workflows").
	 */
	public $basePath = 'application.models.workflows';
	/**
	 * @var string Definition type for workflow. Allowed values are : class, array. Default is 'array'
	 */
	public $definitionType = 'array';
	
	private $_workflow;	// workflow definition collection
	private $_workflowBasePath;
	/**
	 * Initialize the component with configured values. To preload workflows, set configuration
	 * setting 'preload' to an array containing all workflows to preload. If no preload is set
	 * workflows are loaded on demand.
	 *
	 * @see SWWorkflowSource
	 */
	public function init()
	{
		parent::init();
		$this->_workflowBasePath = Yii::getPathOfAlias($this->basePath);
		if( is_array($this->preload) and count($this->preload)!=0){
			foreach ( $this->preload as $wfId ) {
				Yii::t('simpleWorkflow','preloading workflow : {name}',array('{name}'=>$wfId));
				$this->_load($wfId,true);
			}
		}
		if( $this->definitionType == 'class'){
			Yii::import($this->basePath.'.*');
		}
		Yii::trace(Yii::t('simpleWorkflow','SWWorkflowSource initialized - basePath : '.$this->basePath),'application.simpleWorkflow');
	}
	
	//
	///////////////////////////////////////////////////////////////////////////////////
	// private methods
		
	/**
	 * Loads a workflow from a php source file into the $this->_workflow
	 * associative array. A call to reset() will unload all workflows.
	 */
	private function _load($wfId, $forceReload)
	{
		if( !is_string($wfId) or empty($wfId))
		{
			throw new SWException(Yii::t('simpleWorkflow','failed to load workflow - invalid workflow Id : {workflowId}',
				array('{workflowId}'=>$wfId)),
				SWException::SW_ERR_WORKFLOW_ID);
		}
		
		if( !isset($this->_workflow[$wfId]) or $forceReload==true)
		{
			
			if($this->definitionType == 'class')
			{
				$wo = new $wfId;
				$this->_workflow[$wfId] = $this->_createWorkflow($wo->getDefinition(),$wfId);
			}
			elseif( $this->definitionType == 'array')
			{
				$fname=$this->_workflowBasePath.DIRECTORY_SEPARATOR.$wfId.'.php';
				if( file_exists($fname)==false){
					throw new SWException(Yii::t('simpleWorkflow','workflow definition file not found : {file}',
						array('{file}'=>$fname)),
						SWException::SW_ERR_WORKFLOW_NOT_FOUND
					);
				}
				
				Yii::trace(
					Yii::t('simpleWorkflow','loading workflow {wfId} from file {file}',
						array('{wfId}'=>$wfId,'{file}'=>$fname)
					),
					'application.simpleWorkflow'
				);
								
				$this->_workflow[$wfId] = $this->_createWorkflow(require($fname),$wfId);
			}
		}
		return $this->_workflow[$wfId];
	}
	/**
	 * @param array $wf workflow definition
	 * @param string $wfId workflow Id
	 */
	private function _createWorkflow($wf,$wfId)
	{
		if(!is_array($wf) || empty($wfId)){
			throw new SWException(Yii::t('simpleWorkflow','invalid argument'));
		}
		$wfDefinition=array();
		
		if( !isset($wf['initial'])) {
			throw new SWException(Yii::t('simpleWorkflow','missing initial status for workflow {workflow}',
				array('{workflow}'=>$wfId)),
				SWException::SW_ERR_IN_WORKFLOW
			);
		}
			
		// load node list
		$nodeIds = array();
		foreach($wf['node'] as $rnode)
		{
			$node=new SWNode($rnode,$wfId);
			
			if(in_array($node->getId(),$nodeIds )){
				throw new SWException(Yii::t('simpleWorkflow','duplicate node id {nodeId}',
					array('{nodeId}'=>$node->getId())),
					SWException::SW_ERR_IN_WORKFLOW
				);
			}else{
				$nodeIds[] = $node->getId();
			}
			
			$wfDefinition[$node->getId()]=$node;
			if( $node->getId()==$wf['initial'] || $node->toString() == $wf['initial']){
				$wfDefinition['swInitialNode']= $node;
			}
		}
		// checks that initialnode is set
		 
		if(!isset($wfDefinition['swInitialNode']))
			throw new SWException(Yii::t('simpleWorkflow','missing initial status for workflow {workflow}',
				array('{workflow}'=>$wfId)),
{'fraction_non_alphanumeric': 0.1793015332197615, 'fraction_numerical': 0.00021294718909710392, 'mean_word_length': 3.7631845841784988, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 90, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6851069', 'n_tokens_mistral': 3508, 'n_tokens_neox': 2980, 'n_words': 711}