idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
5,400
public function register ( ) { wp_register_style ( $ this -> handle , $ this -> url , $ this -> dependencies , $ this -> version , $ this -> media ) ; $ this -> is_registered = true ; }
Register the stylesheet .
5,401
public function autoload_init ( ) { $ this -> init ( ) ; for ( $ i = count ( $ this -> addons ) - 1 ; $ i >= 0 ; -- $ i ) { $ this -> addons [ $ i ] -> init ( ) ; } }
Called by autoload to init class .
5,402
public function autoload_on_admin ( ) { $ this -> on_admin ( ) ; for ( $ i = count ( $ this -> addons ) - 1 ; $ i >= 0 ; -- $ i ) { $ this -> addons [ $ i ] -> on_admin ( ) ; } }
Called by autoload to init on admin .
5,403
public function add_hooks ( ) { if ( function_exists ( 'add_action' ) && function_exists ( 'add_filter' ) && function_exists ( 'add_shortcode' ) ) { foreach ( $ this -> actions as $ action ) { add_action ( $ action [ 'hook' ] , [ & $ this , $ this -> get_mapped_mvc_call ( $ action [ 'mvc' ] ) ] , $ action [ 'priority' ] , $ action [ 'args' ] ) ; } foreach ( $ this -> filters as $ filter ) { add_filter ( $ filter [ 'hook' ] , [ & $ this , $ this -> get_mapped_mvc_call ( $ filter [ 'mvc' ] , true ) ] , $ filter [ 'priority' ] , $ filter [ 'args' ] ) ; } foreach ( $ this -> shortcodes as $ shortcode ) { add_shortcode ( $ shortcode [ 'tag' ] , [ & $ this , $ this -> get_mapped_mvc_call ( $ shortcode [ 'mvc' ] , true ) ] ) ; } if ( count ( $ this -> widgets ) > 0 ) { add_action ( 'widgets_init' , [ & $ this , '_widgets' ] , 1 ) ; } } }
Adds hooks and filters into Wordpress core .
5,404
public function addClockFeature ( $ showSeconds = true , $ showFullDate = false ) { $ clock = new Clock ( $ this , $ showSeconds , $ showFullDate ) ; $ this -> addScriptFeature ( $ clock ) ; return $ this ; }
Add a dynamic Feature showing the current time
5,405
protected function handlePATCH ( ) { $ content = $ this -> getPayloadData ( ) ; if ( empty ( $ this -> folderPath ) ) { $ this -> driver -> updateContainerProperties ( $ this -> container , $ content ) ; } else { if ( empty ( $ this -> filePath ) ) { $ this -> driver -> updateFolderProperties ( $ this -> container , $ this -> folderPath , $ content ) ; } else { $ this -> driver -> updateFileProperties ( $ this -> container , $ this -> filePath , $ content ) ; } } return ResponseFactory :: create ( [ 'success' => true ] ) ; }
Handles PATCH actions .
5,406
protected function handleDELETE ( ) { $ force = $ this -> request -> getParameterAsBool ( 'force' , false ) ; $ noCheck = $ this -> request -> getParameterAsBool ( 'no_check' , false ) ; $ contentOnly = $ this -> request -> getParameterAsBool ( 'content_only' , false ) ; if ( empty ( $ this -> folderPath ) ) { if ( ! empty ( $ content = ResourcesWrapper :: unwrapResources ( $ this -> request -> getPayloadData ( ) ) ) ) { $ result = $ this -> deleteFolderContent ( $ content , '' , $ force ) ; } else { throw new BadRequestException ( 'No resources given for delete.' ) ; } } else { if ( empty ( $ this -> filePath ) ) { if ( ! empty ( $ content = ResourcesWrapper :: unwrapResources ( $ this -> request -> getPayloadData ( ) ) ) ) { $ result = $ this -> deleteFolderContent ( $ content , $ this -> folderPath , $ force ) ; } else { $ this -> driver -> deleteFolder ( $ this -> container , $ this -> folderPath , $ force , $ contentOnly ) ; $ result = [ 'name' => basename ( $ this -> folderPath ) , 'path' => $ this -> folderPath ] ; } } else { $ this -> driver -> deleteFile ( $ this -> container , $ this -> filePath , $ noCheck ) ; $ result = [ 'name' => basename ( $ this -> filePath ) , 'path' => $ this -> filePath ] ; } } return ResponseFactory :: create ( ResourcesWrapper :: cleanResources ( $ result ) ) ; }
Handles DELETE actions .
5,407
private static function resetAsseticConfig ( ) { return ; $ aYaml = Yaml :: parse ( file_get_contents ( self :: $ _container -> get ( 'kernel' ) -> getRootDir ( ) . '/config/config_dev.yml' ) ) ; $ aYaml [ 'assetic' ] [ 'use_controller' ] = false ; $ sNewYaml = Yaml :: dump ( $ aYaml , 5 ) ; file_put_contents ( self :: $ _container -> get ( 'kernel' ) -> getRootDir ( ) . '/config/config_dev.yml' , $ sNewYaml ) ; $ aYaml = Yaml :: parse ( file_get_contents ( self :: $ _container -> get ( 'kernel' ) -> getRootDir ( ) . '/config/config_prod.yml' ) ) ; $ aYaml [ 'assetic' ] [ 'use_controller' ] = false ; $ sNewYaml = Yaml :: dump ( $ aYaml , 5 ) ; file_put_contents ( self :: $ _container -> get ( 'kernel' ) -> getRootDir ( ) . '/config/config_prod.yml' , $ sNewYaml ) ; }
reset assitx - config not to use controller
5,408
private static function _saveControlUrl ( ) { $ oStatement = self :: $ _connection -> prepare ( 'INSERT INTO `system_settings` (`key` ,`value`)VALUES (:key, :value);' ) ; $ oResult = $ oStatement -> execute ( array ( ":key" => "control_url" , ":value" => self :: $ _data [ 'controlUrl' ] , ) ) ; if ( $ oResult !== true ) { throw new Exception ( "Error while inserting control url" ) ; } $ oStatement = self :: $ _connection -> prepare ( 'INSERT INTO `license` (`id`, `max_clients`, `domain`, `serial`, `valid_until`) VALUES (null, 0, :control_url , \'\', 0);' ) ; $ oResult = $ oStatement -> execute ( array ( ":control_url" => self :: $ _data [ 'controlUrl' ] , ) ) ; }
save control - url to database
5,409
private static function _saveSystemConfig ( ) { $ sYmlDump = array ( 'parameters' => array ( 'database_driver' => self :: checkEmpty ( self :: $ _data [ 'dbDriver' ] ) , 'database_host' => self :: checkEmpty ( self :: $ _data [ 'dbHost' ] ) , 'database_port' => self :: checkEmpty ( self :: $ _data [ 'dbPort' ] ) , 'database_name' => self :: checkEmpty ( self :: $ _data [ 'dbName' ] ) , 'database_user' => self :: checkEmpty ( self :: $ _data [ 'dbUser' ] ) , 'database_password' => self :: checkEmpty ( self :: $ _data [ 'dbPassword' ] ) , 'mailer_transport' => self :: checkEmpty ( self :: $ _data [ 'mailerTransport' ] ) , 'mailer_host' => self :: checkEmpty ( self :: $ _data [ 'mailerHost' ] ) , 'mailer_user' => self :: checkEmpty ( self :: $ _data [ 'mailerUser' ] ) , 'mailer_password' => self :: checkEmpty ( self :: $ _data [ 'mailerPassword' ] ) , 'locale' => 'de' , 'secret' => md5 ( uniqid ( null , true ) ) , ) , ) ; $ oDumper = new Dumper ( ) ; $ sYaml = $ oDumper -> dump ( $ sYmlDump , 99 , 0 , true , false ) ; $ sAppPath = self :: $ _container -> get ( 'kernel' ) -> getRootDir ( ) ; $ sPath = $ sAppPath . '/config/parameters.yml' ; $ sYaml = str_replace ( "'" , '' , $ sYaml ) ; file_put_contents ( $ sPath , $ sYaml ) ; }
save systemconfig to parameters . yml
5,410
private static function _createAdminUser ( ) { $ oUser = new User ( ) ; $ factory = self :: $ _container -> get ( 'security.encoder_factory' ) ; $ encoder = $ factory -> getEncoder ( $ oUser ) ; $ sSalt = $ oUser -> getSalt ( ) ; $ sPassword = $ encoder -> encodePassword ( self :: $ _data [ 'adminPassword' ] , $ sSalt ) ; $ oStatement = self :: $ _connection -> prepare ( 'INSERT INTO `user` (`id`, `username`, `password`, `salt`, `firstname`, `lastname`, `email`, `phone`, `memo`, `activated`, `last_login`, `notification_change`, `notification_error`) VALUES (null, :adminUser, :adminPassword , :adminPasswordSalt, \'admin\', \'admin\', :adminEmail, \'\', \'\', 1, \'0000-00-00 00:00:00\', 1, 1);' ) ; $ oResult = $ oStatement -> execute ( array ( ":adminUser" => self :: $ _data [ 'adminUser' ] , ":adminPassword" => $ sPassword , ":adminPasswordSalt" => $ sSalt , ":adminEmail" => self :: $ _data [ 'adminEmail' ] , ) ) ; if ( $ oResult !== true ) { throw new Exception ( "Error while creating admin user" ) ; } $ iUserId = self :: $ _connection -> lastInsertId ( ) ; $ oStatement = self :: $ _connection -> prepare ( 'INSERT INTO `user_role` (`user_id` ,`role_id`)VALUES (:user_id, :user_role_id);' ) ; $ oResult = $ oStatement -> execute ( array ( ":user_id" => $ iUserId , ":user_role_id" => 6 , ) ) ; if ( $ oResult !== true ) { throw new Exception ( "Error while creating admin user" ) ; } }
create the admin user
5,411
protected static function __getType ( $ param ) { $ type = is_object ( $ param ) ? get_class ( $ param ) : gettype ( $ param ) ; return $ type === 'integer' ? 'int' : $ type ; }
Get type OR class for params as well as re - mapping inconsistencies
5,412
protected static function __match ( array $ patterns ) { return function ( ... $ args ) use ( $ patterns ) { $ parameterTypes = array_map ( self :: getType ( ) , $ args ) ; try { $ keysToValues = Arrays :: zip ( array_keys ( $ patterns ) , array_values ( $ patterns ) ) ; list ( $ key , $ matchingPattern ) = Arrays :: first ( Pattern :: patternApplies ( $ parameterTypes , $ args ) , $ keysToValues ) ; } catch ( ElementNotFoundException $ e ) { throw new IncompletePatternMatchException ( 'Incomplete pattern match expression. (missing ' . implode ( ', ' , $ parameterTypes ) . ')' ) ; } list ( $ hasExtractable , $ unwrappedArgs ) = self :: unwrapArgs ( $ args ) ; $ value = $ matchingPattern ( ... $ args ) ; $ isCallable = is_callable ( $ value ) ; if ( $ hasExtractable && ! $ isCallable ) { throw new InvalidPatternMatchException ( 'Invalid pattern match expression. (one of ' . implode ( ', ' , $ parameterTypes ) . ' requires a callback to unwrap)' ) ; } if ( $ hasExtractable && $ isCallable ) { return $ matchingPattern ( ... $ args ) ( ... $ unwrappedArgs ) ; } return $ value ; } ; }
Pattern Matching . Use switch - case for explicit values this for everything else .
5,413
private static function unwrapArgs ( array $ args ) : array { $ hasExtractable = false ; $ unwrappedArgs = self :: flatten ( array_map ( function ( $ arg ) use ( & $ hasExtractable ) { if ( method_exists ( $ arg , 'extract' ) ) { $ hasExtractable = true ; return $ arg -> extract ( ) ; } return $ arg ; } , $ args ) ) ; return [ $ hasExtractable , $ unwrappedArgs ] ; }
Extracts args from Extractable values
5,414
function getMultiplayerPlayer ( $ titleId , $ login ) { if ( ! $ login ) { throw new Exception ( 'Invalid login' ) ; } return $ this -> execute ( 'GET' , $ this -> getPrefixEndpoint ( $ titleId ) . '/rankings/multiplayer/player/%s/?title=%s' , array ( $ login , $ titleId ) ) ; }
Get player ranking for the give title
5,415
public function withNumber ( $ number , $ variables = null ) { if ( ! is_null ( $ variables ) ) { $ vars = array ( ) ; foreach ( $ variables as $ k => $ v ) { $ vars [ ] = array ( 'key' => $ k , 'value' => $ v ) ; } $ this -> setArgument ( "variables" , $ vars ) ; } return $ this -> setArgument ( "number" , $ number ) ; }
Add or remove this number to the contact list .
5,416
private function detectManyToOne ( $ tables , $ modelTable ) { $ manyToOneRelations = [ ] ; $ foreignKeys = $ modelTable -> foreignKeys ; foreach ( $ foreignKeys as $ foreignKey ) { $ foreignTable = $ foreignKey -> foreignTable ; $ foreignField = $ foreignKey -> foreignField ; if ( ! isset ( $ tables [ $ foreignTable ] ) ) { continue ; } if ( $ foreignField == $ tables [ $ foreignTable ] -> primaryKey ) { $ modelName = model_name_from_table_name ( $ foreignTable ) ; $ manyToOneRelations [ ] = GeneratorFieldRelation :: parseRelation ( 'mt1,' . $ modelName ) ; } } return $ manyToOneRelations ; }
Detect many to one relationship on model table If foreign key of model table is primary key of foreign table .
5,417
public function __ ( $ key , $ params = array ( ) ) { $ namespace = explode ( "\\" , get_called_class ( ) ) ; $ class = strtolower ( 'model/' . str_replace ( '_' , '/' , array_pop ( $ namespace ) ) ) ; $ namespace = implode ( "\\" , $ namespace ) ; if ( $ namespace ) { $ class = $ namespace . '::' . $ class ; } return __ ( $ class . '.label.' . $ key , $ params ) ; }
Label translation helper
5,418
public function strict_assign ( array $ fields , array $ data ) { foreach ( $ fields as $ field ) { if ( isset ( $ data [ $ field ] ) ) { $ this -> __set ( $ field , $ data [ $ field ] ) ; } } }
Strict assign only sets some values out of an array . This can be useful to easly set some values from post .
5,419
protected function _type_assignment_set ( $ type , $ value ) { switch ( $ type ) { case 'int' : case 'timestamp' : return ( int ) $ value ; break ; case 'string' : return ( string ) $ value ; break ; case 'bool' : return ( bool ) $ value ; break ; case 'json' : return json_encode ( $ value ) ; break ; } return $ value ; }
Assign the data type in a set operation
5,420
protected function _type_assignment_get ( $ type , $ value ) { switch ( $ type ) { case 'int' : case 'timestamp' : return ( int ) $ value ; break ; case 'string' : return ( string ) $ value ; break ; case 'bool' : return ( bool ) $ value ; break ; case 'json' : if ( is_array ( $ value ) ) { return $ value ; } if ( is_array ( $ value = json_decode ( $ value , true ) ) ) { return $ value ; } return array ( ) ; break ; } return $ value ; }
Assign the data type in a get operation
5,421
public function & __get ( $ key ) { $ value = null ; $ has_modifier = method_exists ( $ this , '_get_modifier_' . $ key ) ; if ( array_key_exists ( $ key , $ this -> _data_store ) ) { $ value = & $ this -> _data_store [ $ key ] ; if ( $ has_modifier ) { $ tmpvalue = $ this -> { '_get_modifier_' . $ key } ( $ value ) ; return $ tmpvalue ; } return $ value ; } if ( $ has_modifier ) { $ value = $ this -> { '_get_modifier_' . $ key } ( ) ; return $ value ; } if ( method_exists ( $ this , $ key ) ) { $ value = $ this -> __call_property ( $ key ) ; return $ value ; } throw new \ InvalidArgumentException ( "CCModel - Invalid or undefined model property '" . $ key . "'." ) ; }
Get a value by key from the model data
5,422
public function __isset ( $ key ) { return ( array_key_exists ( $ key , $ this -> _data_store ) || method_exists ( $ this , '_get_modifier_' . $ key ) ) ? true : false ; }
Check if model data isset This also checks if a get modifier function exists which will also count as ture .
5,423
public function raw ( $ key = null ) { if ( ! is_null ( $ key ) ) { if ( isset ( $ this -> _data_store [ $ key ] ) ) { return $ this -> _data_store [ $ key ] ; } throw new \ InvalidArgumentException ( "CCModel - Invalid or undefined model property '" . $ key . "'." ) ; } return $ this -> _data_store ; }
Returns all raw data of the object or a single property
5,424
private function parseField ( string $ field ) : array { $ source = static :: DEFAULT_SOURCE ; $ type = static :: DEFAULT_TYPE ; $ origin = null ; if ( strpos ( $ field , '(' ) !== false ) { $ source = substr ( $ field , strpos ( $ field , '(' ) + 1 , - 1 ) ; $ field = substr ( $ field , 0 , strpos ( $ field , '(' ) ) ; if ( strpos ( $ source , ':' ) !== false ) { list ( $ source , $ origin ) = explode ( ':' , $ source ) ; } } if ( strpos ( $ field , ':' ) !== false ) { list ( $ field , $ type ) = explode ( ':' , $ field ) ; } return [ $ field , $ type , $ source , $ origin ] ; }
Parse field to fetch source origin and type .
5,425
protected function initialRedirectUrl ( ) { $ defaultUrl = '/' . $ this -> controller -> id . '/' . $ this -> controller -> defaultAction ; if ( isset ( $ this -> controller -> module -> id ) && ! $ this -> controller -> module instanceof Application ) { $ defaultUrl = '/' . $ this -> controller -> module -> id . $ defaultUrl ; } if ( empty ( $ this -> successUrl ) ) { $ this -> successUrl = $ defaultUrl ; } if ( empty ( $ this -> failedUrl ) ) { $ this -> failedUrl = $ defaultUrl ; } }
Set default redirect url
5,426
private function validate_config ( $ config ) { $ this -> section_names = array ( ) ; foreach ( $ config [ 'sections' ] as $ section ) { if ( in_array ( $ section -> title , $ this -> section_names ) ) { throw new DuplicateSectionException ( $ section -> title ) ; } foreach ( $ section -> get_fields ( ) as $ field ) { $ this -> fields [ ] = $ field ; } $ this -> section_names [ ] = $ section -> title ; } return $ config ; }
Validate the integrity of the provided configuration array
5,427
private function set_section_slugs ( ) { if ( count ( $ this -> sections ) > 1 ) { foreach ( $ this -> sections as $ section ) { $ section -> set_slug ( \ Amarkal \ Common \ Tools :: strtoslug ( $ section -> title ) ) ; } } else { $ this -> sections [ 0 ] -> set_slug ( \ Amarkal \ Common \ Tools :: strtoslug ( $ this -> title ) ) ; } }
Set slugs to each section according the number of sections .
5,428
public function toArray ( ) { return array ( 'site' => $ this -> site , 'type' => $ this -> type , 'storage_time' => $ this -> storage_time , 'credits' => $ this -> credits , 'soft_quota' => $ this -> soft_quota , 'hard_quota' => $ this -> hard_quota , 'daily_credits_usage' => $ this -> daily_credits_usage , 'unique_hashes' => $ this -> unique_hashes , ) ; }
returns status as array
5,429
public function add ( string $ type , string $ value ) : void { if ( $ this -> entry [ $ type ] === null ) { $ this -> entry [ $ type ] = array ( ) ; } $ this -> entry [ $ type ] = ( array ) $ this -> entry [ $ type ] ; $ this -> entry [ $ type ] [ ] = $ value ; }
add a value to an array type in the entry
5,430
public function addQuoted ( string $ type , string $ value ) : void { if ( $ value [ 0 ] == '"' ) { $ value = substr ( $ value , 1 , - 1 ) ; } $ value = stripcslashes ( $ value ) ; if ( $ this -> entry [ $ type ] === null ) { $ this -> entry [ $ type ] = array ( ) ; } $ this -> entry [ $ type ] = ( array ) $ this -> entry [ $ type ] ; $ this -> entry [ $ type ] [ ] = $ value ; }
add a quoted value to the array type in the entry
5,431
public function addQuotedAtPosition ( string $ type , int $ position , string $ value ) : void { if ( $ value [ 0 ] == '"' ) { $ value = substr ( $ value , 1 , - 1 ) ; } $ value = stripcslashes ( $ value ) ; if ( $ this -> entry [ $ type ] === null ) { $ this -> entry [ $ type ] = array ( ) ; } if ( isset ( $ this -> entry [ $ type ] [ $ position ] ) && is_scalar ( $ this -> entry [ $ type ] [ $ position ] ) ) { $ this -> entry [ $ type ] [ $ position ] = array ( $ this -> entry [ $ type ] [ $ position ] ) ; } $ this -> entry [ $ type ] [ $ position ] [ ] = $ value ; }
add a quoted value to the nested array type in the entry
5,432
public function getAsString ( string $ type ) : ? string { $ ret = $ this -> entry [ $ type ] ; if ( is_array ( $ ret ) ) { $ ret = implode ( '' , $ ret ) ; } return $ ret ; }
get the value of a specified type as a string
5,433
public function getAsStringArray ( string $ type ) : ? array { $ plurals = $ this -> entry [ $ type ] ; $ plurals = is_array ( $ plurals ) ? $ plurals : array ( '' , '' ) ; $ ret = array ( ) ; foreach ( $ plurals as $ i => $ value ) { if ( is_array ( $ value ) ) { $ value = implode ( '' , $ value ) ; } $ ret [ $ i ] = $ value ; } return $ ret ; }
Get the value of a specified type as an array of strings . This is mainly for plural TRANSLATED messages .
5,434
protected function formatQuotedString ( $ value , bool $ bare = false ) : string { if ( is_array ( $ value ) ) { $ string = '' ; foreach ( $ value as $ partial ) { $ string .= $ this -> formatQuotedString ( $ partial , true ) . "\n" ; } return $ bare ? $ string : ' ' . $ string ; } else { $ string = ( $ value === null ) ? '' : $ value ; $ string = stripcslashes ( $ string ) ; $ string = addcslashes ( $ string , "\0..\37\"" ) ; $ string = '"' . $ string . '"' ; return $ bare ? $ string : ' ' . $ string . "\n" ; } }
format a string for output by escaping control and double quote characters then surrounding with double quotes
5,435
public function hasFlag ( string $ name ) : bool { $ flags = array ( ) ; $ flagEntry = $ this -> entry [ PoTokens :: FLAG ] ; if ( ! empty ( $ flagEntry ) ) { foreach ( ( array ) $ flagEntry as $ csv ) { $ temp = str_getcsv ( $ csv , ',' ) ; foreach ( $ temp as $ flag ) { $ flag = strtolower ( trim ( $ flag ) ) ; $ flags [ $ flag ] = $ flag ; } } return isset ( $ flags [ strtolower ( trim ( $ name ) ) ] ) ; } return false ; }
check for presence of a flag
5,436
public function addFlag ( string $ name ) : void { if ( ! $ this -> hasFlag ( $ name ) ) { $ flagEntry = $ this -> entry [ PoTokens :: FLAG ] ; if ( $ flagEntry === null ) { $ this -> set ( PoTokens :: FLAG , $ name ) ; } elseif ( is_array ( $ flagEntry ) ) { $ flagEntry [ ] = $ name ; $ this -> set ( PoTokens :: FLAG , implode ( ',' , $ flagEntry ) ) ; } else { $ this -> set ( PoTokens :: FLAG , $ flagEntry . ',' . $ name ) ; } } }
add a flag to the entry
5,437
public function getProvider ( $ key ) { if ( ! $ this -> hasProvider ( $ key ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Location Provider with key "%s" does not exist' , $ key ) ) ; } return $ this -> providers [ $ key ] ; }
Get specified provider
5,438
public function setOption ( $ option , $ value ) { $ this -> options [ $ option ] = $ value ; $ this -> resolve ( $ this -> options ) ; }
Set or modify an option after the object has been initialized
5,439
private function createEditForm ( License $ oLicense ) { $ oForm = $ this -> createForm ( new LicenseType ( ) , $ oLicense , array ( 'action' => $ this -> generateUrl ( 'license_update' , array ( 'id' => $ oLicense -> getId ( ) ) ) , 'method' => 'PUT' , ) ) ; $ oForm -> add ( 'submit' , 'submit' , array ( 'label' => 'Update' ) ) ; return $ oForm ; }
Create edit form for lucense
5,440
private function publishContentObjects ( TreeObject $ object ) { $ last = $ this -> objectService -> createOrUpdate ( $ object -> data ) ; foreach ( $ object -> getNodes ( ) as $ subObject ) { if ( $ subObject instanceof TreeObject ) { $ this -> publishContentObjects ( $ subObject ) ; } else { $ subObject -> addParentLocation ( $ last -> getProperty ( 'content_info' ) -> mainLocationId ) ; $ this -> objectService -> createOrUpdate ( $ subObject ) ; } } }
Publishes content objects .
5,441
public function remove ( $ object ) { if ( $ this -> logger ) { $ this -> logger -> warning ( sprintf ( 'Attempted to delete using %s, which is not supported. Use the implementations of %s instead.' , __CLASS__ , EzPlatformObject :: class ) ) ; } return ; }
Bulk - deletions is not supported .
5,442
public function attach ( Threaded $ object , $ data = null ) { $ this -> data [ ] = $ object ; $ this -> info [ ] = $ data ; }
Adds an object in the storage
5,443
public function addAll ( self $ storage ) { foreach ( $ storage -> data as $ object ) { $ this -> attach ( $ object ) ; } }
Adds all objects from another storage
5,444
public function removeAll ( self $ storage ) { foreach ( $ this -> data as $ key => $ value ) { foreach ( $ storage -> data as $ object ) { if ( $ object === $ value ) { unset ( $ this -> data [ $ key ] ) ; unset ( $ this -> info [ $ key ] ) ; } } } }
Removes objects contained in another storage from the current storage
5,445
public function getInfo ( Threaded $ object ) { foreach ( $ this -> data as $ key => $ value ) { if ( $ object === $ value ) { return $ this -> info [ $ key ] ; } } }
Returns the data associated with the current iterator entry
5,446
public function setInfo ( Threaded $ object , $ data ) { foreach ( $ this -> data as $ key => $ value ) { if ( $ object -> equals ( $ value ) ) { $ this -> info [ $ key ] = $ data ; break ; } } }
Sets the data associated with the current iterator entry
5,447
public function toXLIFF ( $ pretty_print = FALSE ) { $ this -> doc -> formatOutput = $ pretty_print ; $ xpath = new \ DOMXPath ( $ this -> doc ) ; $ wrapper_div = $ xpath -> query ( "//*[@id='eggs-n-cereal-dont-ever-use-this-id']" ) -> item ( 0 ) ; $ out = $ this -> doc -> createDocumentFragment ( ) ; $ domNodeList = array ( ) ; for ( $ i = 0 ; $ i < $ wrapper_div -> childNodes -> length ; ++ $ i ) { $ domNodeList [ ] = $ wrapper_div -> childNodes -> item ( $ i ) ; } $ this -> sanitizeMixedDomNodeList ( $ this -> doc , $ domNodeList ) ; foreach ( $ domNodeList as $ domNode ) { if ( $ output = $ this -> convert ( $ domNode ) ) { $ out -> appendChild ( $ output ) ; } } return $ this -> doc -> saveXML ( $ out ) ; }
Converts HTML to the corresponding XLIFF representation .
5,448
protected function sanitize ( ) { $ sanitized = sanitizer ( ) -> make ( $ this -> all ( ) , $ this -> sanitizerRules ( ) ) ; $ this -> replace ( $ sanitized ) ; }
Sanitize this request s input .
5,449
private function parseNameFromKeyDefinition ( $ strKeyDefinition ) { $ strKeyDefinition = trim ( $ strKeyDefinition ) ; $ intPosition = strpos ( $ strKeyDefinition , '(' ) ; if ( $ intPosition === false ) { throw new \ Exception ( "Invalid Key Definition: $strKeyDefinition" ) ; } else { if ( $ intPosition == 0 ) { return null ; } } $ strName = trim ( substr ( $ strKeyDefinition , 0 , $ intPosition ) ) ; if ( substr ( $ strName , 0 , 1 ) == '`' ) { return substr ( $ strName , 1 , strlen ( $ strName ) - 2 ) ; } else { return $ strName ; } }
If the key name exists this will parse it out and return it
5,450
public function getFiles ( Array $ criteria = array ( ) , Array $ orderBy = NULL ) { $ files = new \ Psc \ Data \ ArrayCollection ( $ this -> manager -> getRepository ( ) -> findBy ( $ criteria , $ orderBy ) ) ; foreach ( $ files as $ file ) { $ this -> manager -> attach ( $ file ) ; } return $ files ; }
Returns a list of all uploaded files
5,451
public function getViewFile ( $ name ) { list ( $ plugin , $ name ) = $ this -> pluginSplit ( $ name ) ; $ return = null ; foreach ( $ this -> _paths ( $ plugin ) as $ path ) { $ viewFile = FS :: clean ( $ path . $ name . $ this -> _ext ) ; if ( FS :: isFile ( $ viewFile ) ) { $ return = $ this -> _checkFilePath ( $ viewFile , $ path ) ; break ; } } return $ return ; }
Get view file path .
5,452
public function partial ( $ name , array $ data = [ ] ) { $ file = $ this -> _getLayoutPartialPath ( $ name ) ; if ( FS :: isFile ( $ file ) ) { return $ this -> _render ( $ file , $ data ) ; } return null ; }
Render layout partial .
5,453
protected function _findViewByRequest ( ) { $ paths = App :: path ( 'Template' , $ this -> plugin ) ; $ action = ( string ) $ this -> request -> getParam ( 'action' ) ; $ controller = $ this -> request -> getParam ( 'controller' ) ; $ viewFile = $ action . $ this -> _ext ; $ viewSubPath = $ this -> _getSubPaths ( $ controller ) ; foreach ( $ paths as $ path ) { foreach ( $ viewSubPath as $ subPath ) { $ full = $ path . $ subPath . DS . $ viewFile ; if ( FS :: isFile ( $ full ) ) { return $ action ; } $ formView = $ path . $ subPath . DS . self :: VIEW_FORM . $ this -> _ext ; if ( FS :: isFile ( $ formView ) ) { return self :: VIEW_FORM ; } } } return null ; }
Find form view by request .
5,454
protected function _getFormView ( $ view = null ) { if ( empty ( $ view ) && Arr :: in ( $ this -> request -> getParam ( 'action' ) , $ this -> _formActions ) ) { $ view = $ this -> _findViewByRequest ( ) ; } return $ view ; }
Get current form view .
5,455
protected function _getLayoutPartialPath ( $ name ) { list ( $ plugin , $ name ) = $ this -> pluginSplit ( $ name ) ; $ paths = $ this -> _paths ( $ plugin ) ; $ layoutPaths = $ this -> _getSubPaths ( 'Layout' . DS . 'Partial' ) ; foreach ( $ paths as $ path ) { foreach ( $ layoutPaths as $ layoutPath ) { $ partial = $ path . $ layoutPath . DS . $ name . $ this -> _ext ; if ( FS :: isFile ( $ partial ) ) { return $ partial ; } } } return false ; }
Finds an partial filename returns false on failure .
5,456
public static function deleteDirectoryContents ( string $ directoryPath ) { $ paths = scandir ( $ directoryPath ) ; if ( $ paths === false ) { throw new \ Exception ( "cannot list directory '{$directoryPath}'" ) ; } foreach ( $ paths as $ path ) { if ( $ path === '.' || $ path === '..' ) { continue ; } $ fullPath = "{$directoryPath}/{$path}" ; if ( is_dir ( $ fullPath ) ) { self :: deleteDirectoryContents ( $ fullPath ) ; self :: throwIfFalse ( rmdir ( $ fullPath ) , "cannot delete '{$fullPath}'" , 1 ) ; continue ; } self :: throwIfFalse ( unlink ( $ fullPath ) , "cannot delete '{$fullPath}'" , 2 ) ; } }
Recursively deletes directory contents
5,457
public function getCsvfile ( $ key ) { if ( array_key_exists ( $ key , $ this -> csv ) ) { return $ this -> csv [ $ key ] ; } return false ; }
Get the CSV file details for data source or false on failure
5,458
public function setCsvOptions ( $ charSet = 'utf-8' , $ delimField = "," , $ delimNewLine = "\n" , array $ columnHeaderNames = [ ] ) { $ this -> csv [ 'charSet' ] = $ charSet ; $ this -> csv [ 'delimField' ] = $ delimField ; $ this -> csv [ 'delimNewLine' ] = $ delimNewLine ; $ this -> csv [ 'columnHeaderNames' ] = $ columnHeaderNames ; return $ this ; }
Set the CSV file details for data source
5,459
public function offsetSet ( $ id , $ value ) { if ( $ this -> locked ) { throw new BadMethodCallException ( 'Setting values into a locked container is not allowed' ) ; } if ( $ value instanceof JuiceParam ) { $ this -> values [ $ id ] = $ value -> value ; return ; } if ( is_callable ( $ value ) || $ value instanceof JuiceDefinition ) { $ this -> definitions [ $ id ] = $ value ; return ; } if ( is_string ( $ value ) && '@' == $ value [ 0 ] ) { $ this -> aliases [ $ id ] = substr ( $ value , 1 ) ; return ; } $ this -> values [ $ id ] = $ value ; }
Sets a parameter or a definition
5,460
private function getServiceOrParameter ( $ id ) { if ( array_key_exists ( $ id , $ this -> aliases ) ) { return $ this -> offsetGet ( $ this -> aliases [ $ id ] ) ; } if ( array_key_exists ( $ id , $ this -> values ) ) { return $ this -> values [ $ id ] ; } if ( array_key_exists ( $ id , $ this -> definitions ) ) { return $ this -> values [ $ id ] = $ this -> build ( $ this -> definitions [ $ id ] ) ; } throw new InvalidArgumentException ( sprintf ( 'Identifier "%s" is not defined.' , $ id ) ) ; }
Return the service associated with this unique identifier
5,461
public function build ( $ definition ) { if ( is_callable ( $ definition ) ) { return call_user_func ( $ definition , $ this ) ; } return $ this -> buildFromDefinition ( $ definition ) ; }
Build a definition and return the instantiated object
5,462
protected function resolveValue ( $ value ) { if ( is_array ( $ value ) ) { foreach ( $ value as $ index => $ val ) { $ value [ $ index ] = $ this -> resolveValue ( $ val ) ; } return $ value ; } if ( is_string ( $ value ) && '@' == $ value [ 0 ] ) { return $ this -> offsetGet ( substr ( $ value , 1 ) ) ; } return $ value ; }
Finds and marks references ( strings beginning with an
5,463
private function getAssociatedLogLevel ( $ errno ) { $ associations = [ E_WARNING => LogLevel :: WARNING , E_NOTICE => LogLevel :: NOTICE , E_USER_ERROR => LogLevel :: ERROR , E_USER_WARNING => LogLevel :: WARNING , E_USER_NOTICE => LogLevel :: NOTICE , E_STRICT => LogLevel :: NOTICE , E_RECOVERABLE_ERROR => LogLevel :: ERROR , E_DEPRECATED => LogLevel :: NOTICE , E_USER_DEPRECATED => LogLevel :: NOTICE , ] ; if ( isset ( $ associations [ $ errno ] ) ) { return $ associations [ $ errno ] ; } return LogLevel :: CRITICAL ; }
Getting the log level constant associated with error code .
5,464
public function isCanSearch ( Item $ item , $ field ) { if ( ! in_array ( $ field , $ this -> supported_fields ) ) { return false ; } if ( $ this -> isCanRefill ( $ item , $ field ) || $ item -> getName ( ) ) { return true ; } foreach ( $ item -> getNames ( ) as $ name ) { if ( $ name -> getName ( ) ) { return true ; } } return false ; }
Is can search .
5,465
public function search ( Item $ item , $ field ) { if ( $ url = $ this -> getSourceForFill ( $ item ) ) { return [ new ItemRefiller ( $ item -> getName ( ) , [ 'url' => $ url ] , $ url , $ item -> getCover ( ) , $ item -> getSummary ( ) ) , ] ; } if ( ! ( $ name = $ item -> getName ( ) ) ) { foreach ( $ item -> getNames ( ) as $ name ) { if ( $ name ) { break ; } } } $ result = [ ] ; if ( $ name ) { $ result = $ this -> search -> search ( [ 'name' => $ name ] ) ; foreach ( $ result as $ key => $ item ) { parse_str ( parse_url ( $ item -> getLink ( ) , PHP_URL_QUERY ) , $ query ) ; $ link = array_values ( $ query ) [ 0 ] [ 'url' ] ; $ result [ $ key ] = new ItemRefiller ( $ item -> getName ( ) , [ 'url' => $ link ] , $ link , $ item -> getImage ( ) , $ item -> getDescription ( ) ) ; } } return $ result ; }
Search items for refill .
5,466
protected function fillItem ( Item $ item , Item $ new_item , $ field ) { switch ( $ field ) { case self :: FIELD_COUNTRY : $ item -> setCountry ( $ new_item -> getCountry ( ) ) ; break ; case self :: FIELD_DATE_END : $ item -> setDateEnd ( $ new_item -> getDateEnd ( ) ) ; break ; case self :: FIELD_DATE_PREMIERE : $ item -> setDatePremiere ( $ new_item -> getDatePremiere ( ) ) ; break ; case self :: FIELD_DURATION : $ item -> setDuration ( $ new_item -> getDuration ( ) ) ; break ; case self :: FIELD_EPISODES : $ item -> setEpisodes ( $ new_item -> getEpisodes ( ) ) ; break ; case self :: FIELD_EPISODES_NUMBER : $ item -> setEpisodesNumber ( $ new_item -> getEpisodesNumber ( ) ) ; break ; case self :: FIELD_FILE_INFO : $ item -> setFileInfo ( $ new_item -> getFileInfo ( ) ) ; break ; case self :: FIELD_GENRES : foreach ( $ new_item -> getGenres ( ) as $ new_genre ) { $ item -> addGenre ( $ new_genre ) ; } break ; case self :: FIELD_NAMES : $ new_names = $ new_item -> getNames ( ) -> toArray ( ) ; array_unshift ( $ new_names , ( new Name ( ) ) -> setName ( $ new_item -> getName ( ) ) ) ; foreach ( $ new_names as $ new_name ) { $ item -> addName ( $ new_name ) ; } break ; case self :: FIELD_SOURCES : foreach ( $ new_item -> getSources ( ) as $ new_source ) { $ item -> addSource ( $ new_source ) ; } break ; case self :: FIELD_STUDIO : $ item -> setStudio ( $ new_item -> getStudio ( ) ) ; break ; case self :: FIELD_SUMMARY : $ item -> setSummary ( $ new_item -> getSummary ( ) ) ; break ; } return $ item ; }
Fill item .
5,467
protected function setDefaultRule ( ) { if ( RBACHelper :: getAuthManager ( ) -> getRule ( RouteRule :: RULE_NAME ) === null ) { RBACHelper :: getAuthManager ( ) -> add ( new RouteRule ( ) ) ; } }
Set default rule of parametrize route .
5,468
public function getJobType ( ) { $ sourceObject = ExternalContent :: getDataObjectFor ( $ this -> sourceObjectID ) ; if ( ! $ sourceObject ) { $ this -> addMessage ( "ERROR: Source object $this->sourceObjectID cannot be found" ) ; return QueuedJob :: QUEUED ; } if ( ! $ this -> includeChildren ) { return QueuedJob :: QUEUED ; } $ children = $ sourceObject -> stageChildren ( ) ; if ( ! $ children ) { return QueuedJob :: QUEUED ; } $ count = 1 ; foreach ( $ children as $ child ) { $ count ++ ; if ( $ count > 20 ) { $ this -> totalSteps = $ count ; return QueuedJob :: QUEUED ; } $ subChildren = $ child -> stageChildren ( ) ; if ( $ subChildren ) { foreach ( $ subChildren as $ sub ) { $ count ++ ; if ( $ count > 20 ) { $ this -> totalSteps = $ count ; return QueuedJob :: QUEUED ; } } } } $ this -> totalSteps = $ count ; return QueuedJob :: QUEUED ; }
By default jobs should just go into the default processing queue
5,469
public function process ( ) { $ remainingChildren = $ this -> remainingChildren ; if ( ! count ( $ remainingChildren ) ) { $ this -> isComplete = true ; return ; } $ this -> currentStep ++ ; $ pair = array_shift ( $ remainingChildren ) ; $ sourceObject = ExternalContent :: getDataObjectFor ( $ pair -> sourceID ) ; if ( ! $ sourceObject ) { $ this -> addMessage ( "Missing source object for " . $ pair -> sourceID , 'WARNING' ) ; $ this -> remainingChildren = $ remainingChildren ; return ; } $ targetObject = DataObject :: get_by_id ( $ pair -> targetType , $ pair -> targetID ) ; if ( ! $ targetObject ) { $ this -> addMessage ( "Missing target object for $pair->targetType $pair->sourceID" , 'WARNING' ) ; $ this -> remainingChildren = $ remainingChildren ; return ; } $ pageType = $ this -> getExternalType ( $ sourceObject ) ; if ( isset ( $ this -> contentTransforms [ $ pageType ] ) ) { $ transformer = $ this -> contentTransforms [ $ pageType ] ; $ result = $ transformer -> transform ( $ sourceObject , $ targetObject , $ this -> duplicateStrategy ) ; if ( $ this -> includeChildren && $ result && $ result -> children && count ( $ result -> children ) ) { foreach ( $ result -> children as $ child ) { $ remainingChildren [ ] = new EC_SourceTarget ( $ child -> ID , $ result -> page -> ID , $ result -> page -> ClassName ) ; $ this -> totalSteps ++ ; } } } $ this -> remainingChildren = $ remainingChildren ; if ( ! count ( $ remainingChildren ) ) { $ this -> isComplete = true ; return ; } }
Lets process a single node and collect its children
5,470
protected function _migrateFile ( $ version , $ filePath , $ direction = 'up' ) { $ classVersion = preg_replace ( '/[^0-9A-Za-z]/' , '' , $ version ) ; $ className = 'Migration_' . $ classVersion ; if ( file_exists ( $ filePath ) ) { require_once $ filePath ; if ( class_exists ( $ className ) ) { $ migration = new $ className ( $ this -> config , $ version ) ; if ( $ direction === 'up' ) { $ migration -> up ( ) ; if ( method_exists ( $ migration , 'afterUp' ) ) { $ migration -> afterUp ( ) ; } print PHP_EOL . Color :: success ( 'Upgrade Version ' . $ version . ' was successfully migrated' ) . PHP_EOL ; } elseif ( $ direction === 'down' ) { $ migration -> down ( ) ; if ( method_exists ( $ migration , 'afterDown' ) ) { $ migration -> afterDown ( ) ; } print PHP_EOL . Color :: info ( 'Downgrade Version ' . $ version . ' was successfully migrated' ) . PHP_EOL ; } } } else { throw new CommandsException ( 'Migration class cannot be found ' . $ className . ' at ' . $ filePath ) ; } }
Migrate Single File Up or Down
5,471
public function generate ( ) { $ version = date ( 'YmdHis' ) ; $ this -> _generateMigrationFile ( $ version ) ; print PHP_EOL . Color :: success ( 'Version ' . $ version . ' was successfully generated' ) . PHP_EOL ; }
Generate Empty Migration file
5,472
protected function _generateMigrationFile ( $ version , $ contentUp = "" , $ contentDown = "" ) { $ classVersion = preg_replace ( '/[^0-9A-Za-z]/' , '' , $ version ) ; $ className = 'Migration_' . $ classVersion ; $ classData = "<?phpuse Phalcon\Migrations\MigrationScript as Migration;class " . $ className . " extends Migration\n" . "{\n\n" . "\tpublic function up()\n" . "\t{\n" . $ contentUp . "\n\t}" . "\n\n" . "\tpublic function down()\n" . "\t{\n" . $ contentDown . "\n\t}" . "\n}\n" ; $ classData = str_replace ( "\t" , " " , $ classData ) ; file_put_contents ( $ this -> migrationsDir . '/' . $ version . '.php' , $ classData ) ; return $ classData ; }
Generate Migration file
5,473
protected function getVerifyCredentialsCallback ( ) { if ( is_null ( $ this -> callback ) || ! is_callable ( $ this -> callback ) ) { throw new Exception \ ServerErrorException ( 'Null or non-callable callback set on Password grant' ) ; } return $ this -> callback ; }
Return the callback function
5,474
public function getAccessToken ( ) { if ( ! $ this -> accessTokenEntity instanceof AccessTokenEntity ) { $ this -> accessTokenEntity = $ this -> server -> getAccessTokenStorage ( ) -> get ( $ this -> accessTokenId ) ; } return $ this -> accessTokenEntity ; }
Return access token
5,475
public static function setDefaultTranslator ( $ translator = null ) { if ( ( null === $ translator ) || ( $ translator instanceof Zend_Translate_Adapter ) ) { self :: $ _defaultTranslator = $ translator ; } elseif ( $ translator instanceof Zend_Translate ) { self :: $ _defaultTranslator = $ translator -> getAdapter ( ) ; } else { require_once 'Zend/Validate/Exception.php' ; throw new Zend_Validate_Exception ( 'Invalid translator specified' ) ; } }
Set default translation object for all validate objects
5,476
public static function getDefaultTranslator ( ) { if ( null === self :: $ _defaultTranslator ) { require_once 'Zend/Registry.php' ; if ( Zend_Registry :: isRegistered ( 'Zend_Translate' ) ) { $ translator = Zend_Registry :: get ( 'Zend_Translate' ) ; if ( $ translator instanceof Zend_Translate_Adapter ) { return $ translator ; } elseif ( $ translator instanceof Zend_Translate ) { return $ translator -> getAdapter ( ) ; } } } return self :: $ _defaultTranslator ; }
Get default translation object for all validate objects
5,477
public function build_alert ( $ alerts ) { return HTML :: tag ( 'div' , function ( ) use ( $ alerts ) { foreach ( $ alerts as $ type => $ items ) { foreach ( $ items as $ alert ) { $ alert = implode ( "<br>\n" , $ alert ) ; $ close = HTML :: tag ( 'button' , '&times;' ) -> add_class ( 'close' ) -> type ( 'button' ) -> data ( 'dismiss' , 'alert' ) ; echo HTML :: tag ( 'div' , $ close . $ alert ) -> add_class ( 'alert fade in' ) -> add_class ( 'alert-' . $ type ) ; } } } ) -> add_class ( 'ui-alert-container' ) ; }
Build the UI alerts
5,478
public function setCurrentDriver ( string $ name ) : ITaxFacade { $ this -> currentDriverName = $ name ; $ this -> makeCurrentDriver ( $ name ) ; return $ this ; }
Set current driver
5,479
public function driverInstance ( string $ driver ) : ? ITaxFacade { if ( ( $ driverClass = $ this -> getDriver ( $ driver ) ) !== null ) { return app ( $ driverClass , [ 'config' => config ( 'taxes.' . $ driverClass ) , ] ) ; } return null ; }
Build driver by name
5,480
public function setMagicFile ( $ file ) { if ( empty ( $ file ) ) { $ this -> _magicfile = null ; } else if ( ! is_readable ( $ file ) ) { require_once 'Zend/Validate/Exception.php' ; throw new Zend_Validate_Exception ( 'The given magicfile can not be read' ) ; } else { $ this -> _magicfile = ( string ) $ file ; } return $ this ; }
Sets the magicfile to use if null the MAGIC constant from php is used
5,481
public function getScriptText ( $ parameters = null ) { if ( ! $ parameters ) { $ parameters = $ this -> parameters ; } ob_start ( ) ; include $ this -> filePath ; $ scriptText = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ scriptText ; }
Get the compiled script text
5,482
protected function decorateResults ( Coordinates $ searchCenter , array $ results ) { $ search = new Search ( ) ; $ search -> setCenter ( $ searchCenter ) ; foreach ( $ results as $ result ) { $ distanceInMiles = UnitConverter :: kmToMiles ( $ result [ 'distance' ] ) ; $ search -> addResult ( new Result ( $ result [ 0 ] , $ distanceInMiles ) ) ; } return $ search ; }
Helper method to decorate search results
5,483
protected static function _clear ( $ menu ) { if ( array_key_exists ( $ menu , self :: $ _items ) ) { self :: $ _items [ $ menu ] = [ ] ; } else { throw new \ UnexpectedValueException ( 'Invalid menu: ' . $ menu ) ; } }
Clear menu items .
5,484
protected static function _replace ( & $ target , $ path , $ options ) { $ pathE = explode ( '.' , $ path ) ; $ path = array_shift ( $ pathE ) ; $ fragment = join ( '.' , $ pathE ) ; if ( ! empty ( $ pathE ) ) { self :: _replace ( $ target [ $ path ] , $ fragment , $ options ) ; } else { $ target [ $ path ] = self :: _merge ( $ target [ $ path ] , $ options ) ; } }
Replace a menu element .
5,485
protected static function _setupOptions ( & $ options ) { $ options = self :: _merge ( self :: $ _defaults , $ options ) ; foreach ( $ options [ 'children' ] as & $ child ) { self :: _setupOptions ( $ child ) ; } }
Setup options .
5,486
public static function write ( $ str , $ color = null , $ background = null ) { if ( ! is_null ( $ color ) ) { $ str = static :: color ( $ str , $ color , $ background ) ; } fwrite ( STDOUT , $ str ) ; }
Write to the standard output device
5,487
public static function line ( $ str , $ color = null , $ background = null ) { if ( is_array ( $ str ) ) { $ str = implode ( PHP_EOL , $ str ) ; } static :: write ( $ str . PHP_EOL , $ color , $ background ) ; }
Write to the standard output device with an end of line .
5,488
public static function confirm ( $ question , $ strict = false ) { $ question .= ' [yes/no]: ' ; if ( $ strict ) { do { $ res = strtolower ( static :: read ( $ question ) ) ; } while ( $ res !== 'yes' && $ res !== 'no' ) ; return ( $ res == 'yes' ) ? true : false ; } do { $ res = strtolower ( static :: read ( $ question ) ) ; } while ( empty ( $ res ) ) ; $ positives = array ( 'yes' , 'y' , 'ya' , 'ye' , 'yeah' , 'yup' , 'jep' , 'jap' , 'ja' , 'si' , 'sim' , 'true' , 'hai' , 'oui' , 'no problemo' , ) ; return in_array ( $ res , $ positives ) ; }
Get a bool value from the user This will write the question down and waiting for a yes or no .
5,489
public static function read ( $ prefix = '' ) { if ( ! static :: is_windows ( ) ) { $ line = readline ( $ prefix ) ; readline_add_history ( $ line ) ; } else { static :: write ( $ prefix ) ; $ line = trim ( fgets ( STDIN ) ) ; } return $ line ; }
Read from comman line Because windows does not support readline we use normal fgets in that case .
5,490
protected function manageEdit ( $ entity , Request $ request , $ formTypeFQCN ) { $ form = $ this -> createForm ( $ formTypeFQCN , $ entity , array ( 'action' => $ this -> getEditUrl ( $ entity ) , 'method' => 'POST' , ) ) ; $ form -> add ( 'save' , SubmitType :: class , array ( 'attr' => array ( 'class' => 'btn btn-primary' ) ) ) -> add ( 'delete' , SubmitType :: class , array ( 'attr' => array ( 'class' => 'btn btn-danger' ) ) ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) ) { if ( $ form -> get ( 'save' ) -> isClicked ( ) ) { if ( $ form -> isValid ( ) ) { return $ this -> crudManage ( $ entity , AdminCrudEvent :: UPDATE ) ; } } elseif ( $ form -> get ( 'delete' ) -> isClicked ( ) ) { return $ this -> crudManage ( $ entity , AdminCrudEvent :: DELETE ) ; } } return $ this -> render ( $ this -> getEditTemplate ( ) , array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , ) ) ; }
Generic edit controller helper .
5,491
protected function manageNew ( $ entity , Request $ request , $ formTypeFQCN ) { $ form = $ this -> createForm ( $ formTypeFQCN , $ entity , array ( 'action' => $ this -> getNewUrl ( $ entity ) , 'method' => 'POST' , ) ) ; $ form -> add ( 'create' , submitType :: class , array ( 'attr' => array ( 'class' => 'btn btn-primary' ) ) ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { return $ this -> crudManage ( $ entity , AdminCrudEvent :: CREATE ) ; } return $ this -> render ( $ this -> getNewTemplate ( ) , array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , ) ) ; }
Generic new controller helper .
5,492
protected function dispatchCrudEvent ( $ entity , $ action , $ eventName ) { $ event = new AdminCrudEvent ( $ entity , $ action , $ this -> getUser ( ) ) ; $ this -> get ( 'event_dispatcher' ) -> dispatch ( $ eventName , $ event ) ; return $ event ; }
Generic Event dispatcher .
5,493
protected function dispatchAssociationActionEvent ( $ entity , $ action , $ target , $ eventName ) { $ event = new AdminAssociationActionEvent ( $ entity , $ action , $ target , $ this -> getUser ( ) ) ; $ this -> get ( 'event_dispatcher' ) -> dispatch ( $ eventName , $ event ) ; return $ event ; }
Generic Association Action dispatcher .
5,494
public static function charAt ( string $ str , int $ i ) : string { return ( string ) BaseStringy :: create ( $ str ) -> at ( $ i ) ; }
Returns the character at a specific point in a potentially multibyte string .
5,495
public static function lines ( string $ str ) : array { $ lines = BaseStringy :: create ( $ str ) -> lines ( ) ; foreach ( $ lines as $ i => $ line ) { $ lines [ $ i ] = $ line ; } return $ lines ; }
Splits on newlines and carriage returns returning an array of strings corresponding to the lines in the string .
5,496
public static function toKebabCase ( string $ string , string $ glue = '-' , bool $ lower = true , bool $ removePunctuation = true ) : string { $ words = self :: _prepStringForCasing ( $ string , $ lower , $ removePunctuation ) ; return implode ( $ glue , $ words ) ; }
kebab - cases a string .
5,497
public static function toCamelCase ( string $ string ) : string { $ words = self :: _prepStringForCasing ( $ string ) ; if ( empty ( $ words ) ) { return '' ; } $ string = array_shift ( $ words ) . implode ( '' , array_map ( [ static :: class , 'upperCaseFirst' ] , $ words ) ) ; return $ string ; }
camelCases a string .
5,498
public static function toPascalCase ( string $ string ) : string { $ words = self :: _prepStringForCasing ( $ string ) ; $ string = implode ( '' , array_map ( [ static :: class , 'upperCaseFirst' ] , $ words ) ) ; return $ string ; }
PascalCases a string .
5,499
public static function toSnakeCase ( string $ string ) : string { $ words = self :: _prepStringForCasing ( $ string ) ; return implode ( '_' , $ words ) ; }
snake_cases a string .