idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
2,400
public function post ( $ resource , $ content ) { $ url = $ this -> baseUrl . $ resource ; $ headers = array ( 'Content-Type' => 'application/json' , 'Authorization' => $ this -> auth -> getCredential ( ) ) ; try { $ response = $ this -> browser -> post ( $ url , $ headers , json_encode ( $ content ) ) ; } catch ( \ Buzz \ Exception \ ClientException $ e ) { throw new RequestException ( $ e -> getMessage ( ) ) ; } if ( $ this -> browser -> getLastResponse ( ) -> getStatusCode ( ) > 299 ) { throw new RequestException ( json_decode ( $ this -> browser -> getLastResponse ( ) -> getContent ( ) , true ) ) ; } return json_decode ( $ response -> getContent ( ) , true ) ; }
Common post request for all API calls
2,401
protected function filter ( $ value ) { if ( ! is_scalar ( $ value ) ) { return $ value ; } $ value = ( string ) $ value ; if ( ! $ this -> hasPcreUnicodeSupport ( ) ) { return preg_replace ( '/[^0-9]/' , '' , $ value ) ; } if ( extension_loaded ( 'mbstring' ) ) { return preg_replace ( '/[^[:digit:]]/' , '' , $ value ) ; } return preg_replace ( '/[\p{^N}]/' , '' , $ value ) ; }
Lifted entirely from the Zend framework so that we don t have to include the Zend \ Filter package and all its dependencies .
2,402
public function getNewToken ( ) { $ post = array ( 'auth' => array ( 'username' => $ this -> username , 'password' => $ this -> password , ) , ) ; return $ this -> http -> call ( HttpMethod :: POST , $ this -> host . '/auth' , $ post ) -> token ; }
Get a new auth token from server
2,403
public function setSaveOptions ( $ file_name = null , $ directory = null , $ suffix = null ) { if ( $ directory ) { $ this -> _save_dir = rtrim ( $ directory , DIRECTORY_SEPARATOR ) ; } else if ( ! $ this -> _save_dir ) { $ this -> _save_dir = $ this -> _image_info [ 'dirname' ] ; } if ( ! is_dir ( $ directory ) ) { mkdir ( $ directory , 0755 , true ) ; } else if ( ! is_writable ( $ directory ) ) { chmod ( $ directory , 0755 ) ; } if ( $ file_name ) { $ this -> _save_name = basename ( $ file_name , '.' . pathinfo ( $ file_name , PATHINFO_EXTENSION ) ) . $ suffix . '.' . $ this -> _output_format ; } else if ( ! $ this -> _save_name ) { $ this -> _save_name = $ this -> _image_info [ 'filename' ] . $ suffix . '.' . $ this -> _output_format ; } $ this -> _save_path = $ this -> _save_dir . DIRECTORY_SEPARATOR . $ this -> _save_name ; return $ this ; }
Set Saving Options
2,404
public function setOutputFormat ( $ format = null , $ quality = null , $ filters = null ) { if ( $ format ) { $ format = strtolower ( $ format ) ; if ( in_array ( $ format , static :: $ _allowed_formates ) ) { $ this -> _output_format = $ format ; if ( $ this -> _save_path ) { $ this -> _save_name = preg_replace ( '/(?<=\.)(?:png|jpeg|jpg|gif)$/i' , $ this -> _output_format , $ this -> _save_name ) ; $ this -> _save_path = $ this -> _save_dir . DIRECTORY_SEPARATOR . $ this -> _save_name ; } } } $ this -> _output_options = [ ] ; if ( is_numeric ( $ quality ) ) { if ( $ this -> _output_format == 'jpg' || $ this -> _output_format == 'jpeg' ) { $ quality = round ( $ quality * 100 / 100 ) ; } else if ( $ this -> _output_format == 'png' ) { $ quality = round ( $ quality * 9 / 100 ) ; } $ this -> _output_options [ ] = $ quality ; } if ( $ filters !== null ) { if ( empty ( $ this -> _output_options ) ) { $ this -> _output_options [ ] = null ; } $ this -> _output_options [ ] = $ filters ; } return $ this ; }
Setting Output Format
2,405
public function exportImage ( $ keep_resource = false ) { array_unshift ( $ this -> _output_options , $ this -> _image_resource , $ this -> _save_path ) ; switch ( $ this -> _output_format ) { case 'jpeg' : case 'jpg' : if ( ! $ this -> _save_path ) { header ( 'content-type: image/jpeg' ) ; } $ result = call_user_func_array ( 'imagejpeg' , $ this -> _output_options ) ; break ; case 'png' : if ( ! $ this -> _save_path ) { header ( 'content-type: image/png' ) ; } $ result = call_user_func_array ( 'imagepng' , $ this -> _output_options ) ; break ; case 'gif' : if ( ! $ this -> _save_path ) { header ( 'content-type: image/gif' ) ; } $ result = call_user_func_array ( 'imagegif' , $ this -> _output_options ) ; break ; } unset ( $ this -> _output_options [ 0 ] , $ this -> _output_options [ 1 ] ) ; $ this -> _output_options = array_values ( $ this -> _output_options ) ; if ( $ keep_resource === false ) { $ this -> destroy ( ) ; } if ( ! $ this -> _save_path ) { exit ; } return ( $ result ) ? ( $ this -> _save_name ? $ this -> _save_name : true ) : false ; }
Save Or Output Current Image Resource
2,406
public function embed ( $ keep_resource = false ) { ob_start ( ) ; switch ( $ this -> _output_format ) { case 'jpeg' : case 'jpg' : imagejpeg ( $ this -> _image_resource ) ; break ; case 'png' : imagepng ( $ this -> _image_resource ) ; break ; case 'gif' : imagegif ( $ this -> _image_resource ) ; break ; } $ str = ob_get_contents ( ) ; ob_end_clean ( ) ; if ( ! $ keep_resource ) { imagedestroy ( $ this -> _image_resource ) ; } return 'data:image/' . $ this -> _output_format . ';base64,' . base64_encode ( $ str ) ; }
Get Image as embeded code
2,407
public function reset ( ) { if ( ! $ this -> _image_resource_backup ) { throw new ImageException ( 'Cannot restore, no backup has been taken for image resource' ) ; } $ cloned = $ this -> cloneResource ( $ this -> _image_resource_backup ) ; $ this -> _image_resource = $ cloned [ 'resource' ] ; $ this -> updateImageInfo ( $ cloned [ 'width' ] , $ cloned [ 'height' ] ) ; return $ this ; }
Restore Image resource from backup
2,408
private function updateImageInfo ( $ width , $ height ) { $ this -> _image_info [ 0 ] = $ width ; $ this -> _image_info [ 1 ] = $ height ; $ this -> _image_info [ 3 ] = 'width="' . $ width . '" height="' . $ height . '"' ; $ this -> _image_info [ 'aspect' ] = $ width / $ height ; }
Update Image Resource Info
2,409
protected function getRGBFromRange ( $ r , $ g , $ b , $ range ) { if ( ! $ range ) { return array ( $ r , $ g , $ b ) ; } $ range = round ( $ range / 2 ) ; $ color = array ( ) ; $ min = $ r - $ range ; $ max = $ r + $ range ; if ( $ min < 0 ) { $ min = 0 ; } if ( $ max > 255 ) { $ max = 255 ; } $ color [ 'r' ] = $ color [ 0 ] = rand ( $ min , $ max ) ; $ min = $ g - $ range ; $ max = $ g + $ range ; if ( $ min < 0 ) { $ min = 0 ; } if ( $ max > 255 ) { $ max = 255 ; } $ color [ 'g' ] = $ color [ 1 ] = rand ( $ min , $ max ) ; $ min = $ b - $ range ; $ max = $ b + $ range ; if ( $ min < 0 ) { $ min = 0 ; } if ( $ max > 255 ) { $ max = 255 ; } $ color [ 'b' ] = $ color [ 2 ] = rand ( $ min , $ max ) ; return $ color ; }
Get Random RGB Values on a specific range
2,410
private function cloneResource ( $ resource ) { $ w = imagesx ( $ resource ) ; $ h = imagesy ( $ resource ) ; $ trans = imagecolortransparent ( $ resource ) ; if ( imageistruecolor ( $ resource ) ) { $ clone = imagecreatetruecolor ( $ w , $ h ) ; imagealphablending ( $ clone , false ) ; imagesavealpha ( $ clone , true ) ; } else { $ clone = imagecreate ( $ w , $ h ) ; if ( $ trans >= 0 ) { $ rgb = imagecolorsforindex ( $ resource , $ trans ) ; imagesavealpha ( $ clone , true ) ; $ trans_index = imagecolorallocatealpha ( $ clone , $ rgb [ 'red' ] , $ rgb [ 'green' ] , $ rgb [ 'blue' ] , $ rgb [ 'alpha' ] ) ; imagefill ( $ clone , 0 , 0 , $ trans_index ) ; } } imagecopy ( $ clone , $ resource , 0 , 0 , 0 , 0 , $ w , $ h ) ; return [ 'resource' => $ clone , 'width' => $ w , 'height' => $ h , ] ; }
Clone Image Resource
2,411
public function composer ( $ views , $ callback ) { foreach ( ( array ) $ views as $ view ) { if ( $ callback instanceof Closure === false ) { $ callback = function ( ) use ( $ callback ) { return $ callback ; } ; } if ( $ view === '*' ) { $ this -> composers [ '*' ] [ ] = $ callback ; continue ; } $ view = $ this -> view ( $ view ) ; if ( ! isset ( $ this -> composers [ $ view ] ) ) { $ this -> composers [ $ view ] = [ ] ; } $ this -> composers [ $ view ] [ ] = $ callback ; } return $ this ; }
Register preprocess with views .
2,412
protected function extension ( $ view ) { $ extensions = $ this -> extensions ( ) ; $ ext_reg = '/(' . implode ( '|' , $ extensions ) . ')+$/' ; if ( preg_match ( $ ext_reg , $ view ) ) { return $ template ; } return substr ( $ view , - strlen ( $ extensions [ 0 ] ) ) === $ extensions [ 0 ] ? $ view : $ view . $ extensions [ 0 ] ; }
Add extension to the view string if it don t exists .
2,413
public function create_data ( $ data = [ ] ) { if ( is_object ( $ data ) && method_exists ( $ data , 'to_array' ) ) { return $ data -> to_array ( ) ; } return is_array ( $ data ) ? $ data : [ ] ; }
Create view data .
2,414
public function get_composer ( View $ view ) { $ view_name = $ view -> get_name ( ) ; if ( isset ( $ this -> composers [ $ view_name ] ) ) { return $ this -> composers [ $ view_name ] ; } return [ ] ; }
Call composer .
2,415
protected function view ( $ view ) { if ( preg_match ( '/\.\w+$/' , $ view , $ matches ) && in_array ( $ matches [ 0 ] , $ this -> extensions ( ) ) ) { return str_replace ( '.' , '/' , preg_replace ( '/' . $ matches [ 0 ] . '$/' , '' , $ view ) ) . $ matches [ 0 ] ; } return $ this -> extension ( str_replace ( '.' , '/' , $ view ) ) ; }
Get the right view string from dot view or view that missing extension .
2,416
protected function reset_composer ( View $ view ) { $ view_name = $ view -> get_name ( ) ; if ( isset ( $ this -> composers [ $ view_name ] ) ) { unset ( $ this -> composers [ $ view_name ] ) ; } }
Reset view composer .
2,417
public static function getControlCapabilities ( ) { $ caps = array ( ) ; foreach ( array_keys ( self :: $ virtualCapabilities ) as $ capabilityName ) { $ caps [ ] = self :: PREFIX_CONTROL . $ capabilityName ; } return $ caps ; }
Returns an array of all the control capabilities
2,418
static function sql_exec ( $ db , $ bindings , $ sql = null ) { if ( $ sql === null ) { $ sql = $ bindings ; } $ stmt = $ db -> prepare ( $ sql ) ; if ( is_array ( $ bindings ) ) { for ( $ i = 0 , $ ien = count ( $ bindings ) ; $ i < $ ien ; $ i ++ ) { $ binding = $ bindings [ $ i ] ; $ stmt -> bindValue ( $ binding [ 'key' ] , $ binding [ 'val' ] , $ binding [ 'type' ] ) ; } } try { $ stmt -> execute ( ) ; } catch ( PDOException $ e ) { self :: fatal ( "An SQL error occurred: " . $ e -> getMessage ( ) ) ; } return $ stmt -> fetchAll ( ) ; }
Execute an SQL query on the database
2,419
static function pluck ( $ a , $ prop ) { $ out = array ( ) ; for ( $ i = 0 , $ len = count ( $ a ) ; $ i < $ len ; $ i ++ ) { $ out [ ] = $ a [ $ i ] [ $ prop ] ; } return $ out ; }
Pull a particular property from each assoc . array in a numeric array returning and array of the property values from each item .
2,420
public function parse ( $ configFile = '' ) { $ defaultConfigFile = $ this -> getConfigFile ( $ configFile , 'default' ) ; $ defaultConfigArray = parent :: parse ( $ defaultConfigFile ) ? : [ ] ; $ envConfigFile = $ this -> getConfigFile ( $ configFile , $ this -> app -> getEnvironment ( ) ) ; $ envConfigArray = parent :: parse ( $ envConfigFile ) ? : [ ] ; return ArrayHelper :: merge ( $ defaultConfigArray , $ envConfigArray , $ deep = true ) ; }
Parse the configuration file and get the configuration array .
2,421
private function getConfigFile ( $ configFile , $ environment = 'default' ) { $ configFile = $ configFile ? : 'config' ; $ envConfigFile = $ this -> app -> getConfigPath ( ) . DIRECTORY_SEPARATOR . $ configFile . '-' . $ environment . '.php' ; if ( ! is_file ( $ envConfigFile ) ) { $ envConfigFile = $ this -> app -> getConfigPath ( ) . DIRECTORY_SEPARATOR . $ configFile . '.php' ; } return $ envConfigFile ; }
Get the configuration file according to the given environment if any .
2,422
public function init ( Parser $ parser , Lexer $ lexer ) { $ parser -> setStartRule ( $ this -> startRule ) ; foreach ( $ this -> rules as $ rule ) { $ parser -> addRule ( $ rule ) ; } $ parser -> setLexer ( $ lexer ) ; $ lexer -> setParser ( $ parser ) ; return $ this ; }
Set start rule and add set s rules to parser
2,423
protected function addRule ( AbstractRule $ rule , $ category = self :: CATEGORY_NONE ) { $ rule -> setRuleSet ( $ this ) ; $ this -> rules [ ] = $ rule ; $ this -> categories [ $ category ] [ ] = $ rule ; return $ this ; }
Add new rule to set
2,424
protected function getListeners ( string $ eventName ) : array { if ( ! isset ( $ this -> listeners [ $ eventName ] ) ) { return [ ] ; } if ( ! isset ( $ this -> sortedListeners [ $ eventName ] ) ) { $ this -> sortedListeners [ $ eventName ] = $ this -> sortEventListeners ( $ eventName ) ; } return $ this -> sortedListeners [ $ eventName ] ; }
Returns array of event listeners .
2,425
protected function sortEventListeners ( string $ eventName ) : array { $ listeners = $ this -> listeners [ $ eventName ] ; $ normalised = [ ] ; ksort ( $ listeners ) ; foreach ( $ listeners as $ priorityListeners ) { foreach ( $ priorityListeners as $ listener ) { $ normalised [ ] = $ listener ; } } return $ normalised ; }
Merges all event listeners for particular event .
2,426
public function cssClass ( $ type ) { $ framework = $ this -> getFramework ( ) ; $ classes = $ this -> getClasses ( $ framework ) ; if ( property_exists ( $ classes , $ type ) ) { return $ classes -> $ type ; } return '' ; }
Get the css class for a given object type .
2,427
public function columns ( $ xs , $ sm , $ md , $ lg ) { $ framework = $ this -> getFramework ( ) ; switch ( $ framework ) { case 'bs3' : case 'bs4' : $ xsC = $ this -> cssClass ( 'column_extra_small' ) . $ xs ; $ smC = $ this -> cssClass ( 'column_small' ) . $ sm ; $ mdC = $ this -> cssClass ( 'column_medium' ) . $ md ; $ lgC = $ this -> cssClass ( 'column_large' ) . $ lg ; return $ this -> buildClassString ( [ $ xsC , $ smC , $ mdC , $ lgC ] ) ; case 'f6' : $ smC = $ this -> cssClass ( 'column_small' ) . $ sm ; $ mdC = $ this -> cssClass ( 'column_medium' ) . $ md ; $ lgC = $ this -> cssClass ( 'column_large' ) . $ lg ; $ columns = $ this -> cssClass ( 'column' ) ; return $ this -> buildClassString ( [ $ columns , $ smC , $ mdC , $ lgC ] ) ; default : return '' ; break ; } }
Create framework column class .
2,428
public function getClasses ( $ framework ) { switch ( $ framework ) { case 'bs3' : $ classes = $ this -> json -> bs3 ; break ; case 'bs4' : $ classes = $ this -> json -> bs4 ; break ; case 'f6' : $ classes = $ this -> json -> f6 ; break ; case '' : default : return '' ; } return $ classes ; }
Get the css class matrix for the given framework .
2,429
public function send ( $ to , $ subject , $ body ) { if ( \ Sifo \ Domains :: getInstance ( ) -> getDebugMode ( ) ) { $ this -> _dispatchMailController ( $ to , $ subject , $ body ) ; } return parent :: send ( $ to , $ subject , $ body ) ; }
Send an email whith debug interruption .
2,430
protected function selectChoice ( ) { $ index = array_search ( $ this -> choices [ $ this -> cursor -> getPosition ( ) ] , $ this -> answers ) ; if ( false !== $ index ) { unset ( $ this -> answers [ $ index ] ) ; } else { $ this -> answers [ ] = $ this -> choices [ $ this -> cursor -> getPosition ( ) ] ; } $ this -> answers = array_values ( $ this -> answers ) ; return $ this ; }
Allows selecting multiple choices
2,431
public function sanitize ( $ var ) { global $ smcFunc ; if ( is_array ( $ var ) ) { foreach ( $ var as $ k => $ v ) $ var [ $ k ] = $ this -> sanitize ( $ v ) ; return $ var ; } else { $ var = ( string ) $ smcFunc [ 'htmltrim' ] ( $ smcFunc [ 'htmlspecialchars' ] ( $ var ) , ENT_QUOTES ) ; if ( ctype_digit ( $ var ) ) $ var = ( int ) $ var ; if ( empty ( $ var ) ) $ var = false ; } return $ var ; }
Sanitizes a var . Recursive . Treats any var as a string and cast it as an integer if necessary .
2,432
public function getStdClass ( $ formatAble = false ) { $ object = new stdClass ( ) ; $ object -> testProperty = 'test' ; $ object -> nullProperty = null ; $ object -> arrayProperty = [ 'level1' => [ 'level2a' => null , 'level2' => [ 'level3' => 'value' , 'level3b' => null , ] , ] , ] ; if ( $ formatAble ) { $ object = Manager :: formatAble ( $ object ) ; } return $ object ; }
Get stdClass dummy data .
2,433
public function getStdClassWithArray ( $ formatAble = false ) { $ object = new stdClass ( ) ; $ object -> array = [ [ 'key' => 'value' , 'key2' => 'value2' , ] , ] ; if ( $ formatAble ) { $ object = Manager :: formatAble ( $ object ) ; } return $ object ; }
Get stdClass dummy data with array .
2,434
public function getPost ( $ formatAble = false ) { $ post = Post :: published ( ) -> first ( ) ; $ post = self :: fix ( $ post ) ; if ( $ formatAble ) { $ post = Manager :: formatAble ( $ post ) ; } return $ post ; }
Get WordPress dummy data .
2,435
public function getMultiplePosts ( $ formatAble = false ) { $ posts = Post :: published ( ) -> get ( ) ; foreach ( $ posts as $ key => $ post ) { $ posts [ $ key ] = self :: fix ( $ post ) ; if ( $ formatAble ) { $ posts [ $ key ] = Manager :: formatAble ( $ posts [ $ key ] ) ; } } return $ posts ; }
Get multiple WordPress data .
2,436
final public function offsetSet ( $ index , $ value ) : void { if ( is_null ( $ index ) ) { throw CannotAlterCollection :: byAddingTo ( $ this ) ; } throw CannotAlterCollection :: byOverWriting ( $ this , $ index ) ; }
Disallows use of the offsetSet method .
2,437
public function get ( $ key , $ locale , $ package = 'default' , $ default = null ) { if ( empty ( $ key ) ) { return $ default ; } $ package = ( $ package ? : 'default' ) ; try { $ this -> loadTranslations ( $ locale , $ package ) ; $ array = ( static :: $ translations [ $ locale ] ? : [ ] ) ; $ value = ArrayHelper :: get ( $ array , $ key , $ default , true ) ; } catch ( Exception $ ex ) { $ value = $ default ; } return $ value ; }
Get a translation value . If the default value is null and no translation is found it throws Exception .
2,438
public static function create ( $ field ) : RowFieldNormalizerInterface { switch ( $ field ) { case Quotation :: ACTIVE : return new ActiveNormalizer ( ) ; case Quotation :: ASSISTS_MAGIC_POINTS : return new AssistsMagicPointsNormalizer ( ) ; case Quotation :: ASSISTS : return new AssistsNormalizer ( ) ; case Quotation :: AUTO_GOALS_MAGIC_POINTS : return new AutoGoalsMagicPointsNormalizer ( ) ; case Quotation :: AUTO_GOALS : return new AutoGoalsNormalizer ( ) ; case Quotation :: CODE : return new CodeNormalizer ( ) ; case Quotation :: GOALS_MAGIC_POINTS : return new GoalsMagicPointsNormalizer ( ) ; case Quotation :: GOALS : return new GoalsNormalizer ( ) ; case Quotation :: MAGIC_POINTS : return new MagicPointsNormalizer ( ) ; case Quotation :: ORIGINAL_MAGIC_POINTS : return new OriginalMagicPointsNormalizer ( ) ; case Quotation :: PENALTIES_MAGIC_POINTS : return new PenaltiesMagicPointsNormalizer ( ) ; case Quotation :: PENALTIES : return new PenaltiesNormalizer ( ) ; case Quotation :: PLAYER : return new PlayerNormalizer ( ) ; case Quotation :: QUOTATION : return new QuotationNormalizer ( ) ; case Quotation :: RED_CARDS_MAGIC_POINTS : return new RedCardsMagicPointsNormalizer ( ) ; case Quotation :: RED_CARDS : return new RedCardsNormalizer ( ) ; case Quotation :: ROLE : return new RoleNormalizer ( ) ; case Quotation :: SECONDARY_ROLE : return new SecondaryRoleNormalizer ( ) ; case Quotation :: TEAM : return new TeamNormalizer ( ) ; case Quotation :: VOTE : return new VoteNormalizer ( ) ; case Quotation :: YELLOW_CARDS_MAGIC_POINTS : return new YellowCardsMagicPointsNormalizer ( ) ; case Quotation :: YELLOW_CARDS : return new YellowCardsNormalizer ( ) ; default : throw new NotFoundFieldException ( 'Field not found: ' . $ field ) ; } }
Returns an implementation of RowFieldNormalizerInterface
2,439
public function available ( $ id , $ start , $ end ) { $ param = array ( 'start' => date ( "Y-m-d\TH:i:s\Z" , $ start ) , 'end' => date ( "Y-m-d\TH:i:s\Z" , $ end ) ) ; return $ this -> get ( 'metrics/definitions/' . urlencode ( $ id ) , $ param ) ; }
Get available metrics
2,440
public function metrics ( $ id , $ filter , $ start , $ end ) { $ param = array ( 'start' => date ( "Y-m-d\TH:i:s\Z" , $ start ) , 'end' => date ( "Y-m-d\TH:i:s\Z" , $ end ) , 'filter' => $ filter ) ; $ param = $ this -> makeJsonReady ( $ param ) ; return $ this -> get ( 'metrics/graphs/' . urlencode ( $ id ) , $ param ) ; }
Get actual metrics
2,441
public function dynamicMetrics ( $ filter , $ start , $ end , $ inventoryFilter = Null ) { $ urlencoded = '' ; $ query = array ( ) ; if ( isset ( $ inventoryFilter ) ) { $ query [ 'inventoryFilter' ] = $ inventoryFilter ; } if ( ! empty ( $ query ) ) { $ urlencoded = '?' . http_build_query ( $ query ) ; } $ param = array ( 'start' => date ( "Y-m-d\TH:i:s\Z" , $ start ) , 'end' => date ( "Y-m-d\TH:i:s\Z" , $ end ) , 'filter' => $ filter ) ; $ param = $ this -> makeJsonReady ( $ param ) ; return $ this -> get ( 'metrics/dynamicgraphs/' . $ urlencoded , $ param ) ; }
Get dynamic metrics
2,442
protected function executePayload ( $ payload , $ args ) { array_unshift ( $ args , $ this -> wrapped ) ; if ( $ payload instanceof Mutator ) { $ this -> wrapped = call_user_func_array ( $ payload , $ args ) ; return $ this ; } else { return call_user_func_array ( $ payload , $ args ) ; } }
Payload is either Mutator or Accessor . Both are supposed to be callable .
2,443
public function getElseSet ( string $ key , int $ ttl , callable $ callable ) { if ( $ this -> exists ( $ key ) ) { return $ this -> get ( $ key ) ; } try { $ callable_data = call_user_func ( $ callable ) ; } catch ( Exception $ e ) { } $ this -> set ( $ key , $ callable_data ) ; $ this -> expireAt ( $ key , time ( ) + $ ttl ) ; return $ this -> get ( $ key ) ; }
Get the cache key . If it does not exist execute the callable and set the cache key .
2,444
public function findByAuth ( $ provider , $ identifier ) { $ user = null ; $ login = $ this -> repository -> findByAuth ( $ provider , $ identifier ) ; if ( $ login !== null ) $ user = $ login -> getUser ( ) ; return $ user ; }
Attempt to find a UserInterface by given login credentials returns the UserInterface or null on error
2,445
public static function instance ( ) { if ( ! isset ( self :: $ instance ) ) { self :: $ instance = new self ; self :: $ instance -> boot ( ) ; self :: $ instance -> setup_actions ( ) ; } return self :: $ instance ; }
Get Plugin boilerplate loader instance .
2,446
public static function config ( $ key , $ value = null ) { return self :: factory ( ) -> engine ( ) -> config ( $ key , $ value ) ; }
Get or set configuration value .
2,447
public function load_extensions ( ) { $ extensions = [ new \ Frozzare \ Digster \ Extensions \ Filter_Extensions ( ) , new \ Frozzare \ Digster \ Extensions \ Function_Extensions ( ) , new \ Frozzare \ Digster \ Extensions \ Global_Extensions ( ) , new \ Frozzare \ Digster \ Extensions \ I18n_Extensions ( ) ] ; $ extensions = apply_filters ( 'digster/extensions' , $ extensions ) ; $ this -> factory -> engine ( ) -> register_extensions ( $ extensions ) ; }
Load Digster extensions .
2,448
public static function view ( $ view = null , array $ data = [ ] ) { if ( func_num_args ( ) === 0 ) { return self :: factory ( ) ; } return self :: factory ( ) -> make ( $ view , $ data ) ; }
Get the view class .
2,449
public static function resolveClass ( $ resource , $ id = null ) { $ class = 'IXF\\' . $ resource ; if ( class_exists ( $ class ) ) return new $ class ( $ id ) ; return new IXF \ ApiResource ( $ id ) ; }
If a class exists for the given resource return an instance of it else return an instance of the generic ApiResouce class .
2,450
public static function retrieve ( $ resource , $ id ) { $ instance = self :: resolveClass ( $ resource , $ id ) ; $ instance -> refresh ( $ resource ) ; return $ instance ; }
Retrieve an object by ID
2,451
public function refresh ( $ resource ) { $ url = $ url = '/' . $ resource . '/' . $ this -> id ; $ requestor = new ApiRequestor ( ) ; $ response = $ requestor -> request ( 'get' , $ url , $ this -> _retrieveOptions ) ; $ this -> refreshFrom ( $ response [ 0 ] ) ; return $ this ; }
Refresh the current object from the API service
2,452
public static function all ( $ resource , $ params = null ) { self :: _validateCall ( 'all' , $ params ) ; $ requestor = new ApiRequestor ( ) ; $ url = '/' . $ resource ; $ response = $ requestor -> request ( 'get' , $ url , $ params ) ; return Util :: convertToIxfObject ( $ response ) ; }
Get all objects of a given resource
2,453
public function save ( ) { $ requestor = new ApiRequestor ( ) ; $ params = $ this -> serializeParameters ( ) ; self :: _validateCall ( 'save' , $ params ) ; unset ( $ params [ 'id' ] ) ; if ( count ( $ params ) > 0 ) { $ url = '/' . $ this -> getType ( ) . '/' . $ this -> id ; return $ requestor -> request ( 'put' , $ url , $ params ) ; } return true ; }
Save an object
2,454
public function toString ( ) { $ email = '<' . Mime :: encodeEmail ( $ this -> email ( ) ) . '>' ; $ name = $ this -> name ( ) ; return $ name ? Mime :: encodeValue ( $ name ) . ' ' . $ email : $ email ; }
Return the encoded representation of the address
2,455
private function encodeCollection ( CollectionInterface $ action_result , ResponseInterface $ response ) { $ response = $ response -> write ( json_encode ( $ action_result ) ) -> withStatus ( 200 ) ; if ( $ action_result -> canBeEtagged ( ) ) { if ( $ action_result -> getApplicationIdentifier ( ) != $ this -> app_identifier ) { $ action_result -> setApplicationIdentifier ( $ this -> app_identifier ) ; } $ response = $ this -> cache_provider -> withEtag ( $ response , $ action_result -> getEtag ( $ this -> user_identifier ) ) ; $ response = $ this -> cache_provider -> withExpires ( $ response , '+90 days' ) ; } if ( $ action_result -> getCurrentPage ( ) && $ action_result -> getItemsPerPage ( ) ) { $ response = $ response -> withHeader ( 'X-PaginationCurrentPage' , $ action_result -> getCurrentPage ( ) ) -> withHeader ( 'X-PaginationItemsPerPage' , $ action_result -> getItemsPerPage ( ) ) -> withHeader ( 'X-PaginationTotalItems' , $ action_result -> count ( ) ) ; } else { $ response = $ response -> withHeader ( 'X-PaginationCurrentPage' , 0 ) -> withHeader ( 'X-PaginationItemsPerPage' , 0 ) -> withHeader ( 'X-PaginationTotalItems' , $ action_result -> count ( ) ) ; } return $ response ; }
Encode DataObject collection .
2,456
private function encodeSingle ( ObjectInterface $ action_result , ResponseInterface $ response ) { $ result = [ 'single' => $ action_result ] ; foreach ( $ action_result -> jsonSerializeDetails ( ) as $ k => $ v ) { if ( $ k == 'single' ) { throw new LogicException ( "JSON serialize details can't overwrite 'single' property" ) ; } else { $ result [ $ k ] = $ v ; } } $ response = $ response -> write ( json_encode ( $ result ) ) -> withStatus ( 200 ) ; if ( $ action_result instanceof EtagInterface ) { $ response = $ response -> withHeader ( 'Etag' , $ action_result -> getEtag ( $ this -> user_identifier ) ) ; } return $ response ; }
Encode individual DataObject object .
2,457
protected function encodeJsonSerializable ( JsonSerializable $ action_result , ResponseInterface $ response , $ status = 200 ) { return $ response -> write ( json_encode ( $ action_result ) ) -> withStatus ( $ status ) ; }
Encode JsonSerializable instance response with status 200 .
2,458
private function encodeUserSessionResponse ( UserSessionResponseInterface $ action_result , ServerRequestInterface $ request , ResponseInterface $ response ) { if ( $ action_result -> getAuthenticatedWith ( ) instanceof SessionInterface ) { $ response = $ this -> getCookiesProvider ( ) -> set ( $ request , $ response , $ this -> getUserSessionIdCookieName ( ) , $ action_result -> getAuthenticatedWith ( ) -> getSessionId ( ) , [ 'ttl' => 1209600 , 'http_only' => true , ] ) [ 1 ] ; } return $ this -> encodeArray ( $ action_result -> toArray ( ) , $ response ) ; }
Encode user session action results and return properly populated response .
2,459
private function encodeUserSessionTerminatedResponse ( UserSessionTerminateResponseInterface $ action_result , ServerRequestInterface $ request , ResponseInterface $ response ) { $ response = $ this -> getCookiesProvider ( ) -> remove ( $ request , $ response , $ this -> getUserSessionIdCookieName ( ) ) [ 1 ] ; return $ this -> encodeArray ( $ action_result -> toArray ( ) , $ response ) ; }
Encode user session terminated action results and return properly populated response .
2,460
private function _getFileContent ( ) { if ( ! isset ( $ this -> _index_file_content ) ) { if ( ! ( $ this -> _index_file_content = file_get_contents ( $ this -> _root_page_path ) ) ) { trigger_error ( "Root file not found. Please, validate the path." , E_USER_ERROR ) ; } } return $ this -> _index_file_content ; }
Return the platform index file content .
2,461
private function _enablePage ( ) { if ( $ this -> test ) { return true ; } $ enabled_source = $ this -> _getEnablingCode ( ) . $ this -> _getFileContent ( ) ; return file_put_contents ( $ this -> _root_page_path , $ enabled_source ) ; }
Enable the replacement page .
2,462
private function _disablePage ( ) { if ( $ this -> test ) { return true ; } $ disabled_source = str_replace ( $ this -> _getEnablingCode ( ) , '' , $ this -> _getFileContent ( ) ) ; return file_put_contents ( $ this -> _root_page_path , $ disabled_source ) ; ; }
Disable the replacement page . Normal page is enabled .
2,463
public function getAllStations ( DWDHourlyParameters $ hourlyParameters , bool $ active = false ) { $ services = $ this -> createServices ( $ hourlyParameters ) ; $ crawler = new DWDHourlyCrawler ( $ services ) ; return $ crawler -> getAllStations ( $ active ) ; }
Retrieve all stations for the parameters
2,464
private function createServices ( DWDHourlyParameters $ variables ) : array { $ conf = DWDConfiguration :: getHourlyConfiguration ( ) -> parameters ; $ controllers = array ( ) ; if ( ! empty ( $ variables -> getVariables ( ) ) ) { foreach ( $ variables -> getVariables ( ) as $ var ) { switch ( $ var ) { case $ conf -> pressure -> name : $ controllers [ $ conf -> pressure -> name ] = new HourlyPressureService ( 'pressure' ) ; break ; case $ conf -> airTemperature -> name : $ controllers [ $ conf -> airTemperature -> name ] = new HourlyAirTemperatureService ( 'airTemperature' ) ; break ; case $ conf -> cloudiness -> name : $ controllers [ $ conf -> cloudiness -> name ] = new HourlyCloudinessService ( 'cloudiness' ) ; break ; case $ conf -> precipitation -> name : $ controllers [ $ conf -> precipitation -> name ] = new HourlyPrecipitationService ( 'precipitation' ) ; break ; case $ conf -> soilTemperature -> name : $ controllers [ $ conf -> soilTemperature -> name ] = new HourlySoilTempService ( 'soilTemperature' ) ; break ; case $ conf -> solar -> name : $ controllers [ $ conf -> solar -> name ] = new HourlySolarService ( 'solar' ) ; break ; case $ conf -> sun -> name : $ controllers [ $ conf -> sun -> name ] = new HourlySunService ( 'sun' ) ; break ; case $ conf -> wind -> name : $ controllers [ $ conf -> wind -> name ] = new HourlyWindService ( 'wind' ) ; break ; default : print ( 'Unknown variable: var=' . $ var . '<br>' ) ; } } } return $ controllers ; }
Create a new instance of the appropriate controller .
2,465
protected function bootMiddleWares ( ) { if ( isset ( $ this -> middleWares [ 'boot' ] ) && count ( $ this -> middleWares [ 'boot' ] ) ) { foreach ( $ this -> middleWares [ 'boot' ] as $ middleware => $ handler ) { $ this -> container -> call ( [ $ this -> container -> make ( $ middleware ) , $ handler ] ) ; } return [ ] ; } $ CSRFProtection = $ this -> container -> make ( CSRFProtection :: class ) ; return $ this -> container -> call ( [ $ CSRFProtection , 'handle' ] ) ; }
Resolve application boot middleware .
2,466
protected function resolveDependencies ( array $ dependencies ) { foreach ( $ dependencies as $ dependency => $ type ) { call_user_func_array ( [ $ this , $ type ] , [ $ dependency ] ) ; } }
Application dependency binding to container .
2,467
private function expandShorthandDefinitions ( ) { foreach ( $ this -> mapping as $ key => $ settings ) { if ( is_string ( $ key ) && is_string ( $ settings ) ) { $ this -> mapping [ $ key ] = [ 'type' => 'column' , 'mapping' => [ 'destination' => $ settings ] ] ; } } }
Expands shorthand definitions to theirs full definition
2,468
public function getCsvFiles ( ) { $ childResults = [ ] ; foreach ( $ this -> parsers as $ type => $ parser ) { $ childResults += $ parser -> getCsvFiles ( ) ; } $ results = array_merge ( [ $ this -> type => $ this -> result ] , $ childResults ) ; return $ results ; }
Return own result and all children
2,469
public function isValid ( ) { if ( $ this -> isValid === null ) $ this -> isValid = $ this -> validate ( ) ; return $ this -> isValid ; }
Returns true if this length unit is valid .
2,470
public function compareTo ( $ l ) { if ( $ l === false ) return false ; if ( $ l -> unit !== $ this -> unit ) { $ converter = new HTMLPurifier_UnitConverter ( ) ; $ l = $ converter -> convert ( $ l , $ this -> unit ) ; if ( $ l === false ) return false ; } return $ this -> n - $ l -> n ; }
Compares two lengths and returns 1 if greater - 1 if less and 0 if equal .
2,471
public function sortAscending ( array $ prefList ) { $ comparator = new MatchedPreferenceComparator ( ) ; usort ( $ prefList , function ( MatchedPreferenceInterface $ lValue , MatchedPreferenceInterface $ rValue ) use ( $ comparator ) { return - 1 * $ comparator -> compare ( $ lValue , $ rValue ) ; } ) ; return $ prefList ; }
Sort the array of MatchedPreference instances in ascending order .
2,472
public static function fromDefaults ( ) { $ handler = new HandlerLDAP ( config ( 'ldap.host' ) , config ( 'ldap.basedn' ) , config ( 'ldap.dn' ) , config ( 'ldap.password' ) , config ( 'ldap.search_user_id' ) , config ( 'ldap.search_username' ) , config ( 'ldap.search_user_mail' ) , config ( 'ldap.search_user_mail_array' ) ) ; $ handler -> setVersion ( config ( 'ldap.version' ) ) ; $ handler -> setOverlayDN ( config ( 'ldap.overlay_dn' ) ) ; $ handler -> setAddBaseDN ( config ( 'ldap.add_base_dn' ) ) ; $ handler -> setAddDN ( config ( 'ldap.add_dn' ) ) ; $ handler -> setAddPassword ( config ( 'ldap.add_pw' ) ) ; $ handler -> setModifyMethod ( config ( 'ldap.modify_method' ) ) ; $ handler -> setModifyBaseDN ( config ( 'ldap.modify_base_dn' ) ) ; $ handler -> setModifyDN ( config ( 'ldap.modify_dn' ) ) ; $ handler -> setModifyPassword ( config ( 'ldap.modify_pw' ) ) ; return $ handler ; }
Returns a HandlerLDAP instance based on the default configuration .
2,473
protected function addMessage ( $ instance ) { $ message = \ Sifo \ FilterPost :: getInstance ( ) -> getString ( 'msgid' ) ; $ translator_model = new I18nTranslatorModel ( ) ; $ instance_domains = $ this -> getConfig ( 'domains' , $ instance ) ; $ instance_inheritance = array ( ) ; if ( isset ( $ instance_domains [ 'instance_inheritance' ] ) ) { $ instance_inheritance = $ instance_domains [ 'instance_inheritance' ] ; } if ( $ translator_model -> getMessageInInhertitance ( $ message , $ instance_inheritance ) > 0 ) { return array ( 'status' => 'KO' , 'msg' => 'This message already exists in parent instance. Please, customize it.' ) ; } elseif ( $ translator_model -> addMessage ( $ message , $ instance ) ) { return array ( 'status' => 'OK' , 'msg' => 'Message successfully saved.' ) ; } return array ( 'status' => 'KO' , 'msg' => 'Failed adding message.' ) ; }
Add message .
2,474
protected function customizeTranslation ( ) { $ message = \ Sifo \ FilterPost :: getInstance ( ) -> getString ( 'msgid' ) ; $ id_message = null ; if ( is_numeric ( $ message ) ) { $ id_message = $ message ; } $ instance = $ this -> getParsedParam ( 'instance' ) ; $ translator_model = new I18nTranslatorModel ( ) ; $ id_message = $ translator_model -> getTranslation ( $ message , $ id_message ) ; $ result = array ( 'status' => 'KO' , 'msg' => 'This Message or ID doesn\'t exist.' ) ; if ( $ id_message ) { $ result = array ( 'status' => 'OK' , 'msg' => 'Message successfully customized.' ) ; if ( ! $ translator_model -> customizeTranslation ( $ id_message , $ instance ) ) { $ result = array ( 'status' => 'KO' , 'msg' => 'This message is already customized in this instance.' ) ; } } return $ result ; }
Customize translation .
2,475
public function handleError ( HTTPInputRequest $ request , HTTPOutputResponse $ response , \ Throwable $ e ) : void { if ( $ e instanceof HTTPError ) { $ e -> generateErrorResponse ( ) ; } throw $ e ; }
Handle HTTP error or other \ Throwable instance throwed under HTTP access .
2,476
public function indexAction ( ) { $ view = new ViewModel ( ) ; $ service = $ this -> getThemeService ( ) ; $ view -> registeredThemes = $ service -> getRegisteredThemes ( ) ; $ view -> options = $ this -> getModuleOptions ( ) ; $ flashMessenger = $ this -> flashMessenger ( ) ; if ( $ flashMessenger -> hasMessages ( ) ) { $ view -> messages = $ flashMessenger -> getMessages ( ) ; } return $ view ; }
Show list of themes .
2,477
public function enableAction ( ) { $ themeName = $ this -> params ( ) -> fromRoute ( 'theme' ) ; if ( ! $ themeName ) { $ this -> flashMessenger ( ) -> addMessage ( $ this -> scTranslate ( 'Theme was not specified.' ) ) ; return $ this -> redirect ( ) -> toRoute ( 'sc-admin/theme' ) -> setStatusCode ( 303 ) ; } $ service = $ this -> getThemeService ( ) ; if ( ! $ service -> enableTheme ( $ themeName ) ) { foreach ( $ service -> getMessages ( ) as $ message ) { $ this -> flashMessenger ( ) -> addMessage ( $ message ) ; } } return $ this -> redirect ( ) -> toRoute ( 'sc-admin/theme' ) ; }
Enable theme .
2,478
public function disableAction ( ) { $ themeName = $ this -> params ( ) -> fromRoute ( 'theme' ) ; if ( ! $ themeName ) { $ this -> flashMessenger ( ) -> addMessage ( $ this -> scTranslate ( 'Theme was not specified.' ) ) ; return $ this -> redirect ( ) -> toRoute ( 'sc-admin/theme' ) -> setStatusCode ( 303 ) ; } $ service = $ this -> getThemeService ( ) ; if ( ! $ service -> disableTheme ( $ themeName ) ) { foreach ( $ service -> getMessages ( ) as $ message ) { $ this -> flashMessenger ( ) -> addMessage ( $ message ) ; } } return $ this -> redirect ( ) -> toRoute ( 'sc-admin/theme' ) ; }
Disable theme .
2,479
public function defaultAction ( ) { $ themeName = $ this -> params ( ) -> fromRoute ( 'theme' ) ; if ( ! $ themeName ) { $ this -> flashMessenger ( ) -> addMessage ( $ this -> scTranslate ( 'Theme was not specified.' ) ) ; return $ this -> redirect ( ) -> toRoute ( 'sc-admin/theme' ) -> setStatusCode ( 303 ) ; } $ side = $ this -> params ( ) -> fromRoute ( 'side' , 'frontend' ) ; $ service = $ this -> getThemeService ( ) ; if ( ! $ service -> setDefault ( $ themeName , $ side ) ) { foreach ( $ service -> getMessages ( ) as $ message ) { $ this -> flashMessenger ( ) -> addMessage ( $ message ) ; } } return $ this -> redirect ( ) -> toRoute ( 'sc-admin/theme' ) ; }
Set the default theme .
2,480
public static function self ( array $ option = array ( ) ) { if ( ! self :: $ self ) { self :: $ self = new self ( $ option ) ; } return self :: $ self ; }
Instance for current process
2,481
public function parallel ( $ closure , $ options = array ( ) , $ start = true ) { if ( is_bool ( $ options ) ) { $ start = $ options ; $ options = array ( ) ; } if ( $ closure instanceof Process ) { $ child = $ closure ; $ closure = $ child -> runner ; $ options = $ child -> options ; } else { $ child = new Process ( $ this , null , $ this -> pid ) ; $ options = $ this -> getOptions ( $ options ) ; } if ( ! $ start ) { $ child -> register ( $ closure , $ options ) ; if ( ! in_array ( $ child , $ this -> prepared_children ) ) { $ this -> prepared_children [ ] = $ child ; } return $ child ; } if ( $ options [ 'init' ] instanceof \ Closure ) { $ options [ 'init' ] ( $ child ) ; } $ pid = pcntl_fork ( ) ; $ this -> children [ $ pid ] = $ child ; if ( ( $ index = array_search ( $ child , $ this -> prepared_children ) ) !== false ) { unset ( $ this -> prepared_children [ $ index ] ) ; } if ( $ pid === - 1 ) { throw new \ RuntimeException ( 'Unable to fork child process.' ) ; } else if ( $ pid ) { $ child -> init ( $ pid ) ; $ child -> emit ( 'fork' ) ; return $ child ; } else { $ this -> childInitialize ( $ options ) ; call_user_func ( $ closure , $ this -> process ) ; exit ; } }
Run the closure in parallel space
2,482
public function daemonize ( ) { $ pid = pcntl_fork ( ) ; if ( $ pid === - 1 ) { throw new \ RuntimeException ( 'Unable to fork child process.' ) ; } else if ( $ pid ) { exit ; } posix_setsid ( ) ; if ( $ pid === - 1 ) { throw new \ RuntimeException ( 'Unable to fork child process.' ) ; } else if ( $ pid ) { exit ; } $ this -> prepared = false ; $ pid = posix_getpid ( ) ; $ this -> ppid = $ this -> pid ; $ this -> pid = $ pid ; $ this -> queue = null ; $ this -> process = new Process ( $ this , $ this -> pid , $ this -> ppid ) ; $ this -> children = array ( ) ; $ this -> prepared = true ; return $ this ; }
Make the process daemonize
2,483
public function listen ( ) { if ( ! $ this -> queue ) { $ this -> queue = msg_get_queue ( $ this -> pid ) ; $ this -> emit ( 'listen' ) ; } return $ this ; }
Register message listener
2,484
protected function childInitialize ( array $ options = array ( ) ) { $ this -> prepared = false ; $ this -> removeAllListeners ( ) ; $ this -> master = false ; $ pid = posix_getpid ( ) ; $ this -> ppid = $ this -> pid ; $ this -> pid = $ pid ; $ this -> queue = null ; $ this -> process = new Process ( $ this , $ this -> pid , $ this -> ppid ) ; $ this -> children = array ( ) ; $ this -> prepared = true ; $ options = $ options + self :: $ child_options ; $ this -> childProcessOptions ( $ options ) ; }
Init child process
2,485
protected function childProcessOptions ( $ options ) { if ( $ options [ 'cwd' ] ) { chdir ( $ options [ 'cwd' ] ) ; } if ( $ options [ 'user' ] ) { $ this -> childChangeUser ( $ options [ 'user' ] ) ; } if ( $ options [ 'env' ] ) { $ this -> childChangeEnv ( $ options [ 'env' ] ) ; } if ( $ options [ 'timeout' ] ) { $ this -> childSetTimeout ( $ options [ 'timeout' ] ) ; } if ( $ options [ 'callback' ] instanceof \ Closure ) { $ options [ 'callback' ] ( $ this ) ; } }
Process options in child
2,486
protected function tryChangeUser ( $ user ) { $ changed_user = false ; if ( $ user && posix_getuid ( ) > 0 ) { throw new \ RuntimeException ( 'Only root can change user to spawn the process' ) ; } if ( $ user && ! ( $ changed_user = posix_getpwnam ( $ user ) ) ) { throw new \ RuntimeException ( 'Can not look up user: ' . $ user ) ; } return $ changed_user ; }
Try to change user
2,487
protected function childSetTimeout ( $ timeout ) { $ start_time = time ( ) ; $ self = $ this ; $ this -> on ( 'tick' , function ( ) use ( $ timeout , $ start_time , $ self ) { if ( $ start_time + $ timeout < time ( ) ) $ self -> shutdown ( 1 ) ; } ) ; }
Try to set timeout
2,488
protected function childChangeUser ( $ user ) { if ( is_array ( $ user ) || ( $ user = $ this -> tryChangeUser ( $ user ) ) ) { posix_setgid ( $ user [ 'gid' ] ) ; posix_setuid ( $ user [ 'uid' ] ) ; } }
Process change user
2,489
protected function signalHandlerDefault ( $ signal ) { switch ( $ signal ) { case SIGTERM : case SIGINT : while ( $ this -> children ) { foreach ( $ this -> children as $ child ) { $ ok = $ child -> kill ( SIGINT ) ; if ( posix_get_last_error ( ) == 1 ) $ ok = false ; if ( $ ok ) { $ child -> emit ( 'abort' , $ signal ) ; $ child -> shutdown ( $ signal ) ; $ this -> clear ( $ child ) ; } } } $ this -> emit ( 'abort' , $ signal ) ; $ this -> shutdown ( $ signal ) ; exit ; break ; } }
Default signal handler
2,490
public function shutdown ( $ status = 0 , $ info = null ) { if ( ! $ this -> process -> isExit ( ) ) { $ this -> process -> status = $ status ; $ this -> emit ( 'exit' , $ status , $ info ) ; $ this -> process -> emit ( 'exit' , $ status , $ info ) ; } }
Shutdown with status
2,491
protected function registerTickHandlers ( ) { $ self = $ this ; register_tick_function ( function ( ) use ( $ self ) { if ( ! $ self -> prepared ) { return ; } if ( $ self -> master ) { while ( $ pid = pcntl_wait ( $ status , WNOHANG ) ) { if ( $ pid === - 1 ) { pcntl_signal_dispatch ( ) ; break ; } if ( empty ( $ self -> children [ $ pid ] ) ) continue ; $ self -> children [ $ pid ] -> emit ( 'finish' , $ status ) ; $ self -> children [ $ pid ] -> shutdown ( $ status ) ; $ self -> clear ( $ pid ) ; } } $ self -> emit ( 'tick' ) ; if ( ! is_resource ( $ self -> queue ) || ! msg_stat_queue ( $ self -> queue ) ) { return ; } while ( msg_receive ( $ self -> queue , 1 , $ null , 1024 , $ msg , true , MSG_IPC_NOWAIT , $ error ) ) { if ( ! is_array ( $ msg ) || empty ( $ msg [ 'to' ] ) || $ msg [ 'to' ] != $ self -> pid ) { $ self -> emit ( 'unknown_message' , $ msg ) ; } else { if ( $ self -> master ) { if ( ! empty ( $ self -> children [ $ msg [ 'from' ] ] ) && ( $ process = $ self -> children [ $ msg [ 'from' ] ] ) ) { $ process -> emit ( 'message' , $ msg [ 'body' ] ) ; } else { $ self -> emit ( 'unknown_message' , $ msg ) ; } } else if ( $ msg [ 'from' ] == $ self -> ppid ) { $ self -> process -> emit ( 'message' , $ msg [ 'body' ] ) ; } } } } ) ; }
Register tick handlers
2,492
static function getDataFromZip ( $ zipFile , $ extractionPrefix ) { $ zip = new ZipArchive ; self :: log ( self :: class , "zip=" . $ zipFile ) ; if ( $ zip -> open ( $ zipFile ) ) { for ( $ i = 0 ; $ i < $ zip -> numFiles ; $ i ++ ) { $ stat = $ zip -> statIndex ( $ i ) ; if ( substr ( $ stat [ 'name' ] , 0 , strlen ( $ extractionPrefix ) ) === $ extractionPrefix ) { return $ zip -> getFromName ( $ stat [ 'name' ] ) ; } } $ zip -> close ( ) ; } else { throw new DWDLibException ( "zip content is empty! zip file count=" . $ zip -> numFiles ) ; } return null ; }
Extract the single file we need to use to get the data .
2,493
public function datetime ( $ name , $ value = null , $ options = [ ] ) { $ value = $ this -> getValueAttribute ( $ name , $ value ) ; $ timeValue = $ dateValue = null ; if ( $ value instanceof \ DateTime ) { $ dateValue = $ value -> format ( 'Y-m-d' ) ; $ timeValue = $ value -> format ( 'H:i' ) ; } return $ this -> date ( $ name . '[date]' , $ dateValue , $ options ) . $ this -> time ( $ name . '[time]' , $ timeValue , $ options ) ; }
Create a date and a time input field .
2,494
public function validateSweetcaptcha ( $ attribute , $ value , $ parameters ) { if ( Input :: has ( 'scvalue' ) ) { $ sweetcaptcha = app ( ) -> make ( 'SweetCaptcha' ) ; return $ sweetcaptcha -> check ( array ( 'sckey' => $ value , 'scvalue' => Input :: get ( 'scvalue' ) ) ) == "true" ; } else return false ; }
Validation method for the Sweet Captcha input values .
2,495
public static function setClient ( $ input = null ) { self :: $ client = ( $ input instanceof Google_client ) ? $ input : new Google_Client ( ) ; if ( is_array ( $ input ) ) { foreach ( $ input as $ key => $ value ) { $ method = "set" . ucfirst ( $ key ) ; if ( ! method_exists ( self :: $ client , $ method ) ) { throw new Exception ( "setClient() Config Key: `{$key}` is invalid referred to Google_Client->{$method}()" , 500 ) ; } call_user_func ( [ self :: $ client , $ method ] , $ value ) ; } } return new self ; }
New a Google_Client with config or set Google_Client by giving
2,496
public static function verifyAccessToken ( $ accessToken = null ) { if ( null === $ accessToken ) { $ token = self :: getClient ( ) -> getAccessToken ( ) ; if ( ! isset ( $ token [ 'access_token' ] ) ) { throw new Exception ( 'access_token must be passed in or set as part of setAccessToken' ) ; } $ accessToken = $ token [ 'access_token' ] ; } $ response = ( new \ GuzzleHttp \ Client ( ) ) -> request ( 'GET' , self :: TOKENINFO_URI , [ 'query' => [ 'access_token' => $ accessToken , ] , 'http_errors' => false , ] ) ; if ( 200 != $ response -> getStatusCode ( ) ) { return false ; } return json_decode ( $ response -> getBody ( ) , true ) ; }
Verify an access_token . This method will verify the current access_token by Google API if one isn t provided .
2,497
public static function verifyScopes ( $ scopes , $ accessToken = null ) { if ( ! $ tokenInfo = self :: verifyAccessToken ( $ accessToken ) ) return false ; $ scopeString = $ tokenInfo [ 'scope' ] ; foreach ( $ scopes as $ key => $ scope ) { if ( stripos ( $ scopeString , $ scope ) === false ) return false ; } return true ; }
Verify scopes of tokenInfo by access_token . This method will verify the current access_token by Google API if one isn t provided .
2,498
public function setId ( Schema $ schema , $ id ) { $ reset_unique_field = ( $ schema -> getUniqueFieldId ( ) === $ this -> _id ) ; $ schema -> removeField ( $ this -> _id ) ; $ this -> _id = $ id ; $ schema -> attachField ( $ this ) ; if ( $ reset_unique_field ) { $ schema -> setUniqueField ( $ id ) ; } return $ this ; }
Resets the unique identifier of the field .
2,499
public function setName ( Schema $ schema , $ name ) { $ schema -> removeField ( $ this -> _id ) ; $ this -> _name = $ name ; $ schema -> attachField ( $ this ) ; return $ this ; }
Sets the name of the field as stored in the index .