idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
47,700
protected function getObjectRequestedById ( string $ class ) { $ itemId = Router :: get ( 0 ) ; if ( ! $ itemId ) { $ this -> enqueueError ( $ this -> lang ( 'NO_ID_OF_ITEM_TO_EDIT' , $ class ) ) ; return NULL ; } $ object = new $ class ( $ itemId ) ; if ( $ object -> isLoaded ( ) ) { return $ object ; } else { $ this -> enqueueError ( $ this -> lang ( 'ID_OF_ITEM_TO_EDIT_IS_NOT_VALID' , $ class ) ) ; $ this -> logError ( 'Object ' . $ class . ' id=' . $ itemId . ' has not been loaded' ) ; return NULL ; } }
Returns the object of inherited class when called with id as first parameter .
47,701
protected function raiseError ( ActiveRecord $ object ) { $ errors = $ object -> getErrors ( ) ; $ message = $ this -> lang ( 'ERROR_ON_LAST_REQUEST' ) . ( $ errors ? ": \n" . implode ( " \n" , $ errors ) : '' ) ; $ this -> enqueueError ( $ message ) ; $ this -> view = 'default' ; }
Get error list from an ActiveRecord object and show it to the user .
47,702
protected function accessDenied ( ? string $ message = NULL ) { $ this -> enqueueError ( ( $ message ? $ message : $ this -> translator -> get ( 'ACCESS_DENIED' ) ) ) ; $ this -> redirect ( strtolower ( $ this -> name ) ) ; }
Print an error message and redirect to default action .
47,703
public function decrypt ( $ data ) { if ( ! $ this -> encEnabled ) return $ data ; switch ( $ this -> encMethod ) { case 'SIMPLE' : return $ this -> decryptSimple ( $ data ) ; case 'INTEGER' : return $ this -> decryptInteger ( $ data ) ; } $ data = base64_decode ( str_replace ( array ( '-' , '_' ) , array ( '+' , '/' ) , $ data ) ) ; $ iv_strlen = 2 * openssl_cipher_iv_length ( $ this -> encMethod ) ; if ( preg_match ( "/^(.{" . $ iv_strlen . "})(.+)$/" , $ data , $ regs ) ) { try { list ( , $ iv , $ crypted_string ) = $ regs ; $ decrypted_string = openssl_decrypt ( $ crypted_string , $ this -> encMethod , $ this -> encPassword , 0 , hex2bin ( $ iv ) ) ; return substr ( $ decrypted_string , strlen ( $ this -> encSalt ) ) ; } catch ( Exception $ ex ) { return false ; } } else { return false ; } }
It is a two way decryption
47,704
function decryptSimple ( $ data ) { $ result = '' ; $ data = base64_decode ( str_replace ( array ( '-' , '_' ) , array ( '+' , '/' ) , $ data ) ) ; for ( $ i = 0 ; $ i < strlen ( $ data ) ; $ i ++ ) { $ char = substr ( $ data , $ i , 1 ) ; $ keychar = substr ( $ this -> encPassword , ( $ i % strlen ( $ this -> encPassword ) ) - 1 , 1 ) ; $ char = chr ( ord ( $ char ) - ord ( $ keychar ) ) ; $ result .= $ char ; } return $ result ; }
It is a simple decryption . It s less safe but the result is shorter .
47,705
function encryptSimple ( $ data ) { $ result = '' ; for ( $ i = 0 ; $ i < strlen ( $ data ) ; $ i ++ ) { $ char = substr ( $ data , $ i , 1 ) ; $ keychar = substr ( $ this -> encPassword , ( $ i % strlen ( $ this -> encPassword ) ) - 1 , 1 ) ; $ char = chr ( ord ( $ char ) + ord ( $ keychar ) ) ; $ result .= $ char ; } return str_replace ( array ( '+' , '/' ) , array ( '-' , '_' ) , base64_encode ( $ result ) ) ; }
It is a simple encryption . It s less safe but generates a short string
47,706
public function encryptInteger ( $ n ) { if ( ! is_numeric ( $ n ) ) return null ; return ( PHP_INT_SIZE == 4 ? self :: encrypt32 ( $ n ) : self :: encrypt64 ( $ n ) ) ^ $ this -> encPassword ; }
It encrypts an integer .
47,707
final public function value ( string $ expression ) : Collection \ StringCollection { $ items = $ this -> query ( $ expression ) ; $ result = [ ] ; foreach ( $ items as $ node ) { $ result [ ] = $ node -> nodeValue ; } return new StringCollection ( $ result ) ; }
Get nodeValue of node
47,708
final public function keyValue ( string $ keyExpression , string $ valueExpression ) : array { $ keyNodes = $ this -> query ( $ keyExpression ) ; $ valueNodes = $ this -> query ( $ valueExpression ) ; if ( $ keyNodes -> length !== $ valueNodes -> length ) { throw new \ RuntimeException ( 'Keys and values must have equal numbers of elements' ) ; } $ result = [ ] ; foreach ( $ keyNodes as $ index => $ node ) { $ result [ $ node -> nodeValue ] = $ valueNodes -> item ( $ index ) -> nodeValue ; } return $ result ; }
Return array of keys and values
47,709
final public static function safeEncodeStr ( string $ str ) : string { return preg_replace_callback ( '/&#([a-z\d]+);/i' , function ( $ m ) { $ value = ( string ) $ m [ 0 ] ; $ value = mb_convert_encoding ( $ value , 'UTF-8' , 'HTML-ENTITIES' ) ; return $ value ; } , $ str ) ; }
Simple helper function for str encoding
47,710
private function isCountable ( $ value ) : bool { return is_string ( $ value ) || is_array ( $ value ) || $ value instanceof \ Countable || $ value instanceof \ Traversable ; }
checks if given value is countable
47,711
private function sizeOf ( $ value ) : int { if ( is_string ( $ value ) ) { return strlen ( $ value ) ; } elseif ( is_array ( $ value ) || $ value instanceof \ Countable ) { return count ( $ value ) ; } $ traversable = $ this -> traversable ( $ value ) ; $ key = $ traversable -> key ( ) ; $ count = iterator_count ( $ traversable ) ; $ traversable -> rewind ( ) ; while ( $ traversable -> valid ( ) && $ key !== $ traversable -> key ( ) ) { $ traversable -> next ( ) ; } return $ count ; }
calculates the size of given value
47,712
private function rewind ( $ traversable , $ key ) { if ( $ key === null ) { return ; } if ( is_array ( $ traversable ) ) { foreach ( $ traversable as $ currentKey => $ value ) { if ( $ currentKey === $ key ) { break ; } } } else { $ traversable -> rewind ( ) ; while ( $ traversable -> valid ( ) && $ key !== $ traversable -> key ( ) ) { $ traversable -> next ( ) ; } } }
rewinds traversable to given key to not change state of traversable
47,713
public static function instance ( ) : Predicate { if ( null === self :: $ instance ) { self :: $ instance = new self ( ) ; } return self :: $ instance ; }
returns reusable predicate instance
47,714
public function message ( callable $ predicate ) : self { assertThat ( $ this -> actualException -> getMessage ( ) , new Wrap ( $ predicate , 'exception message %s' ) ) ; return $ this ; }
asserts actual exception fulfills given predicate
47,715
public function withCode ( int $ expectedCode ) : self { assertThat ( $ this -> actualException -> getCode ( ) , new Wrap ( equals ( $ expectedCode ) , 'exception code %s' ) ) ; return $ this ; }
asserts actual exception code equals expected code
47,716
public function with ( callable $ predicate , string $ description = null ) : self { assertThat ( $ this -> actualException , $ predicate , $ description ) ; return $ this ; }
asserts actual exception fulfills predicate
47,717
private function predicateName ( ) : string { if ( is_array ( $ this -> predicate ) ) { if ( is_string ( $ this -> predicate [ 0 ] ) ) { return $ this -> predicate [ 0 ] . '::' . $ this -> predicate [ 1 ] . '()' ; } return get_class ( $ this -> predicate [ 0 ] ) . '->' . $ this -> predicate [ 1 ] . '()' ; } elseif ( is_string ( $ this -> predicate ) ) { return $ this -> predicate . '()' ; } return 'a lambda function' ; }
tries to determine a name for the callable
47,718
public function evaluate ( Predicate $ predicate , string $ description = null ) : bool { try { if ( $ predicate -> test ( $ this -> value ) ) { return true ; } } catch ( \ Exception $ e ) { if ( empty ( $ description ) ) { $ description = $ e -> getMessage ( ) ; } else { $ description .= "\n" . $ e -> getMessage ( ) ; } } throw new AssertionFailure ( $ this -> describeFailure ( $ predicate , $ description ) ) ; }
evaluates predicate against value throwing an AssertionFailure when predicate fails
47,719
private function describeFailure ( Predicate $ predicate , string $ description = null ) : string { $ predicateText = ( string ) $ predicate ; $ failureDescription = sprintf ( 'Failed asserting that %s %s%s' , $ predicate -> describeValue ( $ this -> exporter , $ this -> value ) , $ predicateText , strpos ( $ predicateText , "\n" ) !== false ? '' : '.' ) ; if ( ! empty ( $ description ) ) { $ failureDescription .= "\n" . $ description ; } return $ failureDescription ; }
creates failure description when value failed the test with given predicate
47,720
private function runCode ( ) { if ( $ this -> executed ) { return $ this -> result ; } $ code = $ this -> code ; try { $ this -> result = $ code ( ) ; } catch ( \ Throwable $ ex ) { $ this -> exception = $ ex ; } finally { $ this -> executed = true ; } return $ this -> result ; }
runs code and returns result
47,721
public function throws ( $ expected = null ) : CatchedException { $ this -> runCode ( ) ; if ( null === $ this -> exception ) { throw new AssertionFailure ( 'Failed asserting that ' . ( null !== $ expected ? 'exception of type "' . ( is_string ( $ expected ) ? $ expected : get_class ( $ expected ) ) . '"' : 'an exception' ) . ' is thrown.' ) ; } elseif ( null !== $ expected ) { if ( is_string ( $ expected ) ) { $ isExpected = new ExpectedException ( $ expected ) ; } elseif ( $ expected instanceof \ Throwable ) { $ isExpected = isSameAs ( $ expected ) ; } else { throw new \ InvalidArgumentException ( 'Given expected is neither a class name nor an instance' . ' of \Throwable, but of type ' . gettype ( $ expected ) ) ; } assertThat ( $ this -> exception , $ isExpected ) ; } return new CatchedException ( $ this -> exception ) ; }
asserts the code throws an exception when executed
47,722
public function doesNotThrow ( string $ unexpectedType = null ) : self { increaseAssertionCounter ( 1 ) ; $ this -> runCode ( ) ; if ( null !== $ this -> exception && ( null === $ unexpectedType || $ this -> exception instanceof $ unexpectedType ) ) { throw new AssertionFailure ( 'Failed asserting that no exception' . ( null !== $ unexpectedType ? ' of type "' . $ unexpectedType . '"' : '' ) . ' is thrown, got ' . get_class ( $ this -> exception ) . ' with message "' . $ this -> exception -> getMessage ( ) . '".' ) ; } return $ this ; }
asserts that code does not throw an exception when executed
47,723
public function triggers ( int $ expectedError = null ) : CatchedError { if ( null !== $ expectedError && ! CatchedError :: knowsLevel ( $ expectedError ) ) { throw new \ InvalidArgumentException ( 'Unknown error level ' . $ expectedError ) ; } set_error_handler ( function ( int $ errno , string $ errstr , string $ errfile , int $ errline , array $ errcontext ) : bool { $ this -> error = new CatchedError ( $ errno , $ errstr , $ errfile , $ errline , $ errcontext ) ; return true ; } ) ; $ this -> runCode ( ) ; restore_error_handler ( ) ; if ( null === $ this -> error ) { throw new AssertionFailure ( 'Failed asserting that ' . ( null !== $ expectedError ? 'error of type "' . CatchedError :: nameOf ( $ expectedError ) . '"' : 'an error' ) . ' is triggered.' ) ; } elseif ( null !== $ expectedError ) { assertThat ( $ this -> error , new ExpectedError ( $ expectedError ) ) ; } return $ this -> error ; }
asserts the code triggers an error when executed
47,724
public function result ( callable $ predicate , string $ description = null ) : self { $ this -> runCode ( ) ; if ( null !== $ this -> exception ) { throw new AssertionFailure ( 'Failed asserting that result ' . Predicate :: castFrom ( $ predicate ) . ' because exception of type ' . get_class ( $ this -> exception ) . ' with message "' . $ this -> exception -> getMessage ( ) . '" was thrown.' ) ; } assertThat ( $ this -> result , $ predicate , $ description ) ; return $ this ; }
asserts result of executed code fulfills a predicate
47,725
public function after ( $ value , callable $ predicate , string $ description = null ) : self { $ this -> runCode ( ) ; assertThat ( $ value , $ predicate , $ description ) ; return $ this ; }
asserts anything after the code was executed even if it threw an exception
47,726
protected function getEmptyBody ( ) { $ body = $ this -> response -> getBody ( ) ; if ( ! $ body -> isWritable ( ) ) { throw new \ RuntimeException ( 'response body is not writeble' ) ; } if ( $ body -> getSize ( ) !== 0 ) { throw new \ RuntimeException ( 'response body is not empty' ) ; } return $ body ; }
ensure body is empty and writable and return that
47,727
public static function buildObtainTokenUrl ( $ client_id , $ redirect_uri , $ scope ) { $ params = sprintf ( "client_id=%s&response_type=%s&redirect_uri=%s&scope=%s" , $ client_id , "code" , $ redirect_uri , implode ( " " , $ scope ) ) ; return sprintf ( "%s/oauth/authorize?%s" , Config :: $ MONEY_URL , $ params ) ; }
Builds authorization url for user s browser
47,728
public static function getAccessToken ( $ client_id , $ code , $ redirect_uri , $ client_secret = NULL ) { $ full_url = Config :: $ MONEY_URL . "/oauth/token" ; return self :: sendRequest ( $ full_url , array ( "code" => $ code , "client_id" => $ client_id , "grant_type" => "authorization_code" , "redirect_uri" => $ redirect_uri , "client_secret" => $ client_secret ) ) ; }
Exchanges temporary authorization code for an access_token .
47,729
public function resolveVariable ( $ key ) { $ key = trim ( $ key ) ; if ( ( $ result = $ this -> executeFunction ( $ key ) ) !== Constants :: NOT_RESOLVED ) { return $ result ; } return Constants :: NOT_RESOLVED ; }
Resolve variable .
47,730
public function executeFunction ( $ string ) { preg_match_all ( '/(.*)\((.*)\)/' , $ string , $ matches ) ; if ( count ( $ matches ) > 0 && is_array ( $ matches [ 0 ] ) && count ( $ matches [ 0 ] ) > 0 ) { $ function = $ matches [ 1 ] [ 0 ] ; return $ function ( $ this -> removeQuotes ( $ matches [ 2 ] [ 0 ] ) ) ; } return Constants :: NOT_RESOLVED ; }
Execute function .
47,731
public function replaceKeysToSelf ( $ string , Collection $ keys ) { preg_match_all ( "/\{\{'((?:[^{}]|(?R))*)\'\}\}/" , $ string , $ matches ) ; foreach ( $ matches [ 0 ] as $ key => $ value ) { $ string = str_replace ( $ matches [ 0 ] [ $ key ] , array_get ( $ keys -> toArray ( ) , $ matches [ 1 ] [ $ key ] ) , $ string ) ; } return $ string ; }
Replace keys to self .
47,732
public function dump ( $ input , $ inline = 5 , $ indent = 4 , $ flags = 0 ) { return SymfonyYaml :: dump ( $ input , $ inline , $ indent , $ flags ) ; }
Dump array to yaml . InvalidYamlFile .
47,733
public function isAllowedDirectory ( $ item ) { return is_dir ( $ item ) && ! ends_with ( $ item , DIRECTORY_SEPARATOR . '.' ) && ! ends_with ( $ item , DIRECTORY_SEPARATOR . '..' ) ; }
Check if the string is a directory .
47,734
public function listFiles ( $ directory ) { if ( ! file_exists ( $ directory ) ) { return collect ( [ ] ) ; } return $ this -> scanDir ( $ directory ) -> reject ( function ( $ item ) { return ! $ this -> isAllowedDirectory ( $ item ) && ! $ this -> isYamlFile ( $ item ) ; } ) -> mapWithKeys ( function ( $ item ) { if ( is_dir ( $ item ) ) { return [ basename ( $ item ) => $ this -> listFiles ( $ item ) -> toArray ( ) ] ; } return [ $ this -> cleanKey ( $ item ) => $ item ] ; } ) ; }
Get all files from dir .
47,735
public function isYamlFile ( $ item ) { return $ this -> isFile ( $ item ) && ( ends_with ( strtolower ( $ item ) , '.yml' ) || ends_with ( strtolower ( $ item ) , '.yaml' ) ) ; }
Check if the file is a yaml file .
47,736
public function scanDir ( $ dir ) { return collect ( scandir ( $ dir ) ) -> map ( function ( $ item ) use ( $ dir ) { return $ dir . DIRECTORY_SEPARATOR . $ item ; } ) ; }
Scan the directory for files .
47,737
public function cleanKey ( $ key ) { return is_string ( $ key ) && file_exists ( trim ( $ key ) ) ? preg_replace ( '/\.[^.]+$/' , '' , basename ( $ key ) ) : $ key ; }
Clean the array key .
47,738
public function loadToConfig ( $ path , $ configKey ) { $ loaded = $ this -> cleanArrayKeysRecursive ( $ this -> file -> isYamlFile ( $ path ) ? $ this -> loadFile ( $ path ) : $ this -> loadFromDirectory ( $ path ) ) ; return $ this -> resolver -> findAndReplaceExecutableCodeToExhaustion ( $ loaded , $ configKey ) ; }
Load yaml files from directory and add to Laravel config .
47,739
public function loadFromDirectory ( $ path ) { return $ this -> file -> listFiles ( $ path ) -> mapWithKeys ( function ( $ file , $ key ) { return [ $ key => $ this -> loadFile ( $ file ) ] ; } ) ; }
Load all yaml files from a directory .
47,740
public function loadFile ( $ file ) { if ( is_array ( $ file ) ) { return collect ( $ file ) -> mapWithKeys ( function ( $ subFile , $ key ) { return [ $ key => $ this -> loadFile ( $ subFile ) ] ; } ) -> toArray ( ) ; } return $ this -> parser -> parseFile ( $ file ) ; }
Load yaml file .
47,741
public function cleanArrayKeysRecursive ( $ dirty ) { if ( is_array ( $ dirty instanceof Collection ? $ dirty -> toArray ( ) : $ dirty ) ) { return collect ( $ dirty ) -> mapWithKeys ( function ( $ item , $ key ) { return [ $ this -> file -> cleanKey ( $ key ) => $ this -> cleanArrayKeysRecursive ( $ item ) , ] ; } ) ; } return $ dirty ; }
Remove extension from file name .
47,742
public function clear ( ) { $ this -> seed = false ; $ this -> pattern = array ( ) ; $ this -> prefixes = array ( ) ; $ this -> suffixes = array ( ) ; $ this -> modifiers = array ( ) ; return $ this ; }
Clears all pattern components to create a fresh expression
47,743
public function add ( $ value , $ format = '(%s)' ) { array_push ( $ this -> pattern , sprintf ( $ format , $ this -> sanitize ( $ value ) ) ) ; return $ this ; }
Adds a sanitized pattern component that augments the overall expression
47,744
public function raw ( $ value , $ format = '%s' ) { array_push ( $ this -> pattern , sprintf ( $ format , $ value ) ) ; return $ this ; }
Adds a raw pattern component that augments the overall expression
47,745
protected function replaceQuantifierByKey ( $ key , $ replacement = '' ) { $ subject = $ this -> pattern [ $ key ] ; if ( strripos ( $ subject , ')' ) !== false ) { $ subject = rtrim ( $ subject , ')' ) ; $ subject = $ this -> removeQuantifier ( $ subject ) ; $ this -> pattern [ $ key ] = sprintf ( '%s%s)' , $ subject , $ replacement ) ; } else { $ subject = $ this -> removeQuantifier ( $ subject ) ; $ this -> pattern [ $ key ] = sprintf ( '%s%s' , $ subject , $ replacement ) ; } return $ this ; }
Allows us to add quantifiers to the pattern created by the last method call
47,746
public function replace ( $ replacement , $ subject , $ seed = '' ) { if ( ! empty ( $ seed ) ) { $ this -> addSeed ( $ seed ) ; } return preg_replace ( $ this -> compile ( ) , $ replacement , $ subject ) ; }
Performs a replacement by using numbered matches
47,747
public function setVars ( $ key , $ value , $ encode = true , $ charset = 'ISO-8859' ) { $ tag = $ this -> config [ 'DELIMITER_LEFT' ] . $ key . $ this -> config [ 'DELIMITER_RIGHT' ] ; if ( strpos ( $ this -> contentXml , $ tag ) === false && strpos ( $ this -> stylesXml , $ tag ) === false ) { throw new OdfException ( "var $key not found in the document" ) ; } $ value = $ encode ? $ this -> recursiveHtmlspecialchars ( $ value ) : $ value ; $ value = ( $ charset == 'ISO-8859' ) ? utf8_encode ( $ value ) : $ value ; $ this -> vars [ $ tag ] = str_replace ( "\n" , "<text:line-break/>" , $ value ) ; return $ this ; }
Assing a template variable
47,748
private function _moveRowSegments ( ) { $ reg1 = "#<table:table-row[^>]*>(.*)</table:table-row>#smU" ; preg_match_all ( $ reg1 , $ this -> contentXml , $ matches ) ; for ( $ i = 0 , $ size = count ( $ matches [ 0 ] ) ; $ i < $ size ; $ i ++ ) { $ reg2 = '#\[!--\sBEGIN\s(row.[\S]*)\s--\](.*)\[!--\sEND\s\\1\s--\]#smU' ; if ( preg_match ( $ reg2 , $ matches [ 0 ] [ $ i ] , $ matches2 ) ) { $ balise = str_replace ( 'row.' , '' , $ matches2 [ 1 ] ) ; $ replace = array ( '[!-- BEGIN ' . $ matches2 [ 1 ] . ' --]' => '' , '[!-- END ' . $ matches2 [ 1 ] . ' --]' => '' , '<table:table-row' => '[!-- BEGIN ' . $ balise . ' --]<table:table-row' , '</table:table-row>' => '</table:table-row>[!-- END ' . $ balise . ' --]' ) ; $ replacedXML = str_replace ( array_keys ( $ replace ) , array_values ( $ replace ) , $ matches [ 0 ] [ $ i ] ) ; $ this -> contentXml = str_replace ( $ matches [ 0 ] [ $ i ] , $ replacedXML , $ this -> contentXml ) ; } } }
Move segment tags for lines of tables Called automatically within the constructor
47,749
private function _parse ( ) { $ this -> contentXml = str_replace ( array_keys ( $ this -> vars ) , array_values ( $ this -> vars ) , $ this -> contentXml ) ; $ this -> stylesXml = str_replace ( array_keys ( $ this -> vars ) , array_values ( $ this -> vars ) , $ this -> stylesXml ) ; }
Merge template variables Called automatically for a save
47,750
public function mergeSegment ( Segment $ segment ) { if ( ! array_key_exists ( $ segment -> getName ( ) , $ this -> segments ) ) { throw new OdfException ( $ segment -> getName ( ) . 'cannot be parsed, has it been set yet ?' ) ; } $ string = $ segment -> getName ( ) ; $ reg = '@\[!--\sBEGIN\s' . $ string . '\s--\](.*)\[!--.+END\s' . $ string . '\s--\]@smU' ; $ this -> contentXml = preg_replace ( $ reg , $ segment -> getXmlParsed ( ) , $ this -> contentXml ) ; foreach ( $ segment -> manif_vars as $ val ) { $ this -> manif_vars [ ] = $ val ; } return $ this ; }
Add the merged segment to the document
47,751
public function setSegment ( $ segment ) { if ( array_key_exists ( $ segment , $ this -> segments ) ) { return $ this -> segments [ $ segment ] ; } $ reg = "#\[!--\sBEGIN\s$segment\s--\](.*?)\[!--\sEND\s$segment\s--\]#smU" ; if ( preg_match ( $ reg , html_entity_decode ( $ this -> contentXml ) , $ m ) == 0 ) { throw new OdfException ( "'$segment' segment not found in the document" ) ; } $ this -> segments [ $ segment ] = new Segment ( $ segment , $ m [ 1 ] , $ this ) ; return $ this -> segments [ $ segment ] ; }
Declare a segment in order to use it in a loop
47,752
public function saveToDisk ( $ file = null ) { if ( $ file !== null && is_string ( $ file ) ) { if ( file_exists ( $ file ) && ! ( is_file ( $ file ) && is_writable ( $ file ) ) ) { throw new OdfException ( 'Permission denied : can\'t create ' . $ file ) ; } $ this -> _save ( ) ; copy ( $ this -> tmpfile , $ file ) ; } else { $ this -> _save ( ) ; } }
Save the odt file on the disk
47,753
public function exportAsAttachedFile ( $ name = "" ) { $ this -> _save ( ) ; if ( headers_sent ( $ filename , $ linenum ) ) { throw new OdfException ( "headers already sent ($filename at $linenum)" ) ; } if ( $ name == "" ) { $ name = md5 ( uniqid ( ) ) . ".odt" ; } header ( 'Content-type: application/vnd.oasis.opendocument.text' ) ; header ( 'Content-Disposition: attachment; filename="' . $ name . '"' ) ; readfile ( $ this -> tmpfile ) ; }
Export the file as attached file by HTTP
47,754
public function getConfig ( $ configKey ) { if ( array_key_exists ( $ configKey , $ this -> config ) ) { return $ this -> config [ $ configKey ] ; } return false ; }
Returns a variable of configuration
47,755
public function merge ( ) { $ this -> xmlParsed .= str_replace ( array_keys ( $ this -> vars ) , array_values ( $ this -> vars ) , $ this -> xml ) ; if ( $ this -> hasChildren ( ) ) { foreach ( $ this -> children as $ child ) { $ this -> xmlParsed = str_replace ( $ child -> xml , ( $ child -> xmlParsed == "" ) ? $ child -> merge ( ) : $ child -> xmlParsed , $ this -> xmlParsed ) ; $ child -> xmlParsed = '' ; foreach ( $ child -> manif_vars as $ file ) { $ this -> manif_vars [ ] = $ file ; } $ child -> manif_vars = array ( ) ; } } $ reg = "/\[!--\sBEGIN\s$this->name\s--\](.*)\[!--\sEND\s$this->name\s--\]/smU" ; $ this -> xmlParsed = preg_replace ( $ reg , '$1' , $ this -> xmlParsed ) ; $ this -> file -> open ( $ this -> odf -> getTmpfile ( ) ) ; foreach ( $ this -> images as $ imageKey => $ imageValue ) { if ( $ this -> file -> getFromName ( 'Pictures/' . $ imageValue ) === false ) { $ this -> file -> addFile ( $ imageKey , 'Pictures/' . $ imageValue ) ; } } $ this -> file -> close ( ) ; return $ this -> xmlParsed ; }
Replace variables of the template in the XML code All the children are also called
47,756
protected function _analyseChildren ( $ xml ) { $ reg2 = "#\[!--\sBEGIN\s([\S]*)\s--\](.*)\[!--\sEND\s(\\1)\s--\]#smU" ; preg_match_all ( $ reg2 , $ xml , $ matches ) ; for ( $ i = 0 , $ size = count ( $ matches [ 0 ] ) ; $ i < $ size ; $ i ++ ) { if ( $ matches [ 1 ] [ $ i ] != $ this -> name ) { $ this -> children [ $ matches [ 1 ] [ $ i ] ] = new self ( $ matches [ 1 ] [ $ i ] , $ matches [ 0 ] [ $ i ] , $ this -> odf ) ; } else { $ this -> _analyseChildren ( $ matches [ 2 ] [ $ i ] ) ; } } return $ this ; }
Analyse the XML code in order to find children
47,757
public function setVars ( $ key , $ value , $ encode = true , $ charset = 'ISO-8859' ) { if ( strpos ( $ this -> xml , $ this -> odf -> getConfig ( 'DELIMITER_LEFT' ) . $ key . $ this -> odf -> getConfig ( 'DELIMITER_RIGHT' ) ) === false ) { throw new SegmentException ( "var $key not found in {$this->getName()}" ) ; } $ value = $ encode ? htmlspecialchars ( $ value ) : $ value ; $ value = ( $ charset == 'ISO-8859' ) ? utf8_encode ( $ value ) : $ value ; $ this -> vars [ $ this -> odf -> getConfig ( 'DELIMITER_LEFT' ) . $ key . $ this -> odf -> getConfig ( 'DELIMITER_RIGHT' ) ] = str_replace ( "\n" , "<text:line-break/>" , $ value ) ; return $ this ; }
Assign a template variable to replace
47,758
public function setImage ( $ key , $ value , $ page = null , $ width = null , $ height = null , $ offsetX = null , $ offsetY = null ) { $ filename = strtok ( strrchr ( $ value , '/' ) , '/.' ) ; $ file = substr ( strrchr ( $ value , '/' ) , 1 ) ; $ size = @ getimagesize ( $ value ) ; if ( $ size === false ) { throw new OdfException ( "Invalid image" ) ; } if ( ! $ width && ! $ height ) { list ( $ width , $ height ) = $ size ; $ width *= Odf :: PIXEL_TO_CM ; $ height *= Odf :: PIXEL_TO_CM ; } $ anchor = $ page == - 1 ? 'text:anchor-type="aschar"' : "text:anchor-type=\"page\" text:anchor-page-number=\"{$page}\" svg:x=\"{$offsetX}cm\" svg:y=\"{$offsetY}cm\"" ; $ xml = <<<IMG<draw:frame draw:style-name="fr1" draw:name="$filename" {$anchor} svg:width="{$width}cm" svg:height="{$height}cm" draw:z-index="3"><draw:image xlink:href="Pictures/$file" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/></draw:frame>IMG ; $ this -> images [ $ value ] = $ file ; $ this -> manif_vars [ ] = $ file ; $ this -> setVars ( $ key , $ xml , false ) ; return $ this ; }
Assign a template variable as a picture
47,759
public function getFromName ( $ name ) { if ( false === $ this -> openned ) { return false ; } $ name = preg_replace ( "/(?:\.|\/)*(.*)/" , "\\1" , $ name ) ; $ extraction = $ this -> pclzip -> extract ( PCLZIP_OPT_BY_NAME , $ name , PCLZIP_OPT_EXTRACT_AS_STRING ) ; if ( ! empty ( $ extraction ) ) { return $ extraction [ 0 ] [ 'content' ] ; } return false ; }
Retrieve the content of a file within the archive from its name
47,760
public function close ( ) { if ( false === $ this -> openned ) { return false ; } $ this -> pclzip = $ this -> filename = null ; $ this -> openned = false ; if ( file_exists ( self :: TMP_DIR ) ) { $ this -> _rrmdir ( self :: TMP_DIR ) ; rmdir ( self :: TMP_DIR ) ; } return true ; }
Close the Zip archive
47,761
private function _rrmdir ( $ dir ) { if ( $ handle = opendir ( $ dir ) ) { while ( false !== ( $ file = readdir ( $ handle ) ) ) { if ( $ file != '.' && $ file != '..' ) { if ( is_dir ( $ dir . '/' . $ file ) ) { $ this -> _rrmdir ( $ dir . '/' . $ file ) ; rmdir ( $ dir . '/' . $ file ) ; } else { unlink ( $ dir . '/' . $ file ) ; } } } closedir ( $ handle ) ; } }
Empty the temporary working directory recursively
47,762
public function render ( $ viewName , $ data = array ( ) ) { try { return $ this -> twig -> render ( $ viewName , $ data ) ; } catch ( \ Twig_Error_Loader $ e ) { throw new TemplateNotFoundError ( $ e -> getMessage ( ) ) ; } catch ( \ Twig_Error_Syntax $ e ) { throw new TemplateSyntaxError ( $ e -> getMessage ( ) , 0 , $ e ) ; } }
Renders the template with the specified name
47,763
public function setSyntax ( $ commentStart = null , $ commentEnd = null , $ blockStart = null , $ blockEnd = null , $ variableStart = null , $ variableEnd = null , $ interpolationStart = null , $ interpolationEnd = null ) { $ this -> twig -> setLexer ( new \ Twig_Lexer ( $ this -> twig , array ( 'tag_comment' => array ( empty ( $ commentStart ) ? '{#' : $ commentStart , empty ( $ commentEnd ) ? '#}' : $ commentEnd ) , 'tag_block' => array ( empty ( $ blockStart ) ? '{%' : $ blockStart , empty ( $ blockEnd ) ? '%}' : $ blockEnd ) , 'tag_variable' => array ( empty ( $ variableStart ) ? '{{' : $ variableStart , empty ( $ variableEnd ) ? '}}' : $ variableEnd ) , 'interpolation' => array ( empty ( $ interpolationStart ) ? '#{' : $ interpolationStart , empty ( $ interpolationEnd ) ? '}' : $ interpolationEnd ) ) ) ) ; }
Changes the syntax recognized by the template engine
47,764
public function getStoragePath ( $ requestedPath ) { $ requestedPath = trim ( $ requestedPath ) ; $ requestedPath = '/' . ltrim ( $ requestedPath , '/' ) ; return $ this -> appStoragePath . $ requestedPath ; }
Returns the path to the specified file or folder inside the private storage of this application
47,765
public function getTemplateManager ( ) { if ( ! isset ( $ this -> templateManager ) ) { $ this -> templateManager = new TemplateManager ( $ this -> templatesPath , $ this -> frameworkStoragePath . self :: TEMPLATES_CACHE_SUBFOLDER ) ; $ this -> templateManager -> addGlobal ( 'app' , $ this ) ; } return $ this -> templateManager ; }
Returns the template manager that can be used to add globals or filters
47,766
public function mail ( ) { if ( ! isset ( $ this -> mail ) ) { $ transport = null ; if ( isset ( $ _ENV [ 'MAIL_TRANSPORT' ] ) ) { if ( $ _ENV [ 'MAIL_TRANSPORT' ] === 'smtp' ) { $ transport = \ Swift_SmtpTransport :: newInstance ( ) ; $ transport -> setHost ( $ _ENV [ 'MAIL_HOST' ] ) ; $ transport -> setPort ( $ _ENV [ 'MAIL_PORT' ] ) ; $ transport -> setUsername ( $ _ENV [ 'MAIL_USERNAME' ] ) ; $ transport -> setPassword ( $ _ENV [ 'MAIL_PASSWORD' ] ) ; if ( ! empty ( $ _ENV [ 'MAIL_TLS' ] ) ) { $ transport -> setEncryption ( 'tls' ) ; } } elseif ( $ _ENV [ 'MAIL_TRANSPORT' ] === 'sendmail' ) { $ sendmailPath = ini_get ( 'sendmail_path' ) ; if ( empty ( $ sendmailPath ) ) { $ sendmailPath = '/usr/sbin/sendmail' ; } $ transport = \ Swift_SendmailTransport :: newInstance ( $ sendmailPath ) ; } elseif ( $ _ENV [ 'MAIL_TRANSPORT' ] === 'php' ) { $ transport = \ Swift_MailTransport :: newInstance ( ) ; } } if ( isset ( $ transport ) ) { $ this -> mail = \ Swift_Mailer :: newInstance ( $ transport ) ; } } return $ this -> mail ; }
Returns the mailing component
47,767
public function ids ( ) { if ( ! isset ( $ this -> ids ) ) { $ this -> ids = new Id ( $ _ENV [ 'SECURITY_IDS_ALPHABET' ] , $ _ENV [ 'SECURITY_IDS_PRIME' ] , $ _ENV [ 'SECURITY_IDS_INVERSE' ] , $ _ENV [ 'SECURITY_IDS_RANDOM' ] ) ; } return $ this -> ids ; }
Returns the component that can be used to encode and decode IDs conveniently for obfuscation
47,768
public function upload ( $ targetDirectory = null ) { $ helper = new FileUpload ( ) ; if ( $ targetDirectory !== null ) { $ helper -> withTargetDirectory ( $ this -> getStoragePath ( $ targetDirectory ) ) ; } return $ helper ; }
Returns a new helper for convenient file uploads
47,769
public function downloadContent ( $ content , $ suggestedFilename , $ mimeType = null ) { if ( $ mimeType === null ) { $ mimeType = 'application/octet-stream' ; } self :: sendDownloadHeaders ( $ mimeType , $ suggestedFilename , strlen ( $ content ) ) ; echo $ content ; }
Sends the specified content to the client and prompts a file download
47,770
public function downloadFile ( $ filePath , $ suggestedFilename , $ mimeType = null ) { if ( \ file_exists ( $ filePath ) && \ is_file ( $ filePath ) ) { if ( $ mimeType === null ) { $ mimeType = 'application/octet-stream' ; } self :: sendDownloadHeaders ( $ mimeType , $ suggestedFilename , filesize ( $ filePath ) ) ; readfile ( $ filePath ) ; } else { throw new \ RuntimeException ( 'File `' . $ filePath . '` not found' ) ; } }
Sends the specified file to the client and prompts a download
47,771
private static function sendDownloadHeaders ( $ mimeType , $ suggestedFilename , $ size ) { header ( 'Content-Type: ' . $ mimeType , true ) ; header ( 'Content-Disposition: attachment; filename="' . $ suggestedFilename . '"' , true ) ; header ( 'Content-Length: ' . $ size , true ) ; header ( 'Accept-Ranges: none' , true ) ; header ( 'Cache-Control: no-cache' , true ) ; header ( 'Connection: close' , true ) ; }
Sends the appropriate response headers for a file download
47,772
public function serveFile ( $ filePath , $ mimeType ) { if ( \ file_exists ( $ filePath ) && \ is_file ( $ filePath ) ) { \ header ( 'Content-Type: ' . $ mimeType , true ) ; \ header ( 'Accept-Ranges: none' , true ) ; \ header ( 'Connection: close' , true ) ; \ readfile ( $ filePath ) ; } else { throw new \ RuntimeException ( 'File `' . $ filePath . '` not found' ) ; } }
Sends the specified file to the client
47,773
public function url ( $ requestedPath ) { $ requestedPath = trim ( $ requestedPath ) ; $ requestedPath = '/' . ltrim ( $ requestedPath , '/' ) ; return $ this -> rootUrl . $ requestedPath ; }
Returns the public URL for the specified path below the root of this application
47,774
public function setContentType ( $ contentType , $ charset = null ) { switch ( $ contentType ) { case 'text' : $ contentType = 'text/plain' ; $ charset = isset ( $ charset ) ? $ charset : 'auto' ; break ; case 'html' : $ contentType = 'text/html' ; $ charset = isset ( $ charset ) ? $ charset : 'auto' ; break ; case 'json' : $ contentType = 'application/json' ; break ; case 'xml' : $ contentType = 'text/xml' ; $ charset = isset ( $ charset ) ? $ charset : 'auto' ; break ; } if ( $ charset === 'auto' ) { if ( isset ( $ _ENV [ 'APP_CHARSET' ] ) ) { $ charset = strtolower ( $ _ENV [ 'APP_CHARSET' ] ) ; } else { $ charset = 'utf-8' ; } } $ headerLine = 'Content-Type: ' . $ contentType ; if ( $ charset !== null ) { $ headerLine .= '; charset=' . $ charset ; } \ header ( $ headerLine ) ; }
Sets the content type and character encoding for the HTTP response
47,775
function hasUpload ( $ name ) { if ( isset ( $ _FILES [ $ name ] ) ) { if ( \ is_array ( $ _FILES [ $ name ] [ 'error' ] ) ) { foreach ( $ _FILES [ $ name ] [ 'error' ] as $ errorCode ) { if ( $ errorCode !== \ UPLOAD_ERR_NO_FILE ) { return true ; } } } else { return $ _FILES [ $ name ] [ 'error' ] !== \ UPLOAD_ERR_NO_FILE ; } } return false ; }
Returns whether the specified file upload has been sent with the current request
47,776
public function hasAny ( ) { return isset ( $ _SESSION [ self :: SESSION_KEY_FLASH ] ) && is_array ( $ _SESSION [ self :: SESSION_KEY_FLASH ] ) && count ( $ _SESSION [ self :: SESSION_KEY_FLASH ] ) > 0 ; }
Returns whether any message is available that could be retrieved
47,777
public function getAll ( ) { if ( $ this -> hasAny ( ) ) { $ messages = $ _SESSION [ self :: SESSION_KEY_FLASH ] ; $ _SESSION [ self :: SESSION_KEY_FLASH ] = [ ] ; return $ messages ; } else { return [ ] ; } }
Retrieves and returns all messages available right now
47,778
private function set ( $ key , $ value ) { if ( ! isset ( $ _SESSION [ self :: SESSION_KEY_FLASH ] ) ) { $ _SESSION [ self :: SESSION_KEY_FLASH ] = [ ] ; } $ _SESSION [ self :: SESSION_KEY_FLASH ] [ $ key ] = ( string ) $ value ; }
Writes a flash message of the specified type
47,779
private function has ( $ key ) { return isset ( $ _SESSION [ self :: SESSION_KEY_FLASH ] ) && isset ( $ _SESSION [ self :: SESSION_KEY_FLASH ] [ $ key ] ) ; }
Returns whether a message of the specified type is available
47,780
public function get ( $ key , $ type = null ) { return self :: fromSource ( \ INPUT_GET , $ _GET , $ key , $ type ) ; }
Returns a validated filtered and typecast value from the GET variables
47,781
public function post ( $ key , $ type = null ) { return self :: fromSource ( \ INPUT_POST , $ _POST , $ key , $ type ) ; }
Returns a validated filtered and typecast value from the POST variables
47,782
public function cookie ( $ key , $ type = null ) { return self :: fromSource ( \ INPUT_COOKIE , $ _COOKIE , $ key , $ type ) ; }
Returns a validated filtered and typecast value from the cookies
47,783
public function value ( $ value , $ type = null ) { if ( ! isset ( $ value ) ) { return null ; } $ type = self :: dataTypeOrDefault ( $ type ) ; if ( $ type === self :: DATA_TYPE_EMAIL || $ type === self :: DATA_TYPE_URL || $ type === self :: DATA_TYPE_IP ) { $ value = \ trim ( $ value ) ; } $ filtered = \ filter_var ( $ value , self :: determineFilterMode ( $ type ) , self :: composeFilterFlags ( $ type ) ) ; return self :: applyPostProcessing ( $ filtered , $ type ) ; }
Validates filters and typecasts the given value
47,784
private static function fromSource ( $ source , $ elements , $ key , $ type = null ) { if ( ! isset ( $ elements ) || ! isset ( $ elements [ $ key ] ) ) { return null ; } $ type = self :: dataTypeOrDefault ( $ type ) ; $ filtered = \ filter_input ( $ source , $ key , self :: determineFilterMode ( $ type ) , self :: composeFilterFlags ( $ type ) ) ; return self :: applyPostProcessing ( $ filtered , $ type ) ; }
Returns a validated filtered and typecast value from the given source
47,785
public function hasMetadata ( $ paramName ) { if ( ! is_string ( $ paramName ) || empty ( $ paramName ) ) { throw new WorkflowException ( "Invalid metadata name : non empty string expected" ) ; } return array_key_exists ( $ paramName , $ this -> _metadata ) ; }
Test if a metadata parameter is defined .
47,786
public static function getNextStatusListData ( $ model , $ validate = false , $ beforeEvents = false , $ includeCurrent = false ) { if ( ! SimpleWorkflowBehavior :: isAttachedTo ( $ model ) ) { throw new WorkflowException ( 'The model does not have a SimpleWorkflowBehavior behavior' ) ; } $ listData = [ ] ; if ( $ includeCurrent ) { $ currentStatus = $ model -> getWorkflowStatus ( ) ; $ listData [ $ currentStatus -> getId ( ) ] = $ currentStatus -> getLabel ( ) ; } $ report = $ model -> getNextStatuses ( $ validate , $ beforeEvents ) ; foreach ( $ report as $ endStatusId => $ info ) { if ( ! isset ( $ info [ 'isValid' ] ) || $ info [ 'isValid' ] === true ) { $ listData [ $ endStatusId ] = $ info [ 'status' ] -> getLabel ( ) ; } } return $ listData ; }
Returns an associative array containing all statuses that can be reached by model .
47,787
public static function renderLabel ( $ model ) { if ( $ model -> hasWorkflowStatus ( ) ) { $ labelTemplate = $ model -> getWorkflowStatus ( ) -> getMetadata ( 'labelTemplate' ) ; if ( ! empty ( $ labelTemplate ) ) { return strtr ( $ labelTemplate , [ '{label}' => $ model -> getWorkflowStatus ( ) -> getLabel ( ) ] ) ; } } return null ; }
Displays the status for the model passed as argument .
47,788
public static function getStatusDropDownData ( $ model , $ beforeEvents = false ) { $ transitions = array_keys ( static :: getNextStatusListData ( $ model , false , $ beforeEvents ) ) ; $ items = static :: getAllStatusListData ( $ model -> getWorkflow ( ) -> getId ( ) , $ model -> getWorkflowSource ( ) ) ; $ options = [ ] ; foreach ( array_keys ( $ items ) as $ status ) { if ( $ status != $ model -> getWorkflowStatus ( ) -> getId ( ) && ! in_array ( $ status , $ transitions ) ) { $ options [ $ status ] [ 'disabled' ] = true ; } } return [ 'items' => $ items , 'options' => $ options , ] ; }
Returns the items and options for a dropDownList All status options are in the list but invalid transitions are disabled
47,789
public static function getNextStatus ( $ model ) { $ currentStatus = $ model -> getAttribute ( 'status' ) ; $ statusList = $ model -> getWorkflowSource ( ) -> getAllStatuses ( $ model -> getWorkflow ( ) -> getId ( ) ) ; $ transitions = array_keys ( WorkflowHelper :: getNextStatusListData ( $ model ) ) ; $ started = false ; foreach ( $ statusList as $ status ) { $ status_id = $ status -> getId ( ) ; if ( $ started ) { if ( in_array ( $ status_id , $ transitions ) && static :: isValidNextStatus ( $ model , $ status_id ) ) { return $ status_id ; } } if ( $ status_id == $ currentStatus ) { $ started = true ; } } return $ currentStatus ; }
Returns the status string of the next valid status from the list of transitions
47,790
public static function isValidNextStatus ( $ model , $ status_id ) { $ eventSequence = $ model -> getEventSequence ( $ status_id ) ; foreach ( $ eventSequence [ 'before' ] as $ event ) { if ( $ model -> hasEventHandlers ( $ event -> name ) ) { $ model -> trigger ( $ event -> name , $ event ) ; if ( $ event -> isValid === false ) { return false ; } } } return true ; }
Checks if a given status is a valid transition from the current status
47,791
private function collectTransitions ( ) { $ nlEdges = $ this -> _xp -> query ( '//ns:edge' ) ; if ( $ nlEdges -> length == 0 ) { throw new WorkflowException ( "no edge could be found in this workflow" ) ; } $ result = [ ] ; for ( $ i = 0 ; $ i < $ nlEdges -> length ; $ i ++ ) { $ currentNode = $ nlEdges -> item ( $ i ) ; $ source = trim ( $ this -> _xp -> query ( "@source" , $ currentNode ) -> item ( 0 ) -> value ) ; $ target = trim ( $ this -> _xp -> query ( "@target" , $ currentNode ) -> item ( 0 ) -> value ) ; if ( ! isset ( $ result [ $ source ] ) || ! isset ( $ result [ $ source ] [ $ target ] ) ) { $ result [ $ source ] [ $ target ] = [ ] ; } } return $ result ; }
Extract edges defined in the graphml input file
47,792
public function invalidate ( $ message = null , $ handled = false ) { $ this -> isValid = false ; $ this -> handled = $ handled ; if ( ! empty ( $ message ) ) { $ this -> _errorMessage [ ] = $ message ; } }
Invalidate this event .
47,793
public function run ( $ id , $ status ) { $ model = $ this -> findModel ( $ id ) ; $ model -> load ( Yii :: $ app -> request -> post ( ) ) ; $ changedStatus = $ model -> sendToStatus ( $ status ) ; $ model -> save ( ) ; return $ this -> response ( $ changedStatus , $ model ) ; }
Runs this action with the specified parameters . This method is mainly invoked by the controller
47,794
public static function changeStatus ( $ start , $ end ) { if ( empty ( $ start ) || ! is_string ( $ start ) ) { throw new WorkflowException ( '$start must be a string' ) ; } if ( empty ( $ end ) || ! is_string ( $ end ) ) { throw new WorkflowException ( '$end must be a string' ) ; } return 'from {' . $ start . '} to {' . $ end . '}' ; }
Returns the scenario name for a change status action .
47,795
public static function match ( $ scenario1 , $ scenario2 ) { $ match1 = $ match2 = [ ] ; if ( preg_match_all ( '/([^\\}{]*)\{([^\{\}]+)\}/' , $ scenario1 , $ match1 , PREG_SET_ORDER ) && preg_match_all ( '/([^\\}{]*)\{([^\{\}]+)\}/' , $ scenario2 , $ match2 , PREG_SET_ORDER ) ) { if ( count ( $ match1 ) != count ( $ match2 ) ) { return false ; } for ( $ i = 0 ; $ i < count ( $ match1 ) ; $ i ++ ) { if ( str_replace ( ' ' , '' , $ match1 [ $ i ] [ 1 ] ) != str_replace ( ' ' , '' , $ match2 [ $ i ] [ 1 ] ) ) { return false ; } if ( $ match1 [ $ i ] [ 2 ] != $ match2 [ $ i ] [ 2 ] && $ match1 [ $ i ] [ 2 ] != '*' && $ match2 [ $ i ] [ 2 ] != '*' ) { return false ; } } } else { return false ; } return true ; }
Test if 2 scenario match .
47,796
public function loadDefinition ( $ workflowId , $ source ) { $ wd = require_once ( $ this -> createFilename ( $ workflowId ) ) ; return $ this -> parse ( $ workflowId , $ wd , $ source ) ; }
Loads and returns the workflow definition available as a PHP array in a file . If a parser has been configured it is used to converte the array structure defined in the file into the format expected by the WorkflowFileSource class .
47,797
public function validateAttribute ( $ object , $ attribute ) { if ( ! SimpleWorkflowBehavior :: isAttachedTo ( $ object ) ) { throw new WorkflowException ( 'Validation error : the model does not have the SimpleWorkflowBehavior' ) ; } try { $ scenarioList = $ object -> getScenarioSequence ( $ object -> $ attribute ) ; } catch ( WorkflowException $ e ) { $ object -> addError ( $ attribute , 'Workflow validation failed : ' . $ e -> getMessage ( ) ) ; $ scenarioList = [ ] ; } if ( count ( $ scenarioList ) != 0 ) { foreach ( $ object -> getValidators ( ) as $ validator ) { foreach ( $ scenarioList as $ scenario ) { if ( $ this -> _isActiveValidator ( $ validator , $ scenario ) ) { $ validator -> validateAttributes ( $ object ) ; } } } } }
Apply active validators for the current workflow event sequence .
47,798
private function _isActiveValidator ( $ validator , $ currentScenario ) { foreach ( $ validator -> on as $ scenario ) { if ( WorkflowScenario :: match ( $ scenario , $ currentScenario ) ) { return true ; } } return false ; }
Checks if a validator is active for the workflow event passed as argument . A Validator is active if it is configured for a scenario that matches the current scenario .
47,799
public function loadDefinition ( $ workflowId , $ source ) { $ wfClassname = $ this -> getClassname ( $ workflowId ) ; $ defProvider = null ; try { $ defProvider = Yii :: createObject ( [ 'class' => $ wfClassname ] ) ; } catch ( \ ReflectionException $ e ) { throw new WorkflowException ( 'failed to load workflow definition : ' . $ e -> getMessage ( ) ) ; } if ( ! $ defProvider instanceof IWorkflowDefinitionProvider ) { throw new WorkflowException ( 'Invalid workflow provider : class ' . $ wfClassname . ' doesn\'t implement \raoul2000\workflow\source\file\IWorkflowDefinitionProvider' ) ; } return $ this -> parse ( $ workflowId , $ defProvider -> getDefinition ( ) , $ source ) ; }
Instanciate the PHP class to use as workflow definition provider retrieve the workflow definition and parses it .