idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
56,100
public static function sslConnect ( $ host , $ user , $ password , $ name , $ key , $ cert , $ ca ) { if ( $ key == "" || $ cert == "" || $ ca == "" ) { throw new MysqlUtilsException ( "SSL parameters error" ) ; } $ mysqliRef = mysqli_init ( ) ; $ mysqliRef -> ssl_set ( $ key , $ cert , $ ca , null , null ) ; $ connected = @ $ mysqliRef -> real_connect ( $ host , $ user , $ password , $ name , 3306 , null , MYSQLI_CLIENT_SSL ) ; if ( ! $ connected || $ mysqliRef -> connect_error ) { throw new MysqlUtilsException ( 'Database connection error (' . $ mysqliRef -> connect_errno . ') ' . $ mysqliRef -> connect_error ) ; } return $ mysqliRef ; }
Init a mysqli connection over SSL
56,101
public static function connect ( $ host , $ user , $ password , $ name ) { $ mysqliRef = mysqli_init ( ) ; $ connected = @ $ mysqliRef -> real_connect ( $ host , $ user , $ password , $ name ) ; if ( ! $ connected || $ mysqliRef -> connect_error ) { throw new MysqlUtilsException ( 'Database connection error (' . $ mysqliRef -> connect_errno . ') ' . $ mysqliRef -> connect_error ) ; } return $ mysqliRef ; }
Init a normal mysqli connection
56,102
private function apply ( array $ data ) { $ data = array_intersect_key ( $ data , get_object_vars ( $ this ) ) ; $ values = array_filter ( $ data , static function ( $ value ) { return null !== $ value ; } ) ; $ types = array_intersect_key ( $ this -> types ( ) , $ values ) ; $ expects = array_intersect_key ( $ this -> expects ( ) , $ values ) ; foreach ( $ types as $ key => $ type ) { settype ( $ data [ $ key ] , $ type ) ; } foreach ( $ expects as $ key => $ class ) { if ( false === $ data [ $ key ] instanceof $ class ) { throw new \ DomainException ( sprintf ( 'Expected value of `%s` to be an object of `%s` type' , $ key , $ class ) ) ; } } foreach ( $ data as $ key => $ value ) { $ this -> $ key = $ value ; } $ this -> validate ( ) ; }
Update the current object with new values
56,103
public function toArray ( ) { return array_map ( static function ( $ value ) { if ( $ value instanceof ArraySerializableInterface ) { $ value = $ value -> toArray ( ) ; } return $ value ; } , get_object_vars ( $ this ) ) ; }
Get the current object values as an array
56,104
protected function getModuleId ( $ filePath ) { preg_match ( '/.*(protected|public|private)\s\$id\s=\s(\'|\")(?P<id>.*)(\'|\")\;.*/' , file_get_contents ( $ filePath ) , $ matches ) ; if ( array_key_exists ( 'id' , $ matches ) && isset ( $ matches [ 'id' ] { 0 } ) ) { return $ matches [ 'id' ] ; } else { return false ; } }
Get module id
56,105
protected function getClassParentModule ( Container $ container , $ className , array $ ignoredClasses = [ ExternalModule :: class , CompressableExternalModule :: class , \ samson \ core \ Service :: class , CompressableService :: class ] ) { if ( ! in_array ( $ className , $ ignoredClasses , true ) ) { try { $ instance = $ container -> get ( trim ( $ className ) ) ; $ instance -> parent = $ this -> getClassParentModule ( $ container , get_parent_class ( $ instance ) ) ; return $ instance ; } catch ( \ Exception $ exception ) { return null ; } } return null ; }
Find parent module by OOP class inheritance .
56,106
public function addConfig ( array $ config , $ environment = null ) { $ env = ( $ environment ) ? $ environment : '_top' ; $ this -> values [ $ env ] = ( array_key_exists ( $ env , $ this -> values ) ) ? array_replace_recursive ( $ this -> values [ $ env ] , $ config ) : $ config ; $ this -> buildCache = null ; return $ this ; }
Adds config into this object
56,107
public function email ( $ name , $ value = NULL , $ options = [ ] ) { $ this -> addErrorClass ( $ name , $ options ) ; $ tags [ 'input' ] = parent :: email ( $ name , $ value , $ options ) ; $ tags [ 'error' ] = $ this -> getErrorTag ( $ name ) ; return $ this -> buildTags ( $ tags ) ; }
Create a email input field .
56,108
public function password ( $ name , $ options = [ ] ) { $ this -> addErrorClass ( $ name , $ options ) ; $ tags [ 'input' ] = parent :: password ( $ name , $ options ) ; $ tags [ 'error' ] = $ this -> getErrorTag ( $ name ) ; return $ this -> buildTags ( $ tags ) ; }
Create a password input field .
56,109
public function textarea ( $ name , $ value = null , $ options = [ ] ) { $ this -> addErrorClass ( $ name , $ options ) ; $ tags [ 'input' ] = parent :: textarea ( $ name , $ value , $ options ) ; $ tags [ 'error' ] = $ this -> getErrorTag ( $ name ) ; return $ this -> buildTags ( $ tags ) ; }
Create a textarea input .
56,110
public function current ( ) { $ val = $ this -> base [ 'value' ] [ $ this -> position ] ; $ layout = $ val [ 'acf_fc_layout' ] ; $ group = new LayoutFieldGroup ( $ this -> getLayoutFields ( $ layout ) , $ val , $ this , $ this -> fieldFactory ) ; return $ group -> setLayout ( $ layout ) ; }
Get the current flexible content item .
56,111
public static function section ( $ name , $ args , $ child ) { $ args [ "sectionPath" ] = $ args [ "path" ] ; unset ( $ args [ "path" ] ) ; Router :: $ sections [ ] = [ $ name , $ args , $ child , Router :: $ context ] ; }
Add section to the router the class will handle object creation
56,112
public static function page ( $ name = "" , $ args = [ ] ) { if ( Router :: $ context == "" ) $ path = "/" . $ name ; else $ path = Router :: $ context . "/" . $ name ; $ path = str_replace ( "root/" , "" , $ path ) ; Router :: $ routes [ $ path ] = array_merge ( Router :: $ stackedOptions , $ args ) ; }
Add page to a specific section
56,113
public static function notFound ( $ arg1 , $ arg2 = null ) { if ( is_null ( $ arg2 ) ) { $ name = "404" ; $ args = $ arg1 ; } else { $ name = $ arg1 ; $ args = $ arg2 ; } $ args [ "pageName" ] = "404" ; Router :: page ( $ name , $ args ) ; }
Add a home page to a specifc section
56,114
public static function build ( ) { while ( count ( Router :: $ sections ) > 0 ) { $ section = array_shift ( Router :: $ sections ) ; $ name = $ section [ 0 ] ; $ options = $ section [ 1 ] ; $ callback = $ section [ 2 ] ; $ context = $ section [ 3 ] ; Router :: $ context = $ context . "/" . ( ( $ context == "root" ) ? "" : $ name ) ; Router :: $ stackedOptions = $ options ; $ callback ( ) ; } ksort ( Router :: $ routes ) ; }
After this method is called you can t add more paths to the router
56,115
public static function find ( ) { if ( count ( Router :: $ routes ) == 0 ) return null ; echo Router :: $ queryString ; if ( Router :: $ queryString == "" ) { Router :: $ target = Router :: $ routes [ "/" ] ; } else if ( isset ( Router :: $ routes [ "/" . Router :: $ queryString ] ) ) { } Router :: $ built = true ; }
Must be called after build method
56,116
public function digipolisCleanDir ( $ dirs , $ opts = [ 'sort' => PartialCleanDirsTask :: SORT_NAME ] ) { $ dirsArg = array ( ) ; foreach ( array_map ( 'trim' , explode ( ',' , $ dirs ) ) as $ dir ) { $ dirParts = explode ( ':' , $ dir ) ; if ( count ( $ dirParts ) > 1 ) { $ dirsArg [ $ dirParts [ 0 ] ] = $ dirParts [ 1 ] ; continue ; } $ dirsArg [ ] = $ dirParts [ 0 ] ; } return $ this -> taskPartialCleanDirs ( $ dirsArg ) -> sortBy ( $ opts [ 'sort' ] ) -> run ( ) ; }
Partially clean directories .
56,117
public function answerWith ( Type $ collectedData , array $ metadata = [ ] ) { $ collectedPayload = Payload :: fromType ( $ collectedData ) ; $ collectedDataTypeClass = $ collectedPayload -> getTypeClass ( ) ; if ( $ this -> payload -> getTypeClass ( ) !== $ collectedPayload -> getTypeClass ( ) ) { throw InvalidTypeException :: fromInvalidArgumentExceptionAndPrototype ( new \ InvalidArgumentException ( sprintf ( "Type %s of collected data does not match the type of requested data %s" , $ collectedPayload -> getTypeClass ( ) , $ this -> payload -> getTypeClass ( ) ) ) , $ collectedDataTypeClass :: prototype ( ) ) ; } $ type = MessageNameUtils :: getTypePartOfMessageName ( $ this -> messageName ) ; $ metadata = ArrayUtils :: merge ( $ this -> metadata , $ metadata ) ; return new self ( $ collectedPayload , MessageNameUtils :: getDataCollectedEventName ( $ type ) , $ this -> target , $ this -> origin , $ metadata , $ this -> processTaskListPosition , $ this -> version + 1 ) ; }
Transforms current message to a data collected event and replaces payload data with collected data
56,118
public function prepareDataProcessing ( TaskListPosition $ newTaskListPosition , $ target , array $ metadata = [ ] ) { $ type = MessageNameUtils :: getTypePartOfMessageName ( $ this -> messageName ) ; $ metadata = ArrayUtils :: merge ( $ this -> metadata , $ metadata ) ; return new self ( $ this -> payload , MessageNameUtils :: getProcessDataCommandName ( $ type ) , $ this -> target , $ target , $ metadata , $ newTaskListPosition , $ this -> version + 1 ) ; }
Transforms current message to a process data command
56,119
public function answerWithDataProcessingCompleted ( array $ metadata = [ ] ) { $ type = MessageNameUtils :: getTypePartOfMessageName ( $ this -> messageName ) ; $ metadata = ArrayUtils :: merge ( $ this -> metadata , $ metadata ) ; return new self ( $ this -> payload , MessageNameUtils :: getDataProcessedEventName ( $ type ) , $ this -> target , $ this -> origin , $ metadata , $ this -> processTaskListPosition , $ this -> version + 1 ) ; }
Transforms current message to a data processed event
56,120
public function getTerms ( $ topLevel = false , $ options = array ( ) ) { $ terms = array ( ) ; $ wpTerms = get_terms ( $ this -> getName ( ) , array_merge ( array ( 'hide_empty' => false , 'parent' => $ topLevel ? 0 : '' ) , $ options ) ) ; foreach ( $ wpTerms as $ termData ) { $ terms [ ] = $ this -> termFactory -> create ( $ termData , $ this ) ; } return $ terms ; }
Get all Terms in this taxonomy .
56,121
public function getTermsForPost ( AbstractPost $ post ) { $ terms = array ( ) ; if ( $ dbTerms = get_the_terms ( $ post -> getId ( ) , $ this -> getName ( ) ) ) { foreach ( $ dbTerms as $ termData ) { $ terms [ ] = $ this -> termFactory -> create ( $ termData , $ this ) ; } } return $ terms ; }
Get all terms in this taxonomy for the given post .
56,122
public function generateToken ( ) { $ token = md5 ( __CLASS__ . uniqid ( ) ) ; $ sesCont = new SessionContainer ( self :: SESSION_KEY ) ; $ sesCont -> $ token = time ( ) ; $ sesCont -> setExpirationSeconds ( 30 , $ token ) ; return $ token ; }
Store a unique key in session to validate rest calls
56,123
public function attachScripts ( ) { if ( $ this -> isScriptsAttached ( ) ) return $ this ; $ view = $ this -> getView ( ) ; $ view -> inlineScript ( ) -> appendFile ( $ view -> staticsUri ( 'Yima.Widgetator.JS.Jquery.Json' ) ) -> appendFile ( $ view -> staticsUri ( 'Yima.Widgetator.JS.Jquery.Ajaxq' ) ) -> appendFile ( $ view -> staticsUri ( 'Yima.Widgetator.JS.Jquery.WidgetAjaxy' ) ) ; $ this -> isScriptAttached = true ; return $ this ; }
Attach needed scripts to load widgets
56,124
public static function url ( $ endpoint = null , $ suffix = '' ) { $ base = Phramework :: getSetting ( 'base' ) ; if ( $ endpoint ) { $ suffix = $ endpoint . '/' . $ suffix ; $ suffix = str_replace ( '//' , '/' , $ suffix ) ; } return $ base . $ suffix ; }
Get url of the API resource .
56,125
public static function curlHeaders ( $ url , & $ data ) { $ ch = curl_init ( $ url ) ; curl_setopt ( $ ch , CURLOPT_NOBODY , true ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_HEADER , true ) ; curl_setopt ( $ ch , CURLOPT_FOLLOWLOCATION , true ) ; curl_setopt ( $ ch , CURLOPT_MAXREDIRS , 5 ) ; $ data = curl_exec ( $ ch ) ; $ headers = curl_getinfo ( $ ch ) ; curl_close ( $ ch ) ; return $ headers ; }
Get Headers from a remote link
56,126
public static function curlDownload ( $ url , $ path , $ timeout = 3600 ) { $ return = false ; try { $ fp = fopen ( $ path , 'w+' ) ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , false ) ; curl_setopt ( $ ch , CURLOPT_BINARYTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , false ) ; curl_setopt ( $ ch , CURLOPT_CONNECTTIMEOUT , $ timeout ) ; curl_setopt ( $ ch , CURLOPT_FILE , $ fp ) ; $ return = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; fclose ( $ fp ) ; } catch ( \ Exception $ e ) { return false ; } return $ return ; }
Download a file from a remote link
56,127
public static function tempfile ( $ prefix ) { global $ settings ; $ folder = '/tmp' ; if ( isset ( $ settings [ 'temporary_folder' ] ) ) { $ folder = $ settings [ 'temporary_folder' ] ; } return tempnam ( $ folder , $ prefix ) ; }
Create a temporary file path
56,128
public static function parseFile ( $ filename , & $ extendedFiles = null ) { $ schema = static :: annotateSchema ( Utils :: parse_json_file ( $ filename ) , false ) ; $ extends_file = isset ( $ schema [ 'extends_file' ] ) ? dirname ( $ filename ) . '/' . $ schema [ 'extends_file' ] : null ; while ( $ extends_file !== null ) { if ( $ extendedFiles !== null ) { $ extendedFiles [ ] = $ extends_file ; } $ part = static :: annotateSchema ( Utils :: parse_json_file ( $ extends_file ) , str_replace ( '.schema.json' , '' , basename ( $ extends_file ) ) ) ; $ extends_file = isset ( $ part [ 'extends_file' ] ) ? dirname ( $ extends_file ) . '/' . $ part [ 'extends_file' ] : null ; $ schema = static :: extendSchema ( $ part , $ schema ) ; } if ( isset ( $ schema [ 'extends_file' ] ) ) { unset ( $ schema [ 'extends_file' ] ) ; } return $ schema ; }
Read and process file read dependencies if exist .
56,129
protected static function annotateSchema ( $ schema , $ annotation , $ path = '' ) { if ( isset ( $ schema [ 'type' ] ) && ! isset ( $ schema [ '_annotation' ] ) ) { $ schema [ '_annotation' ] = $ annotation ; } foreach ( [ 'properties' , 'patternProperties' ] as $ p ) { if ( isset ( $ schema [ $ p ] ) ) { foreach ( $ schema [ $ p ] as $ k => & $ v ) { $ v = static :: annotateSchema ( $ v , $ annotation , $ path . '/' . $ p . '/' . $ k ) ; } } } foreach ( [ 'items' , 'additionalProperties' ] as $ p ) { if ( isset ( $ schema [ $ p ] ) ) { $ schema [ $ p ] = static :: annotateSchema ( $ schema [ $ p ] , $ annotation , $ path . '/' . $ p ) ; } } return $ schema ; }
Annotate schema with an annotation .
56,130
public function createFailed ( $ errors = null ) { app ( 'antares.messages' ) -> add ( 'error' , empty ( $ errors ) ? trans ( 'Unable to add language.' ) : $ errors ) ; return redirect ( ) -> back ( ) ; }
Response when storing language failed
56,131
public function publishFailed ( $ type , $ error = null ) { app ( 'antares.messages' ) -> add ( 'error' , is_null ( $ error ) ? trans ( 'Translations has not been published.' ) : $ error ) ; return redirect ( handles ( 'antares::translations/index/' . $ type ) ) ; }
response when publishing failed
56,132
public function changeFailed ( $ error = null ) { app ( 'antares.messages' ) -> add ( 'error' , is_null ( $ error ) ? trans ( 'Language has not been changed.' ) : $ error ) ; return redirect ( ) -> back ( ) ; }
response when changing language failed
56,133
public function deleteFailed ( $ error = null ) { app ( 'antares.messages' ) -> add ( 'error' , $ error ? $ error : trans ( 'Language has not been deleted.' ) ) ; return redirect ( ) -> back ( ) ; }
response when deletion failed
56,134
public function defaultFailed ( $ error = null ) { app ( 'antares.messages' ) -> add ( 'error' , $ error ? $ error : trans ( 'Language has not been set as default.' ) ) ; return redirect ( ) -> back ( ) ; }
Response when default language has not been set
56,135
protected function removeDir ( $ realPath , $ keep = false ) { if ( $ keep || @ rmdir ( $ realPath ) ) { return true ; } else { return $ this -> setError ( Message :: get ( Message :: STR_DELETE_FAIL , $ realPath ) , Message :: STR_DELETE_FAIL ) ; } }
Remove the directory itself
56,136
public function setItems ( array $ items ) { $ items = $ this -> getArrayableItems ( $ items ) ; foreach ( $ items as $ item ) { $ this -> checkType ( $ item ) ; } $ this -> items = $ items ; return $ this ; }
Sets an array as the content of the collection .
56,137
public function filter ( callable $ callback = null ) { if ( ! is_null ( $ callback ) ) { return new static ( $ this -> wye , array_filter ( $ this -> items , $ callback , ARRAY_FILTER_USE_BOTH ) ) ; } return new static ( $ this -> wye , array_filter ( $ this -> items ) ) ; }
Create a new collection containing the items of the original collection that pass the given callback . When no callback is provided falsey values are removed .
56,138
public function last ( callable $ callback = null , $ default = null ) { $ items = array_reverse ( $ this -> items ) ; if ( is_null ( $ callback ) ) { if ( empty ( $ items ) ) { return null ; } foreach ( $ items as $ value ) { return $ value ; } } foreach ( $ items as $ key => $ value ) { if ( call_user_func ( $ callback , $ value , $ key ) ) { return $ value ; } } return $ default ; }
Retrieve the last item in the collection or the last item that matches the criteria defined in a function . When matching by a function a default value may be set if no results are found .
56,139
public function push ( ... $ values ) { foreach ( $ values as $ value ) { $ this -> offsetSet ( null , $ value ) ; } return $ this ; }
Appends one or more values to the end of the collection s items .
56,140
public function unshift ( ... $ values ) { foreach ( $ values as $ value ) { $ this -> checkType ( $ value ) ; } foreach ( array_reverse ( $ values ) as $ value ) { array_unshift ( $ this -> items , $ value ) ; } return $ this ; }
Appends one or more values to the beginning of the collection s items .
56,141
protected function checkType ( $ item ) { if ( $ this -> isCorrectType ( $ item ) === false ) { $ error = sprintf ( '%s may contain only values of type %s, %s given.' , get_class ( $ this ) , $ this -> type , is_object ( $ item ) ? get_class ( $ item ) : gettype ( $ item ) ) ; throw new InvalidArgumentException ( $ error ) ; } return true ; }
Checks an item to ensure it of the correct type and throws an exception if the type is invalid .
56,142
protected function getArrayableItems ( $ items ) { if ( is_array ( $ items ) ) { return $ items ; } if ( $ items instanceof Traversable ) { return iterator_to_array ( $ items ) ; } return ( array ) $ items ; }
Convert input into an array .
56,143
protected function isCorrectType ( $ item ) { if ( is_null ( $ this -> type ) ) { return true ; } if ( $ this -> type !== 'object' && is_object ( $ item ) ) { return $ item instanceof $ this -> type ; } return gettype ( $ item ) === $ this -> type ; }
Checks if an item is the correct type as set for the collection .
56,144
public function apply ( $ testable , array $ config = array ( ) ) { $ message = 'Protected method {:name} must start with an underscore' ; $ tokens = $ testable -> tokens ( ) ; $ filtered = $ testable -> findAll ( array ( T_PROTECTED ) ) ; foreach ( $ filtered as $ tokenId ) { $ token = $ tokens [ $ tokenId ] ; $ parent = $ testable -> findNext ( array ( T_FUNCTION , T_VARIABLE ) , $ tokenId ) ; $ parentLabel = Parser :: label ( $ parent , $ tokens ) ; if ( substr ( $ parentLabel , 0 , 1 ) !== '_' ) { $ classTokenId = $ testable -> findNext ( array ( T_STRING ) , $ token [ 'parent' ] ) ; $ classname = $ tokens [ $ classTokenId ] [ 'content' ] ; $ params = array ( 'message' => String :: insert ( $ message , array ( 'name' => $ parentLabel , ) ) , 'line' => $ token [ 'line' ] ) ; if ( $ this -> _strictMode ( $ classname ) ) { $ this -> addViolation ( $ params ) ; } else { $ this -> addWarning ( $ params ) ; } } } }
Will iterate the tokens looking for protected methods and variables once found it will validate the name of it s parent starts with an underscore .
56,145
protected function _strictMode ( $ classname ) { foreach ( $ this -> _exceptions as $ regex ) { if ( preg_match ( "/{$regex}/" , $ classname ) ) { return false ; } } return true ; }
Will iterate over exceptions regex to see if the rule need to be strictly applied .
56,146
public static function label ( $ tokenId , array $ tokens ) { $ token = $ tokens [ $ tokenId ] ; $ hasName = in_array ( $ token [ 'id' ] , array ( T_FUNCTION , T_CLASS , T_INTERFACE , T_VARIABLE , ) ) ; if ( $ hasName ) { if ( $ token [ 'id' ] === T_VARIABLE ) { return substr ( $ token [ 'content' ] , 1 ) ; } $ total = count ( $ tokens ) ; for ( $ key = $ tokenId ; $ key <= $ total ; $ key ++ ) { if ( $ tokens [ $ key ] [ 'id' ] === T_STRING ) { return $ tokens [ $ key ] [ 'content' ] ; } elseif ( in_array ( $ tokens [ $ key ] [ 'content' ] , array ( '(' , '{' , ':' ) ) ) { break ; } } } return null ; }
Will find the label of the given token .
56,147
public static function parameters ( $ tokenId , array $ tokens ) { $ params = array ( ) ; if ( $ tokens [ $ tokenId ] [ 'id' ] !== T_FUNCTION ) { throw new \ Exception ( 'Cannot call params on non function' ) ; } $ foundOpen = false ; $ total = count ( $ tokens ) ; for ( $ key = $ tokenId ; $ key <= $ total ; $ key ++ ) { $ token = $ tokens [ $ key ] ; if ( $ foundOpen ) { if ( $ token [ 'content' ] === ')' ) { break ; } elseif ( $ token [ 'id' ] === T_VARIABLE ) { $ params [ ] = $ key ; } } elseif ( $ token [ 'content' ] === '(' ) { $ foundOpen = true ; } } return $ params ; }
Will return the parameters of a given token .
56,148
public static function modifiers ( $ tokenId , array $ tokens ) { if ( ! in_array ( $ tokens [ $ tokenId ] [ 'id' ] , array ( T_CLASS , T_FUNCTION , T_VARIABLE ) ) ) { $ token = print_r ( $ tokens [ $ tokenId ] , true ) ; throw new \ Exception ( 'Cannot call modifiers on non class/function/variable' . $ token ) ; } $ modifiers = array ( ) ; for ( $ key = $ tokenId - 1 ; $ key >= 0 ; $ key -- ) { $ token = $ tokens [ $ key ] ; if ( $ token [ 'id' ] === T_WHITESPACE ) { continue ; } elseif ( in_array ( $ token [ 'id' ] , static :: $ modifiers ) ) { $ modifiers [ ] = $ key ; } else { break ; } } return $ modifiers ; }
Will return a list of all the modifiers for a given token .
56,149
protected static function _checksum ( array $ token , $ isString ) { $ token [ 'checksum' ] = static :: $ _bracketsChecksum ; if ( $ isString ) { return $ token ; } $ char = $ token [ 'content' ] ; if ( $ char === ')' || $ char === ']' || $ char === '}' ) { $ token [ 'checksum' ] = -- static :: $ _bracketsChecksum ; } elseif ( $ char === '(' || $ char === '[' || $ char === '{' ) { static :: $ _bracketsChecksum ++ ; } return $ token ; }
Update the bracket checksum values for a token .
56,150
protected static function _isEndOfParent ( $ tokenId , $ parentId , array $ tokens ) { if ( ! isset ( $ tokens [ $ parentId ] ) ) { return false ; } $ diff = $ tokens [ $ tokenId ] [ 'checksum' ] - $ tokens [ $ parentId ] [ 'checksum' ] ; if ( $ diff > 0 ) { return false ; } $ token = $ tokens [ $ tokenId ] ; $ parent = $ tokens [ $ parentId ] ; $ endingTokens = static :: $ _parentTokens [ $ parent [ 'id' ] ] [ 'endingTokens' ] ; if ( isset ( $ endingTokens [ $ token [ 'name' ] ] ) || ( $ diff < 0 && $ token [ 'name' ] === '}' ) ) { return $ tokens [ $ parentId ] [ 'parent' ] ; } return false ; }
Will determine if this is the end of the current parent .
56,151
protected static function _tokenize ( array $ tokens ) { $ inString = false ; $ results = array ( ) ; $ cpt = 0 ; $ previousTokenId = null ; foreach ( $ tokens as $ tokenId => $ token ) { if ( $ token [ 'content' ] === '"' ) { if ( ! $ inString ) { $ token [ 'id' ] = T_START_DOUBLE_QUOTE ; $ token [ 'name' ] = 'T_START_DOUBLE_QUOTE' ; } else { $ token [ 'id' ] = T_END_DOUBLE_QUOTE ; $ token [ 'name' ] = 'T_END_DOUBLE_QUOTE' ; } $ inString = ! $ inString ; } $ isCurlyBrace = ( $ token [ 'content' ] === '$' && isset ( $ tokens [ $ tokenId + 1 ] ) && $ tokens [ $ tokenId + 1 ] [ 'content' ] === '{' ) ; if ( $ isCurlyBrace ) { $ token [ 'id' ] = T_DOLLAR_CURLY_BRACES ; $ token [ 'name' ] = 'T_DOLLAR_CURLY_BRACES' ; } $ isArray = ( ! $ token [ 'id' ] && $ token [ 'content' ] === '(' && $ previousTokenId !== null && $ tokens [ $ previousTokenId ] [ 'id' ] === T_ARRAY ) ; if ( $ isArray ) { $ token [ 'id' ] = T_ARRAY_OPEN ; $ token [ 'name' ] = 'T_ARRAY_OPEN' ; } $ isShortArray = ( ! $ token [ 'id' ] && $ token [ 'content' ] === '[' && $ previousTokenId !== null && ( $ tokens [ $ previousTokenId ] [ 'id' ] !== T_VARIABLE && $ tokens [ $ previousTokenId ] [ 'id' ] !== T_ENCAPSED_AND_WHITESPACE ) ) ; if ( $ isShortArray ) { $ token [ 'id' ] = T_SHORT_ARRAY_OPEN ; $ token [ 'name' ] = 'T_SHORT_ARRAY_OPEN' ; } if ( $ token [ 'content' ] === '(' && ! $ token [ 'id' ] ) { $ token [ 'id' ] = T_START_BRACKET ; $ token [ 'name' ] = 'T_START_BRACKET' ; } if ( $ token [ 'id' ] !== T_WHITESPACE ) { $ previousTokenId = $ tokenId ; } if ( $ token [ 'id' ] === T_IF ) { $ i = $ cpt ; $ spaces = '' ; while ( $ i -- > 0 && $ results [ $ i ] [ 'id' ] === T_WHITESPACE ) { $ spaces = $ results [ $ i ] [ 'content' ] . $ spaces ; } if ( $ i >= 0 && $ results [ $ i ] [ 'id' ] === T_ELSE ) { $ token [ 'id' ] = T_ELSEIF ; $ token [ 'name' ] = 'T_ELSEIF' ; $ token [ 'content' ] = $ results [ $ i ] [ 'content' ] . $ spaces . $ token [ 'content' ] ; $ cpt = $ i ; } } $ results [ $ cpt ++ ] = $ token ; } return $ results ; }
Adding extra tokens for quality rules
56,152
protected function refresh_info ( ) { $ this -> pid = ( int ) getmypid ( ) ; $ this -> gid = ( int ) getmygid ( ) ; $ this -> inode = ( int ) getmyinode ( ) ; $ this -> uid = ( int ) getmyuid ( ) ; $ this -> user = ( string ) get_current_user ( ) ; $ this -> uname = posix_uname ( ) ; return true ; }
refresh the basic info
56,153
protected function cpu_info ( ) { $ this -> cpu_info = array ( ) ; if ( ! stristr ( PHP_OS , 'win' ) ) { exec ( "cat /proc/cpuinfo" , $ output ) ; foreach ( $ output as $ line ) { $ parts = explode ( ':' , $ line ) ; if ( empty ( $ parts [ 0 ] ) ) continue ; $ this -> cpu_info [ trim ( $ parts [ 0 ] ) ] = ( ! empty ( $ parts [ 1 ] ) ) ? trim ( $ parts [ 1 ] ) : null ; } } return true ; }
Collect Cpu info
56,154
protected function system_memory_info ( ) { $ this -> system_memory_kb = array ( ) ; exec ( "cat /proc/meminfo" , $ output ) ; foreach ( $ output as $ line ) { $ parts = explode ( ':' , $ line ) ; if ( empty ( $ parts [ 0 ] ) ) continue ; $ this -> system_memory_kb [ trim ( $ parts [ 0 ] ) ] = ( int ) ( ! empty ( $ parts [ 1 ] ) ? trim ( str_replace ( 'kB' , '' , $ parts [ 1 ] ) ) : null ) ; } return true ; }
memory info for a linux system
56,155
protected function process_memory_info ( ) { $ this -> current_mem_use = ( int ) memory_get_usage ( ) ; $ this -> current_mem_peak = ( int ) memory_get_peak_usage ( ) ; $ this -> current_mem_peak_mb = ( float ) $ this -> current_mem_peak / 1024 / 1024 ; $ this -> current_mem_use_mb = ( float ) $ this -> current_mem_use / 1024 / 1024 ; return true ; }
get memory infos
56,156
public function actionGenerate ( ) { Question :: confirm ( null , 1 ) ; $ count = \ App :: $ domain -> rbac -> const -> generateAll ( ) ; if ( $ count ) { Output :: block ( "Generated {$count} constants" ) ; } else { Output :: block ( "All rules exists!" ) ; } }
Generating enums for RBAC roles permissions and rules
56,157
public function apply ( $ testable , array $ config = array ( ) ) { $ tokens = $ testable -> tokens ( ) ; $ filtered = $ testable -> findAll ( array ( T_FUNCTION ) ) ; foreach ( $ filtered as $ key ) { $ token = $ tokens [ $ key ] ; $ label = Parser :: label ( $ key , $ tokens ) ; $ modifiers = Parser :: modifiers ( $ key , $ tokens ) ; $ isClosure = Parser :: closure ( $ key , $ tokens ) ; if ( in_array ( $ label , $ this -> _magicMethods ) ) { continue ; } if ( $ testable -> findNext ( array ( T_PROTECTED ) , $ modifiers ) !== false ) { $ label = preg_replace ( '/^_/' , '' , $ label ) ; } if ( ! $ isClosure && $ label !== Inflector :: camelize ( $ label , false ) ) { $ this -> addViolation ( array ( 'message' => 'Function "' . $ label . '" is not in camelBack style' , 'line' => $ tokens [ $ tokens [ $ key ] [ 'parent' ] ] [ 'line' ] , ) ) ; } } }
Will iterate the tokens looking for functions validating they have the correct camelBack naming style .
56,158
public static function render ( $ options = null ) { $ pagination = new static ( $ options ) ; if ( ! $ links = $ pagination -> getLinks ( ) ) { return '' ; } if ( ! $ pagination -> view ) { return $ pagination -> autoRender ( $ links ) ; } return $ pagination -> renderView ( $ links ) ; }
Return pagination HTML
56,159
private function renderView ( $ links ) { $ defaults = $ this -> defaults ; return View :: make ( $ this -> view , compact ( 'links' , 'defaults' ) ) -> render ( ) ; }
Render pagination based on a view
56,160
private function autoRender ( $ links ) { $ list = "<div class=\"{$this->defaults['container_class']}\">\n\t" ; $ list .= "<ul class=\"{$this->defaults['ul_class']}\">\n\t" ; foreach ( $ links as $ l ) { $ active = ( $ l [ 'active' ] ) ? 'class="active"' : '' ; $ list .= "<li {$active}>{$l['link']}</li>" ; } $ list .= "</ul>\n" ; $ list .= "</div>\n" ; return $ list ; }
Render de HTML
56,161
protected function getLinks ( $ options = array ( ) ) { global $ wp_query , $ wp_rewrite ; $ current = $ wp_query -> query_vars [ 'paged' ] > 1 ? $ wp_query -> query_vars [ 'paged' ] : 1 ; $ pagination = array ( 'base' => @ add_query_arg ( 'paged' , '%#%' ) , 'showall' => false , 'end_size' => $ this -> endSize , 'mid_size' => $ this -> midSize , 'total' => $ wp_query -> max_num_pages , 'current' => $ current , 'type' => 'array' , 'prev_text' => $ this -> defaults [ 'prev_text' ] , 'next_text' => $ this -> defaults [ 'next_text' ] , ) ; if ( $ wp_rewrite -> using_permalinks ( ) ) { $ pagination [ 'base' ] = user_trailingslashit ( trailingslashit ( remove_query_arg ( 's' , get_pagenum_link ( 1 ) ) ) . 'page/%#%/' , 'paged' ) ; } if ( ! empty ( $ wp_query -> query_vars [ 's' ] ) ) { $ pagination [ 'add_args' ] = array ( 's' => urlencode ( get_query_var ( 's' ) ) ) ; } $ aLinks = paginate_links ( $ pagination ) ; if ( ! $ aLinks ) { return null ; } return $ this -> parseWpLinks ( $ aLinks ) ; }
WordPress regular functions to process pagination
56,162
private function parseWpLinks ( $ aLinks ) { $ links = [ ] ; foreach ( $ aLinks as $ link ) { $ links [ ] = [ 'active' => $ this -> checkActive ( $ link ) , 'link' => $ link ] ; } return $ links ; }
parse array of links and set which is active .
56,163
public function connectionSettingsAreValid ( ) { if ( ! $ this -> getDbAdapter ( ) ) { return false ; } $ connectionSettings = $ this -> getDbAdapter ( ) -> getConnectionSettings ( ) ; if ( ! $ connectionSettings ) { return false ; } return $ connectionSettings -> validateProperties ( ) ; }
a database connection needs certain parameters to work
56,164
public function splice ( $ offset , $ length = 0 , $ replacement = [ ] ) { return new static ( array_splice ( $ this -> items , $ offset , $ length , $ replacement ) ) ; }
Splice portion of the underlying collection array .
56,165
public function equalsProperties ( $ host , $ user , $ password , $ name , $ key = "" , $ cert = "" , $ ca = "" ) { return ( $ this -> host == $ host && $ this -> user == $ user && $ this -> password == $ password && $ this -> name == $ name && $ this -> key == $ key && $ this -> cert == $ cert && $ this -> ca == $ ca ) ; }
Check if the passed properties are equal to instance properties
56,166
public function equals ( MysqlConnection $ connection ) { return ( $ this -> host == $ connection -> host && $ this -> user == $ connection -> user && $ this -> password == $ connection -> password && $ this -> name == $ connection -> name && $ this -> key == $ connection -> key && $ this -> cert == $ connection -> cert && $ this -> ca == $ connection -> ca ) ; }
Check if the passed object is equal to this this check the properties not the mysqli connection
56,167
protected function runPhp ( \ Everon \ View \ Interfaces \ TemplateCompilerContext $ Context , \ Everon \ Interfaces \ FileSystem $ FileSystem ) { $ handleError = function ( $ errno , $ errstr , $ errfile , $ errline , array $ errcontext ) { if ( 0 === error_reporting ( ) ) { return false ; } throw new \ Everon \ Exception \ TemplateEvaluationError ( $ errstr , 0 , $ errno , $ errfile , $ errline ) ; } ; $ old_error_handler = set_error_handler ( $ handleError ) ; $ TmpPhpFile = $ FileSystem -> createTmpFile ( ) ; try { $ TmpPhpFile -> write ( $ Context -> getPhp ( ) ) ; $ php_file = $ TmpPhpFile -> getFilename ( ) ; ob_start ( ) ; $ callback = function ( ) use ( $ php_file , $ Context ) { extract ( [ 'Tpl' => new PopoProps ( $ Context -> getData ( ) ) , ] ) ; include $ php_file ; } ; $ callback = $ callback -> bindTo ( $ Context -> getScope ( ) ? : $ this ) ; $ callback ( ) ; $ Context -> setCompiled ( ob_get_contents ( ) ) ; } finally { ob_end_clean ( ) ; $ TmpPhpFile -> close ( ) ; restore_error_handler ( $ old_error_handler ) ; } }
Must implement Logger
56,168
public function getPagedResults ( $ limit = 50 , $ page = 0 ) : Paginator { $ dql = sprintf ( self :: DQL_GET_PAGED , TargetTemplate :: class ) ; return $ this -> getPaginator ( $ dql , $ limit , $ page ) ; }
Get all templates paged .
56,169
public function getGroupedTemplates ( ? Application $ application = null ) : array { $ environments = $ this -> getEntityManager ( ) -> getRepository ( Environment :: class ) -> findAll ( ) ; if ( $ application ) { $ findBy = [ 'application' => $ application ] ; } else { $ findBy = [ ] ; } $ templates = $ this -> findBy ( $ findBy ) ; usort ( $ environments , $ this -> environmentSorter ( ) ) ; usort ( $ templates , $ this -> templateSorter ( ) ) ; $ sorted = [ ] ; foreach ( $ environments as $ environment ) { $ sorted [ $ environment -> id ( ) ] = [ 'environment' => $ environment , 'templates' => [ ] , ] ; } foreach ( $ templates as $ template ) { $ id = $ template -> environment ( ) -> id ( ) ; $ sorted [ $ id ] [ 'templates' ] [ ] = $ template ; } return array_filter ( $ sorted , function ( $ e ) { return count ( $ e [ 'templates' ] ) !== 0 ; } ) ; }
Get all templates sorted into environments .
56,170
protected function checkToken ( $ token ) { try { $ response = $ this -> http -> get ( $ this -> checkTokenURL ( ) , [ 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest' , 'Authorization' => 'Bearer ' . $ token ] ] ) ; $ content = json_decode ( $ response -> getBody ( ) -> getContents ( ) ) ; if ( isset ( $ content -> message ) ) { if ( $ content -> message === 'Token is valid' ) { return true ; } } } catch ( \ Exception $ e ) { return false ; } return false ; }
Check token .
56,171
public function lock ( ) { if ( $ this -> isRunning ( ) ) return false ; $ pidFile = $ this -> directory . $ this -> filename ; if ( ! is_writable ( $ this -> directory ) ) { throw new \ Exception ( 'Can not write to folder: ' . $ this -> directory ) ; } if ( file_exists ( $ pidFile ) && ! is_writable ( $ pidFile ) ) { throw new \ Exception ( 'Can not write to file: ' . $ pidFile ) ; } $ file = fopen ( $ pidFile , 'w' ) ; if ( $ file === false ) { return false ; } fputs ( $ file , getmypid ( ) ) ; fclose ( $ file ) ; return true ; }
Writes the process id to a pid file
56,172
public function isRunning ( ) { $ this -> checkDirExists ( ) ; $ pidFile = $ this -> directory . $ this -> filename ; if ( ! file_exists ( $ pidFile ) ) { return false ; } $ pid = file_get_contents ( $ pidFile ) ; if ( empty ( $ pid ) ) { return false ; } if ( ! is_dir ( '/proc/' ) ) { exec ( 'ps -Ac -o pid | awk \'{print $1}\' | grep \'^' . $ pid . '$\'' , $ output , $ return ) ; if ( $ return == 0 ) { return true ; } } if ( ! is_dir ( '/proc/' . $ pid ) ) { return false ; } return true ; }
Checks if a process is still running
56,173
public function unlock ( ) { $ this -> checkDirExists ( ) ; $ pidFile = $ this -> directory . $ this -> filename ; if ( ! file_exists ( $ pidFile ) ) { return false ; } if ( ! is_writable ( $ pidFile ) ) { throw new \ Exception ( 'Can not write to file: ' . $ pidFile ) ; } return unlink ( $ pidFile ) ; }
Removes a pid file from the pid directory kind of optional as if your process has already stopped we should already be able to detect it . It s nice to clean up though .
56,174
public function resetPassword ( $ token , $ password ) { $ this -> cleanResetTokens = true ; $ token = $ this -> getEntityManager ( ) -> find ( PasswordResetToken :: class , $ token ) ; if ( ! $ token ) { throw new TokenNotFoundException ; } $ user = $ token -> getUser ( ) ; $ user -> setPassword ( $ password ) ; $ em = $ this -> getEntityManager ( ) ; $ em -> remove ( $ token ) ; $ em -> flush ( ) ; return $ user ; }
Set password and return updated User Entity
56,175
function validate ( $ options = [ ] ) { $ groups = @ $ options [ 'groups' ] ? : [ ] ; $ this -> errors = static :: validator ( ) -> validate ( $ this , $ groups ) ; return $ this -> errors -> count ( ) === 0 ; }
Validates the class .
56,176
protected function _getServerHttpUrlFromCommand ( $ command ) { $ base = null ; $ cmMethod = strtolower ( ( string ) $ command ) ; switch ( $ cmMethod ) { case 'getauthurl' : $ base = 'auth' ; break ; case 'token' : $ base = 'auth/token' ; break ; case 'register' : $ base = 'api/v1/members' ; break ; case 'accountinfo' : $ params = iterator_to_array ( $ command ) ; if ( isset ( $ params [ 'username' ] ) ) $ postfix = 'u/' . $ params [ 'username' ] ; else $ postfix = '-' . current ( $ params ) ; $ base = 'api/v1/members/profile/' . $ postfix ; break ; case 'listaccountsinfo' : $ base = 'api/v1/members/profiles' ; break ; case 'recover::validate' : $ params = iterator_to_array ( $ command ) ; $ base = 'api/v1/me/identifiers/change/confirm/' . $ params [ 'validation_code' ] ; break ; case 'recover::resendcode' : $ params = iterator_to_array ( $ command ) ; $ base = 'recover/validate/resend/' . $ params [ 'validation_code' ] . '/' . $ params [ 'identifier_type' ] ; break ; case 'members::exists' : $ base = 'api/v1/members/exists' ; break ; case 'members::whois' : $ base = 'api/v1/members/whois' ; break ; case 'members::validateuseridentifier' : $ base = 'api/v1/members/' . $ command -> getUserId ( ) . '/validate/' . $ command -> getIdentifier ( ) ; break ; case 'me::accountinfo' : $ postfix = '' ; if ( $ command -> getIncludeGrants ( ) ) $ postfix = '?grants' ; $ base = 'api/v1/me/profile' . $ postfix ; break ; case 'me::changepassword' : $ base = 'api/v1/me/grants/password' ; break ; case 'me::changeidentity' : $ base = 'api/v1/me/identifiers/change' ; break ; } $ serverUrl = rtrim ( $ this -> serverBaseUrl , '/' ) ; ( ! $ base ) ? : $ serverUrl .= '/' . trim ( $ base , '/' ) ; return $ serverUrl ; }
Determine Server Http Url Using Http or Https?
56,177
protected function getYoutubeParameters ( ReadBlockInterface $ block ) { $ urlParams = array ( ) ; foreach ( array ( 'youtubeAutoplay' , 'youtubeShowinfo' , 'youtubeFs' , 'youtubeRel' , 'youtubeDisablekb' , 'youtubeLoop' ) as $ key ) { if ( $ block -> getAttribute ( $ key ) === true ) { $ urlParams [ strtolower ( substr ( $ key , 7 ) ) ] = 1 ; } } if ( $ block -> getAttribute ( 'youtubeControls' ) === false ) { $ urlParams [ 'controls' ] = 0 ; } if ( $ block -> getAttribute ( 'youtubeTheme' ) === true ) { $ urlParams [ 'theme' ] = 'light' ; } if ( $ block -> getAttribute ( 'youtubeColor' ) === true ) { $ urlParams [ 'color' ] = 'white' ; } if ( $ block -> getAttribute ( 'youtubeHl' ) !== '' ) { $ urlParams [ 'hl' ] = $ block -> getAttribute ( 'youtubeHl' ) ; } $ url = "//www.youtube.com/embed/" . $ block -> getAttribute ( 'youtubeVideoId' ) . "?" . http_build_query ( $ urlParams , '' , '&amp;' ) ; return array ( 'url' => $ url , 'class' => $ block -> getStyle ( ) , 'id' => $ block -> getId ( ) , 'width' => $ block -> getAttribute ( 'youtubeWidth' ) , 'height' => $ block -> getAttribute ( 'youtubeHeight' ) ) ; }
Return view parameters for a youtube video
56,178
protected function getDailymotionParameters ( ReadBlockInterface $ block ) { $ urlParams = array ( ) ; foreach ( array ( 'dailymotionAutoplay' , 'dailymotionChromeless' ) as $ key ) { if ( $ block -> getAttribute ( $ key ) === true ) { $ urlParams [ strtolower ( substr ( $ key , 11 ) ) ] = 1 ; } } foreach ( array ( 'dailymotionLogo' , 'dailymotionInfo' , 'dailymotionRelated' ) as $ key ) { if ( $ block -> getAttribute ( $ key ) === false ) { $ urlParams [ strtolower ( substr ( $ key , 11 ) ) ] = 0 ; } } foreach ( array ( 'dailymotionBackground' , 'dailymotionForeground' , 'dailymotionHighlight' , 'dailymotionQuality' ) as $ key ) { if ( $ block -> getAttribute ( $ key ) !== '' ) { $ urlParams [ strtolower ( substr ( $ key , 11 ) ) ] = $ block -> getAttribute ( $ key ) ; } } $ url = "//www.dailymotion.com/embed/video/" . $ block -> getAttribute ( 'dailymotionVideoId' ) . "?" . http_build_query ( $ urlParams ) ; return array ( 'url' => $ url , 'width' => $ block -> getAttribute ( 'dailymotionWidth' ) , 'height' => $ block -> getAttribute ( 'dailymotionHeight' ) ) ; }
Return view parameters for a dailymotion video
56,179
public function resolve ( ) { $ this -> zone -> setComponents ( $ this -> components -> buildRanking ( ) ) ; $ this -> assertEntityIsValid ( $ this -> zone , array ( 'Zone' , 'edition' ) ) ; $ this -> fireEvent ( ZoneEvents :: ZONE_EDITED , new ZoneEvent ( $ this -> zone , $ this ) ) ; }
Edition trigger method .
56,180
protected function getFiles ( ) { $ dir_iterator = new RecursiveDirectoryIterator ( $ this -> entryPath ) ; $ iterator = new RecursiveIteratorIterator ( $ dir_iterator , RecursiveIteratorIterator :: CHILD_FIRST ) ; $ files = new RegexIterator ( $ iterator , '/^.+\.scss$/i' ) ; return $ files ; }
Returns a list of all . scss files in the entry directory
56,181
protected function checkFiles ( $ force = false ) { $ files = $ this -> getFiles ( ) ; foreach ( $ files as $ file ) { $ this -> checkFile ( $ file , $ force ) ; } }
Checks all . scss files for modifications
56,182
protected function checkFile ( SplFileInfo $ file , $ force ) { $ scssPath = $ file -> getPathname ( ) ; $ scssMod = $ file -> getMTime ( ) ; $ scssName = preg_replace ( '/^.+(\/|\\\\)([^\/\\\\]+)$/' , '\\2' , $ scssPath ) ; if ( substr ( $ scssName , 0 , 1 ) === '_' ) { $ this -> sysMod = max ( $ this -> sysMod , $ scssMod ) ; return ; } $ cssPath = preg_replace ( '/(\.|\/|\\\\)scss($|\/|\\\\)/' , '\\1css\\2' , $ scssPath ) ; $ cssMod = is_file ( $ cssPath ) ? filemtime ( $ cssPath ) : 0 ; $ this -> oldestMod = min ( $ this -> oldestMod , $ cssMod ) ; $ isModified = $ scssMod - $ cssMod > 0 ? true : false ; if ( $ isModified || $ force ) { $ this -> generateCss ( $ scssPath , $ cssPath ) ; } if ( ! $ force && $ this -> sysMod > $ this -> oldestMod ) { $ this -> checkFiles ( true ) ; $ this -> oldestMod = $ this -> sysMod ; } }
Checks a given file for modifications and triggers CSS generation
56,183
protected function generateCss ( $ scssPath , $ cssPath ) { $ cssDirName = preg_replace ( '/^(.+)(\/|\\\\)[^\/\\\\]+$/' , '\\1' , $ cssPath ) ; if ( ! is_dir ( $ cssDirName ) ) { mkdir ( $ cssDirName , 0777 ) ; } $ response = trim ( shell_exec ( "$this->sassBinary $scssPath $cssPath --style $this->style $this->flags 2>&1" ) ) ; if ( strpos ( $ response , 'error' ) !== false ) { if ( $ response === $ this -> currentError ) { echo '.' ; } else { echo substr ( $ scssPath , strlen ( $ this -> entryPath ) ) . "\n" . $ response . "\n" ; } $ this -> currentError = $ response ; } else { if ( $ this -> currentError ) { echo "fixed\n" ; $ this -> currentError = null ; } echo substr ( $ scssPath , strlen ( $ this -> entryPath ) ) . "\n" ; } }
Converts a . scss file to the corresponding . css version
56,184
public function add ( $ callable ) { $ callable = $ this -> resolveCallable ( $ callable ) ; if ( $ callable instanceof Closure ) { $ callable = $ callable -> bindTo ( $ this -> container ) ; } $ this -> middleware [ ] = $ callable ; return $ this ; }
Add middleware .
56,185
public function finalize ( ) { foreach ( $ this -> getGroups ( ) as $ group ) { foreach ( $ group -> getMiddleware ( ) as $ middleware ) { array_unshift ( $ this -> middleware , $ middleware ) ; } } foreach ( $ this -> getMiddleware ( ) as $ middleware ) { $ this -> addMiddleware ( $ middleware ) ; } }
Finalize the route in preparation for dispatching .
56,186
public function setOutputBuffering ( $ mode ) { if ( ! in_array ( $ mode , [ false , 'prepend' , 'append' ] , true ) ) { throw new InvalidArgumentException ( 'Unknown output buffering mode' ) ; } $ this -> outputBuffering = $ mode ; }
Set output buffering mode .
56,187
public function prepare ( ServerRequestInterface $ request , array $ arguments ) { foreach ( $ arguments as $ k => $ v ) { $ this -> setArgument ( $ k , $ v ) ; } }
Prepare the route for use .
56,188
public function registerZoneType ( array $ zoneTypeData ) { $ zoneType = $ this -> normalizer -> denormalize ( array ( 'id' => $ zoneTypeData [ 'id' ] , 'name' => $ zoneTypeData [ 'name' ] , 'order' => $ zoneTypeData [ 'order' ] , ) , $ this -> entityCollection -> getEntityClass ( ) ) ; foreach ( $ zoneTypeData [ 'components' ] as $ componentTypeId ) { $ zoneType -> getAllowedComponentTypes ( ) -> set ( $ componentTypeId , $ this -> componentTypeLoader -> retrieve ( $ componentTypeId ) ) ; } $ this -> entityCollection -> set ( $ zoneType -> getId ( ) , $ zoneType ) ; }
Register a new ZoneType into loader .
56,189
static function of ( $ resource ) { if ( ! is_resource ( $ resource ) && get_resource_type ( $ resource ) !== 'stream-context' ) throw new \ InvalidArgumentException ( sprintf ( 'Invalid Context Resource Passed, given: "%s".' , \ Poirot \ Std \ flatten ( $ resource ) ) ) ; $ options = stream_context_get_params ( $ resource ) ; $ context = new ContextStreamSocket ( $ options ) ; return $ context ; }
Factory ContextOption From context resource
56,190
protected static function fetchUrl ( $ url ) { $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , [ 'User-Agent: Mozilla/5.0 (OSX) Gecko/20030208 Netscape/7.02' ] ) ; curl_setopt ( $ ch , CURLOPT_FOLLOWLOCATION , true ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ ch , CURLOPT_HEADER , 1 ) ; $ response = curl_exec ( $ ch ) ; $ httpcode = curl_getinfo ( $ ch , CURLINFO_HTTP_CODE ) ; $ header_size = curl_getinfo ( $ ch , CURLINFO_HEADER_SIZE ) ; $ headers = substr ( $ response , 0 , $ header_size ) ; $ body = substr ( $ response , $ header_size ) ; return [ 'code' => $ httpcode , 'headers' => $ headers , 'body' => $ body ] ; }
XXX put in class Http and use Guzzle
56,191
protected static function runCommand ( $ cmd , $ stderr_file = false , $ extra_file = false ) { $ output = [ ] ; $ exitcode = - 1 ; exec ( $ cmd , $ output , $ exitcode ) ; return [ 'code' => $ exitcode , 'stdout' => implode ( "\n" , $ output ) , 'stderr' => $ stderr_file ? file_get_contents ( stderr_file ) : null , 'extra_file' => $ return_file ? file_get_contents ( $ return_file ) : null ] ; }
Runs a command and returns the exit code stdout stderr and possible any extra file .
56,192
public function createProjectSkel ( $ projectName ) { $ rootDir = $ this -> config -> get ( 'phpalchemy.root_dir' ) ; $ defAppIniFile = $ rootDir . '/config/defaults.application.ini' ; if ( ! self :: validateProjectName ( $ projectName ) ) { throw new \ Exception ( "Error: Invalid project name!\nProject name can be contains only alphanumeric characteres." ) ; } $ newProjectDir = getcwd ( ) . '/' . $ projectName ; if ( ! file_exists ( $ defAppIniFile ) ) { throw new \ Exception ( "FATAL ERROR: File: 'defaults.application.ini' is missing!" ) ; } $ this -> projectDir = $ newProjectDir ; $ this -> config -> set ( 'app.root_dir' , $ newProjectDir ) ; self :: createDir ( $ newProjectDir ) ; $ this -> config -> load ( $ this -> homeDir . DS . 'config' . DS . 'defaults.application.ini' ) ; $ this -> config -> load ( $ this -> projectDir . DS . 'application.ini' ) ; $ appInitConf = $ this -> config -> all ( ) ; foreach ( $ appInitConf as $ key => $ targetDir ) { if ( preg_match ( '/^app\.[\w]+_dir/' , $ key , $ m ) && $ key !== 'app.root_dir' ) { self :: createDir ( $ targetDir ) ; } } $ data = array ( ) ; $ data [ 'appName' ] = $ projectName ; $ data [ 'namespace' ] = self :: camelize ( $ projectName ) ; $ data [ 'framework_dir' ] = $ this -> homeDir ; $ projectFiles = glob ( $ rootDir . '/templates/project/*' ) ; foreach ( $ projectFiles as $ file ) { $ targetFile = $ this -> projectDir . '/' . str_replace ( '|' , DIRECTORY_SEPARATOR , basename ( $ file ) ) ; self :: createDir ( pathinfo ( $ targetFile , PATHINFO_DIRNAME ) ) ; if ( substr ( $ file , - 4 ) === '.tpl' ) { $ contents = file_get_contents ( $ file ) ; $ targetFile = str_replace ( '.tpl' , '' , $ targetFile ) ; foreach ( $ data as $ key => $ value ) { $ contents = str_replace ( '{' . $ key . '}' , $ value , $ contents ) ; } file_put_contents ( $ targetFile , $ contents ) ; } else { copy ( $ file , $ targetFile ) ; } } return $ projectName ; }
Creates a project directory skeleton
56,193
public static function forge ( $ host = null , $ user = null , $ password = null , $ port = 21 , $ timeout = 90 ) { static :: $ _host = $ host ; static :: $ _user = $ user ; static :: $ _pwd = $ password ; static :: $ _port = ( int ) $ port ; static :: $ _timeout = ( int ) $ timeout ; if ( ! static :: $ instance ) { static :: $ instance = new self ( ) ; } return static :: $ instance ; }
Initialize connection params
56,194
public static function getEnv ( $ variable = null ) { $ cmd = preg_match ( "/WIN/Ai" , PHP_OS ) ? 'set' : 'printenv' ; $ output = self :: run ( $ cmd ) -> output ; $ env = [ ] ; foreach ( $ output as $ line ) { list ( $ key , $ value ) = explode ( "=" , $ line , 2 ) ; if ( $ variable && strtolower ( $ key ) === strtolower ( $ variable ) ) { return $ value ; } $ env [ $ key ] = $ value ; } return $ env ; }
Get all environment variables or a value of specified variable .
56,195
public function run ( $ groupName , array $ exludedProjects = [ ] , $ historyFile = null ) { if ( $ historyFile ) { $ this -> historyShellManager -> getHistory ( ) -> loadHistory ( $ historyFile ) ; } $ this -> historyShellManager -> setPrompt ( $ this -> getPrompt ( $ groupName ) ) ; $ this -> application -> setAutoExit ( false ) ; $ this -> output -> writeln ( $ this -> getHeader ( $ groupName , $ exludedProjects ) ) ; while ( true ) { if ( $ this -> promptCounter > 0 && ! empty ( $ cmd ) ) { $ this -> output -> write ( "\n" ) ; } $ cmd = $ this -> readline ( $ groupName ) ; $ this -> promptCounter ++ ; if ( false === $ cmd ) { $ this -> output -> writeln ( "\n" ) ; break ; } if ( ! empty ( $ cmd ) && $ cmd != 'exit' ) { $ this -> historyShellManager -> getHistory ( ) -> addCommand ( $ cmd ) ; } $ event = new BeforeShellCommandExecutionEvent ( $ cmd ) ; $ this -> dispatcher -> dispatch ( ShellEvents :: BEFORE_SHELL_COMMAND_EXECUTION_EVENT , $ event ) ; if ( $ event -> getCommand ( ) == 'exit' ) { $ this -> application -> setAutoExit ( true ) ; return ; } if ( $ exludedProjects != [ ] ) { foreach ( $ exludedProjects as & $ exludedProject ) { $ exludedProject = '-x ' . $ exludedProject ; } } $ command = new StringInput ( sprintf ( 'execute %s "%s"' . ( $ exludedProjects != [ ] ? join ( ' ' , $ exludedProjects ) : '' ) , $ groupName , $ event -> getCommand ( ) ) ) ; $ ret = $ this -> application -> run ( $ command , $ this -> output ) ; if ( 0 !== $ ret ) { $ this -> output -> writeln ( sprintf ( '<error>The command terminated with an error status (%s)</error>' , $ ret ) ) ; } } }
Starts a new shell process .
56,196
private function getHeader ( $ groupName , array $ excludedProjects = [ ] ) { if ( $ excludedProjects != [ ] ) { $ ignoredProjects = '' ; foreach ( $ excludedProjects as $ project ) { $ ignoredProjects .= '<comment>' . $ project . '</comment>, ' ; } $ ignoredProjects = ' except for the projects ' . substr ( $ ignoredProjects , 0 , strlen ( $ ignoredProjects ) - 2 ) . '.' ; } else { $ ignoredProjects = '.' ; } return <<<EOFWelcome to the <info>Para</info> shell (<comment>{$this->application->getVersion()}</comment>).All commands you type in will be executed for each project configured in the group <comment>{$groupName}</comment>{$ignoredProjects}THE SHORTCUT <comment>(ctrl + C)</comment> HAS BEEN <comment>DISABLED</comment> !To exit the shell, type <comment>exit</comment>.EOF ; }
Returns the shell header .
56,197
public function compile ( ) { extract ( $ this -> vars ) ; ob_start ( ) ; include $ this -> filename ; $ __strCompiled__ = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ __strCompiled__ ; }
Compiles template .
56,198
public function actionDeleteUnused ( ) { $ articeThumb = [ ] ; $ rootPath = yii :: getAlias ( '@frontend/web' ) ; foreach ( Article :: find ( ) -> where ( [ '<>' , 'thumb' , '' ] ) -> each ( 100 ) as $ artice ) { $ articeThumb [ ] = str_replace ( yii :: $ app -> params [ 'site' ] [ 'url' ] , $ rootPath , $ artice -> thumb ) ; } $ articleContent = [ ] ; foreach ( ArticleContent :: find ( ) -> where ( [ '<>' , 'content' , '' ] ) -> each ( 100 ) as $ content ) { $ content -> content = str_replace ( yii :: $ app -> params [ 'site' ] [ 'url' ] , yii :: $ app -> params [ 'site' ] [ 'sign' ] , $ content -> content ) ; preg_match_all ( '/<img.*src="(' . yii :: $ app -> params [ 'site' ] [ 'sign' ] . '.*)"/isU' , $ content -> content , $ matches ) ; if ( ! empty ( $ matches [ 1 ] ) ) { foreach ( $ matches [ 1 ] as $ pic ) { $ articleContent [ ] = str_replace ( yii :: $ app -> params [ 'site' ] [ 'sign' ] , $ rootPath , $ pic ) ; } } } $ friendlink = [ ] ; foreach ( FriendlyLink :: find ( ) -> where ( [ '<>' , 'image' , '' ] ) -> each ( 100 ) as $ link ) { $ friendlink [ ] = $ rootPath . $ link -> image ; } $ this -> unusedFiles = array_merge ( $ articeThumb , $ articleContent , $ friendlink ) ; $ this -> _deleteFileRecursive ( yii :: getAlias ( '@uploads' ) ) ; }
Delete unused files and empty directory .
56,199
protected function calculateMode ( $ class ) { foreach ( $ this -> modeArray as $ constant ) { $ this -> mode = $ this -> mode | constant ( $ class . '::' . $ constant ) ; } return $ this ; }
Calculate the mode score .