idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
11,200
private function merge ( ServerRequestInterface $ request , array $ data ) { $ existing = $ request -> getAttribute ( 'viewData' , [ ] ) ; return array_merge ( $ existing , $ data ) ; }
Merges any existing view data in the request with the provided one
11,201
private function responseFrom ( ControllerContextInterface $ context ) { $ response = $ context -> response ( ) ; if ( ! $ response instanceof ResponseInterface ) { throw new MissingResponseException ( "Missing response object after handle the request. If you disabled rendering you need to " . "provide an HTTP response...
Verify and return the response from the context
11,202
public function update ( $ newValues ) { foreach ( $ newValues as $ key => $ value ) { $ this -> offsetSet ( $ key , $ value ) ; } return $ this ; }
Update the dictionary with new values .
11,203
public function without ( $ key ) { $ keys = func_num_args ( ) > 1 ? func_get_args ( ) : ( array ) $ key ; $ copy = $ this -> copy ( ) ; foreach ( $ keys as $ key ) { $ copy -> offsetUnset ( $ key ) ; } return $ copy ; }
Returns a new Dictionary object without the key key .
11,204
public static function fromKeys ( $ keys ) { $ hash = new static ( ) ; foreach ( $ keys as $ key ) { $ hash [ $ key ] = null ; } return $ hash ; }
Constructs a Hash with the passed keys .
11,205
protected function renderAsset ( Asset $ asset , $ group ) { return $ asset -> isInline ( ) ? $ this -> renderInline ( $ asset , $ group ) : $ this -> renderExternal ( $ asset , $ group ) ; }
Renders one asset .
11,206
protected function renderExternal ( Asset $ asset , $ group ) { return '<!-- asset external' . $ this -> renderAttributes ( [ 'href' => $ asset -> uri ( ) ] , $ asset -> attributes ( ) ) . ' ; }
Renders an external asset .
11,207
public static function fromRaw ( array $ raw ) { $ last = $ raw [ count ( $ raw ) - 2 ] ; if ( strncmp ( $ last , 'ACK' , 3 ) === 0 ) { return self :: produceFailResponse ( $ last ) ; } array_pop ( $ raw ) ; array_pop ( $ raw ) ; return new self ( $ raw ) ; }
Create response from raw one
11,208
public function suggest ( ) { if ( strip_tags ( $ this -> value ) != $ this -> value ) { return self :: EDITOR ; } if ( strlen ( $ this -> value ) < 50 ) { return self :: TEXT ; } return self :: TEXTAREA ; }
Get suggestions for a type of value
11,209
private function do_request ( $ verb , $ path , $ data = Array ( ) , $ timeout = 10 ) { return $ this -> use_sockets ? $ this -> do_request_with_sockets ( $ verb , $ path , $ data , $ timeout ) : $ this -> do_request_with_curl ( $ verb , $ path , $ data , $ timeout ) ; }
Do actual HTTP requests in here absctract from the rest of phpDefensio so we can easily change the library or technique used as of now it uses a simple sockets implementation and might throw an exception if no socket can be open
11,210
public function run ( $ language , CompileOptions $ options ) { $ namespaces = $ options -> getNamespaces ( ) ; if ( ! $ namespaces || count ( $ namespaces ) === 0 ) { throw new \ InvalidArgumentException ( 'Missing "namespaces" options.' ) ; } if ( ! is_array ( $ namespaces ) ) { $ namespaces = [ $ namespaces ] ; } fo...
Generates and writes files for each schema .
11,211
public function lock ( ) { if ( ! $ this -> beforeLock ( ) ) { return false ; } $ redis = $ this -> getConnection ( ) -> getClient ( ) ; if ( ! $ redis -> setnx ( $ this -> name , $ this -> getExpiresAt ( true ) ) ) { $ value = $ redis -> get ( $ this -> name ) ; if ( $ value > microtime ( true ) ) { return false ; } }...
Attempts to lock the mutex returns true if successful or false if the mutex is locked by another process .
11,212
public function unlock ( ) { if ( ! $ this -> beforeUnlock ( ) ) { return false ; } $ redis = $ this -> getConnection ( ) -> getClient ( ) ; $ value = $ redis -> get ( $ this -> name ) ; $ decimalPlaces = max ( strlen ( substr ( $ value , strpos ( $ value , "." ) ) ) , strlen ( substr ( $ this -> _expiresAt , strpos ( ...
Attempts to unlock the mutex returns true if successful or false if the mutex is in use by another process
11,213
public function beforeLock ( ) { $ event = new ModelEvent ( ) ; $ event -> sender = $ this ; $ this -> onBeforeLock ( $ event ) ; return $ event -> isValid ; }
Invoked before the mutex is locked . The default implementation raises the onBeforeLock event
11,214
public function beforeUnlock ( ) { $ event = new ModelEvent ; $ event -> sender = $ this ; $ this -> onBeforeUnlock ( $ event ) ; return $ event -> isValid ; }
Invoked before the mutex is unlocked . The default implementation raises the onBeforeUnlock event
11,215
public function getExpiresAt ( $ forceRecalculate = false ) { if ( $ forceRecalculate || $ this -> _expiresAt === null ) { $ this -> _expiresAt = $ this -> expiresAfter + microtime ( true ) ; } return $ this -> _expiresAt ; }
Gets the time the mutex expires
11,216
public function loadModule ( ) { \ BFW \ Application :: getInstance ( ) -> getMonolog ( ) -> getLogger ( ) -> debug ( 'Load module' , [ 'name' => $ this -> name ] ) ; $ this -> loadConfig ( ) ; $ this -> obtainLoadInfos ( ) ; $ this -> status -> load = true ; }
Load informations about the module
11,217
protected function loadConfig ( ) { if ( ! file_exists ( CONFIG_DIR . $ this -> name ) ) { return ; } $ this -> config = new \ BFW \ Config ( $ this -> name ) ; $ this -> config -> loadFiles ( ) ; }
Instantiate the Config object to obtains module s configuration
11,218
protected function obtainLoadInfos ( ) { $ currentClass = get_called_class ( ) ; $ this -> loadInfos = $ currentClass :: readJsonFile ( MODULES_DIR . $ this -> name . '/module.json' ) ; }
Save loaded informations from json file into the loadInfos property
11,219
protected static function readJsonFile ( string $ jsonFilePath ) { if ( ! file_exists ( $ jsonFilePath ) ) { throw new Exception ( 'File ' . $ jsonFilePath . ' not found.' , self :: ERR_FILE_NOT_FOUND ) ; } $ infos = json_decode ( file_get_contents ( $ jsonFilePath ) ) ; if ( $ infos === null ) { throw new Exception ( ...
Read and parse a json file
11,220
public function addDependency ( string $ dependencyName ) : self { if ( ! property_exists ( $ this -> loadInfos , 'require' ) ) { $ this -> loadInfos -> require = [ ] ; } if ( ! is_array ( $ this -> loadInfos -> require ) ) { $ this -> loadInfos -> require = [ $ this -> loadInfos -> require ] ; } $ this -> loadInfos ->...
Add a dependency to the module Used for needMe property in module infos
11,221
protected function obtainRunnerFile ( ) : string { $ moduleInfos = $ this -> loadInfos ; $ runnerFile = '' ; if ( property_exists ( $ moduleInfos , 'runner' ) ) { $ runnerFile = ( string ) $ moduleInfos -> runner ; } if ( empty ( $ runnerFile ) ) { return '' ; } $ runnerFile = MODULES_DIR . $ this -> name . '/' . $ run...
Get path to the runner file
11,222
public function runModule ( ) { if ( $ this -> status -> run === true ) { return ; } $ runnerFile = $ this -> obtainRunnerFile ( ) ; $ initFunction = function ( ) use ( $ runnerFile ) { if ( empty ( $ runnerFile ) ) { return ; } require ( realpath ( $ runnerFile ) ) ; } ; $ this -> status -> run = true ; $ initFunction...
Run the module in a closure
11,223
private function strAdd ( string $ str , string $ insertstr , int $ pos ) : string { $ str = substr ( $ str , 0 , $ pos ) . $ insertstr . substr ( $ str , $ pos ) ; return $ str ; }
Add string at specific postion
11,224
public function textRenderer ( string $ text , string $ dataType = 'text' ) : Renderer { if ( ! $ this -> allowedTypeExist ( $ dataType ) ) { throw new Server500 ( new \ ArrayObject ( array ( "explain" => 'Undefined {' . $ dataType . '} type for text render' , "solution" => "Please set the allowed text render type : " ...
Display text on screen
11,225
private function allowedTypeExist ( string $ type ) : bool { foreach ( $ this -> allowed_text_render as $ one ) { if ( $ one [ "type" ] === $ type ) { return ( true ) ; } } return ( false ) ; }
Check if allowed type exist for text render
11,226
private function assemblyTextRender ( ) : array { $ str = "" ; $ type = "text" ; foreach ( $ this -> allowed_text_render as $ one ) { if ( $ one [ "priority" ] === 1 ) { $ type = $ one [ "type" ] ; break ; } } foreach ( self :: $ buffer_text as $ one ) { $ str .= $ one [ "text" ] ; } return ( array ( "text" => $ str , ...
Merge all text render
11,227
public function jsonRenderer ( $ elements ) : Renderer { if ( ! is_array ( $ elements ) && ! is_object ( $ elements ) ) { throw new Server500 ( new \ ArrayObject ( array ( "explain" => "The parameters {elements} is not a valid object/array for json renderer " , "solution" => "Please set a valid parameters for json rend...
Display json elements on screen
11,228
public function xmlRenderer ( array $ response , string $ firstelem , string $ name = null ) : Renderer { $ xmlElem = new \ SimpleXMLElement ( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><$firstelem></$firstelem>" ) ; $ this -> buildXml ( $ response , $ xmlElem ) ; libxml_use_internal_errors ( true ) ; $ feed = new \ ...
Render to XML format
11,229
private function buildXml ( array $ array , \ SimpleXMLElement & $ xmlElem ) : \ SimpleXMLElement { foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { if ( ! is_numeric ( $ key ) ) { $ subnode = $ xmlElem -> addChild ( "$key" ) ; $ this -> buildXml ( $ value , $ subnode ) ; } else { $ subnode = $ x...
Build xml element
11,230
public function registerCustomRenderer ( $ callback , array $ args = null ) : Renderer { if ( is_callable ( $ callback ) ) { $ end = substr ( $ callback , ( strlen ( $ callback ) - 8 ) ) ; if ( $ end === "Renderer" ) { $ this -> display_elements [ "custom" ] = $ callback ; $ this -> display_elements [ "args" ] = $ args...
Register a custom renderer
11,231
private function buildCsv ( ) { if ( $ this -> display_elements [ 'excel' ] === true ) { header ( 'Content-Type: application/vnd.ms-excel' ) ; } else { header ( 'Content-Transfer-Encoding: binary' ) ; header ( 'Expires: 0' ) ; header ( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ) ; header ( 'Pragma: pu...
Build a CSV
11,232
public function pushRender ( ) { if ( isset ( $ this -> display_elements [ "graphic" ] ) ) { echo $ this -> display_elements [ "graphic" ] ; } elseif ( isset ( $ this -> display_elements [ "json" ] ) && $ this -> display_elements [ "json" ] != "" ) { if ( isset ( $ this -> display_elements [ "json" ] [ 'code' ] ) ) { @...
Display element in display_element array
11,233
public function update ( ) { $ s = new static ( ) ; $ where = "id = {$s::$ID}" ; return self :: $ db -> update ( $ s :: $ entity_table , $ this -> db_fields , $ where ) ; }
Update a record in the table
11,234
public static function remove ( $ id ) { $ s = new static ( ) ; if ( is_int ( $ id ) ) { $ where = "id = {$id}" ; self :: $ db -> delete ( $ s :: $ entity_table , $ where ) ; } else { throw new IDShouldBeNumber ( 'Pass in an ID as the parameter, ID has to be a number' , 1 ) ; } }
Remove a record from the table with the specified ID
11,235
public static function findAll ( ) { $ s = new static ( ) ; self :: $ db -> select ( $ s :: $ entity_table ) ; return self :: $ db -> objectSet ( self :: $ child_class ) ; }
Finds all records in the table
11,236
public function create ( string $ type ) : RenderableElementInterface { $ type = ( string ) $ type ; $ search = strtolower ( $ type ) ; if ( isset ( $ this -> typeToView [ $ search ] ) ) { $ class = $ this -> typeToView [ $ search ] ; return new $ class ( ) ; } elseif ( class_exists ( $ type ) ) { $ class = new $ type ...
Find the correct Field - Class by type .
11,237
private function truncateTrace ( $ thrower ) : void { $ this -> truncatedTrace = new ExceptionTrace ( $ this -> getTrace ( ) , $ this -> file , $ this -> line ) ; $ options = $ this -> createOptionsForTruncateTrace ( $ thrower ) ; if ( ! $ options ) { return ; } $ this -> truncatedTrace -> truncate ( $ options ) ; $ th...
Truncates the trace by howTruncateTrace options
11,238
private function createOptionsForTruncateTrace ( $ thrower ) : ? array { if ( $ thrower ) { if ( is_string ( $ thrower ) ) { return [ 'namespace' => $ thrower , ] ; } if ( is_object ( $ thrower ) ) { return [ 'namespace' => preg_replace ( '/(\\\\[^\\\\]+)$/s' , '' , get_class ( $ thrower ) ) , ] ; } return null ; } $ o...
Creates an options list for truncate
11,239
public function evaluate ( ) { if ( ! ( $ wrapperClass = $ this -> tsValue ( 'wrapperClass' ) ) ) { throw new Exception ( "Missing 'wrapperClass' property for WrapRemover." ) ; } $ content = $ this -> getValue ( ) ; if ( $ this -> getWorkspaceName ( ) !== 'live' ) { return $ content ; } return $ this -> removeWrapper (...
Inside live workspace it does NOT render extra DIV . content - collection .
11,240
public function removeWrapper ( $ content , $ wrapperTag , $ wrapperClass ) { $ content = trim ( $ content ) ; $ wrap = array ( "<$wrapperTag class=\"$wrapperClass\">" , "</$wrapperTag>" , ) ; if ( 0 !== strpos ( $ content , $ wrap [ 0 ] ) ) { return $ content ; } $ start = strlen ( $ wrap [ 0 ] ) ; $ length = strlen (...
Remove extra DIV wrapper if it contains only the default CSS class set in wrapperClass TS variable .
11,241
public static function build ( $ content , ExecutionInfos $ infos , Request \ AbstractRequest $ request ) { $ response = new Response ( $ request ) ; $ response -> setStatus ( $ infos -> status ) ; $ response -> setTransactionTime ( $ infos -> transactionTime ) ; $ response -> setExecutionInfos ( $ infos ) ; if ( ! emp...
Build a new reponse object from handle execution result
11,242
public static function parseHeaders ( $ content , AbstractMessage $ message ) { $ namespace = explode ( '\\' , get_class ( $ message ) ) ; $ name = strtoupper ( array_pop ( $ namespace ) ) ; if ( strpos ( $ content , 'HTTP/' ) === 0 || strpos ( $ content , $ name ) === 0 ) { $ line = self :: nibbleLine ( $ content ) ; ...
Parse headers from content and populate response with it
11,243
private static function nibbleLine ( & $ content , $ eol = "\r\n" ) { $ line = substr ( $ content , 0 , strpos ( $ content , $ eol ) ) ; $ content = substr ( $ content , strlen ( $ line ) + 2 ) ; return $ line ; }
Read a line inside a string remove the read line from the string and return the line
11,244
protected function mergeExtra ( RootPackageInterface $ root , PluginState $ state ) { $ extra = $ this -> getPackage ( ) -> getExtra ( ) ; unset ( $ extra [ 'merge-plugin' ] ) ; if ( $ state -> shouldMergeExtra ( ) && ! empty ( $ extra ) ) { $ unwrapped = static :: unwrapIfNeeded ( $ root , 'setExtra' ) ; $ unwrapped -...
Merge extra config into a RootPackage .
11,245
private function getExtra ( RootPackageInterface $ root , PluginState $ state , $ extra ) { $ rootExtra = $ root -> getExtra ( ) ; if ( $ state -> replaceDuplicateLinks ( ) ) { return self :: mergeExtraArray ( $ state -> shouldMergeExtraDeep ( ) , $ rootExtra , $ extra ) ; } if ( ! $ state -> shouldMergeExtraDeep ( ) )...
Get extra config .
11,246
public static function startOutputBuffer ( ) { if ( ob_get_level ( ) > 1 ) { return ; } $ outputCallback = null ; if ( GZIP_SUPPORTED && ! DISABLE_GZIP ) { $ outputCallback = 'ob_gzhandler' ; } if ( in_array ( $ outputCallback , ob_list_handlers ( ) ) ) { return ; } ob_start ( $ outputCallback ) ; }
Start a new output buffer .
11,247
public static function get_by_transaction ( Transaction $ transaction , $ limit = null ) { $ db = Database :: Get ( ) ; if ( is_null ( $ limit ) ) { $ ids = $ db -> get_column ( 'SELECT id FROM transaction_log WHERE transaction_id=?' , [ $ transaction -> id ] ) ; } else { $ ids = $ db -> get_column ( 'SELECT id FROM tr...
Get by transaction
11,248
public static function get_last_by_transaction ( Transaction $ transaction ) { $ db = Database :: Get ( ) ; $ id = $ db -> get_one ( 'SELECT id FROM transaction_log WHERE transaction_id=? ORDER BY created DESC LIMIT 1' , [ $ transaction -> id ] ) ; if ( $ id === null ) { throw new \ Exception ( 'No transaction_log yet'...
Get last by transaction
11,249
public static function getInstance ( ) : Request { if ( self :: $ instance === null ) { $ calledClass = get_called_class ( ) ; self :: $ instance = new $ calledClass ; } return self :: $ instance ; }
Create singleton instance for this class
11,250
public function runDetect ( ) { $ this -> detectIp ( ) ; $ this -> detectLang ( ) ; $ this -> detectReferer ( ) ; $ this -> detectMethod ( ) ; $ this -> detectSsl ( ) ; $ this -> detectRequest ( ) ; }
Run all detect method
11,251
protected function detectLang ( ) { $ acceptLanguage = $ this -> serverValue ( 'HTTP_ACCEPT_LANGUAGE' ) ; if ( empty ( $ acceptLanguage ) ) { $ this -> lang = '' ; return ; } $ acceptedLangs = explode ( ',' , $ acceptLanguage ) ; $ firstLang = explode ( ';' , $ acceptedLangs [ 0 ] ) ; $ lang = strtolower ( $ firstLang ...
Detect the primary client s language
11,252
protected function detectRequest ( ) { $ parseUrl = parse_url ( $ this -> serverValue ( 'REQUEST_URI' ) ) ; $ scheme = ( $ this -> ssl === true ) ? 'https' : 'http' ; $ request = [ 'scheme' => $ scheme , 'host' => $ this -> serverValue ( 'HTTP_HOST' ) , 'port' => $ this -> serverValue ( 'SERVER_PORT' ) , 'user' => $ th...
Detect the current request informations
11,253
protected function replicate ( array $ properties = [ ] ) { $ class = get_class ( $ this ) ; $ domain = isset ( $ properties [ 'domain' ] ) ? $ properties [ 'domain' ] : $ this -> domain ; $ namespace = isset ( $ properties [ 'namespace' ] ) ? $ properties [ 'namespace' ] : $ this -> namespace ; return new $ class ( $ ...
Returns a new instance of this TextProvider .
11,254
public function toType ( $ alias , TypeFactory $ factory ) { $ typeRule = $ this -> findTypeRule ( $ alias ) ; $ config = $ typeRule [ 'type' ] . '|' . $ typeRule [ 'rule' ] ; return $ factory -> toType ( $ config ) ; }
Create a type of this aliases .
11,255
protected function buildCacheOnce ( ) { if ( $ this -> aliasCache !== null ) { return ; } $ this -> aliasCache = [ ] ; foreach ( $ this -> aliases as $ typeName => $ rules ) { foreach ( $ rules as $ name => $ rule ) { if ( isset ( $ this -> aliasCache [ $ name ] ) ) { $ firstTypeName = $ this -> aliasCache [ $ name ] [...
Build a cache for faster name lookups .
11,256
protected function defuseKey ( ) : string { try { if ( ! ( $ key = DefuseKey :: createNewRandomKey ( ) -> saveToAsciiSafeString ( ) ) ) { throw new Exception ( 'Failed to generate an encryption key.' ) ; } } catch ( \ Throwable $ Exception ) { throw $ Exception ; } return $ key ; }
Generates a Defuse key .
11,257
public function registerReflectionIdAccessors ( $ classNames , $ idPropertyName ) { foreach ( ( array ) $ classNames as $ className ) { $ getter = function ( $ entity ) use ( $ className , $ idPropertyName ) { $ reflectionClass = new ReflectionClass ( $ className ) ; $ property = $ reflectionClass -> getProperty ( $ id...
Registers accessors that use reflection to set Id properties in the input classes
11,258
protected function getLengths ( array $ data ) { for ( $ i = 0 ; $ i < $ this -> columns ; $ i ++ ) { $ this -> maxLength [ $ i ] = 0 ; foreach ( $ this -> headers as $ field ) { $ field = strip_tags ( $ field ) ; if ( strlen ( $ field ) > $ this -> maxLength [ $ i ] ) { $ this -> maxLength [ $ i ] = strlen ( $ field )...
Find maximum lengths for each column
11,259
protected function mapColumName ( $ columnName ) { if ( isset ( $ this -> defaultAddressMapping [ $ columnName ] ) ) { return $ this -> defaultAddressMapping [ $ columnName ] ; } throw new \ Exception ( sprintf ( 'Can\'t map member name to default address column "%s"' , $ columnName ) ) ; }
Maps the passed customer address column name to the matching customer member name .
11,260
protected function saveDefaultAddressByType ( $ type ) { $ email = $ this -> getValue ( ColumnKeys :: EMAIL ) ; $ websiteId = $ this -> getSubject ( ) -> getStoreWebsiteIdByCode ( $ this -> getValue ( ColumnKeys :: WEBSITE ) ) ; if ( $ customer = $ this -> getCustomerBunchProcessor ( ) -> loadCustomerByEmailAndWebsiteI...
Save default address by type .
11,261
public function add ( $ identifiable ) { if ( $ identifiable instanceof Named ) { return $ this -> set ( $ identifiable -> getId ( ) , $ identifiable ) ; } $ id = $ identifiable instanceof Identifiable ? $ identifiable -> getId ( ) : $ identifiable ; $ title = $ this -> getTitleFromProvider ( $ id ) ; $ resourceName = ...
Add a identifiable object or just an id .
11,262
protected function getTitleFromProvider ( $ itemId ) { $ itemId = $ this -> escapeId ( $ itemId ) ; if ( ! $ this -> texts ) { return $ itemId ; } return $ this -> texts -> get ( $ itemId ) ; }
Get the title from TextProvider if one set .
11,263
protected function escapeId ( $ id ) { if ( ! $ this -> replace ) { return $ id ; } return str_replace ( array_keys ( $ this -> replace ) , array_values ( $ this -> replace ) , $ id ) ; }
Escape the id for safe usage in translation keys .
11,264
protected function prepare ( ) { $ this -> addOption ( 'passive' , true ) ; $ tmp = clone $ this -> getUrl ( ) ; $ tmp -> path ( '' ) ; $ this -> addOption ( 'url' , $ tmp -> toString ( ) ) ; }
Prepare the request execution by adding specific cURL parameters
11,265
private function getFromExcludedSource ( $ key , $ replace , $ locale , $ fallback ) { if ( ! PageKey :: fromLineKeyString ( $ key ) -> isExcludedSource ( ) ) return null ; return parent :: get ( $ key , $ replace , $ locale , $ fallback ) ; }
Get from excluded sources . This is used here to make retrieval of these non - managed translations a lot faster by going straight to source
11,266
private function getFromCache ( $ key , array $ replace = array ( ) , $ locale = null , $ fallback = true ) { if ( false === strpos ( $ key , 'squanto::' ) ) { $ key = 'squanto::' . $ key ; } $ result = parent :: get ( $ key , $ replace , $ locale , $ fallback ) ; return ( $ result !== $ key ) ? $ result : null ; }
Retrieve the translation from the squanto cache .
11,267
private function isDatabaseAlreadyMigrated ( ) { if ( ! is_null ( $ this -> isDatabaseAlreadyMigrated ) ) { return $ this -> isDatabaseAlreadyMigrated ; } return ( $ this -> isDatabaseAlreadyMigrated = Schema :: hasTable ( 'squanto_lines' ) ) ; }
Verify that SQUANTO migrations are already run and present in this environment Allow for a soft install
11,268
public function nested ( ) { if ( $ this -> nestedCache === null ) { $ this -> nestedCache = static :: toNested ( $ this -> array , $ this -> separator ) ; } return $ this -> nestedCache ; }
Returns the complete nested version of the source array .
11,269
public static function toNested ( array $ flat , $ delimiter = '.' ) { $ tree = [ ] ; foreach ( $ flat as $ key => $ val ) { $ parts = static :: splitPath ( $ key , $ delimiter ) ; $ leafPart = array_pop ( $ parts ) ; $ parent = & $ tree ; foreach ( $ parts as $ part ) { if ( ! isset ( $ parent [ $ part ] ) ) { $ paren...
Direct access to the array - nester . Put a flat array in this method and it will return a recursivly nested version .
11,270
public static function withoutNested ( array $ flat , $ separator = '.' ) { $ root = [ ] ; foreach ( $ flat as $ key => $ value ) { if ( strpos ( $ key , $ separator ) === false && ! is_array ( $ value ) ) { $ root [ $ key ] = $ value ; } } return $ root ; }
Removes all nested arrays from a flat array .
11,271
protected static function flatArray ( array & $ result , array $ array , $ connector = '.' , $ prefix = null ) { foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { static :: flatArray ( $ result , $ value , $ connector , $ prefix . $ key . $ connector ) ; continue ; } $ result [ $ prefix . $ key ] ...
Recursively converts nested array into a flat one with keys preserving .
11,272
public static function checkType ( array $ vars ) : bool { foreach ( $ vars as $ var ) { if ( ! is_array ( $ var ) ) { throw new Exception ( 'The informations need for the check is not in a correct format.' , self :: ERR_CHECKTYPE_INFOS_FORMAT ) ; } if ( ! isset ( $ var [ 'data' ] ) || empty ( $ var [ 'type' ] ) || ( i...
Check types of variables
11,273
public static function checkMail ( string $ mail ) : bool { $ securisedMail = Secure :: secureData ( $ mail , 'email' , false ) ; if ( $ securisedMail === false ) { return false ; } return true ; }
Check if an email address is valid
11,274
public function getSectionInfoBySlug ( string $ sectionHandle , string $ slug ) : JsonResponse { try { $ entry = $ this -> readSection -> read ( ReadOptions :: fromArray ( [ ReadOptions :: SECTION => $ sectionHandle , ReadOptions :: SLUG => $ slug ] ) ) [ 0 ] ; } catch ( \ Exception $ exception ) { return $ this -> err...
Just like getSectionInfo but for slugs instead of IDs . IDs are used in too much logic to cleanly replace by slugs . So we fetch by slug then transform that into a getSectionInfo call . That could be a bit slower but maybe not if Doctrine is smart enough .
11,275
private function handleToPropertyName ( string $ handle , array $ fieldProperties ) : string { foreach ( $ fieldProperties as $ propertyName => $ property ) { if ( $ property [ 'handle' ] === $ handle ) { return $ propertyName ; } } return $ handle ; }
Use the handle to convert it to the actual property name
11,276
private function orderFields ( array $ fields , array $ fieldProperties , array $ showFields = null ) : array { $ originalFields = $ fields [ 'fields' ] ; $ desiredFieldsOrder = $ fields [ 'section' ] [ 'fields' ] ; $ desiredFieldsOrderFiltered = [ ] ; if ( ! is_null ( $ showFields ) ) { foreach ( $ desiredFieldsOrder ...
Make sure the fields are returned in the order you have configured them
11,277
private function cleanFields ( array $ fields ) : array { foreach ( $ fields [ 'fields' ] as & $ field ) { if ( array_key_exists ( 'generator' , $ field [ key ( $ field ) ] ) ) { unset ( $ field [ key ( $ field ) ] [ 'generator' ] ) ; } } unset ( $ fields [ 'section' ] ) ; return $ fields ; }
Just remove stuff that s not needed for a frontend
11,278
private function getEntityProperties ( SectionInterface $ section ) : array { $ sectionFullyQualifiedClassName = ( string ) $ section -> getConfig ( ) -> getFullyQualifiedClassName ( ) ; $ sectionEntity = new $ sectionFullyQualifiedClassName ; return $ sectionEntity :: FIELDS ; }
Get the built in field mapping
11,279
private function getRelationshipsTo ( string $ fieldHandle , array $ fieldInfo , string $ sectionHandle , int $ id = null ) : ? array { if ( ! empty ( $ fieldInfo [ $ fieldHandle ] [ 'to' ] ) ) { try { $ sexyFieldInstructions = $ this -> getSexyFieldRelationshipInstructions ( $ fieldInfo , $ fieldHandle ) ; $ nameExpre...
Get entries to populate a relationships field
11,280
private function getSexyFieldRelationshipInstructions ( array $ fieldInfo , string $ fieldHandle ) : ? array { return ! empty ( $ fieldInfo [ $ fieldHandle ] [ 'form' ] [ 'sexy-field-instructions' ] [ 'relationship' ] ) ? $ fieldInfo [ $ fieldHandle ] [ 'form' ] [ 'sexy-field-instructions' ] [ 'relationship' ] : null ;...
We may have special instructions configured
11,281
private function setSelectedRelationshipsTo ( string $ sectionHandle , string $ fieldHandle , array $ fieldInfo , int $ id ) : array { $ editing = $ this -> readSection -> read ( ReadOptions :: fromArray ( [ ReadOptions :: SECTION => $ sectionHandle , ReadOptions :: ID => ( int ) $ id ] ) ) -> current ( ) ; try { $ met...
If editing an entry with relationships mark related as true
11,282
private function getOptions ( ) : ? array { $ requestOptions = $ this -> requestStack -> getCurrentRequest ( ) -> get ( 'options' ) ; if ( is_null ( $ requestOptions ) ) { return null ; } $ requestOptions = explode ( ',' , $ requestOptions ) ; $ options = [ ] ; foreach ( $ requestOptions as $ requestOption ) { $ reques...
This is gets the potential parameters from the section info request .
11,283
public function render ( ) : string { $ out = $ this -> before ( ) ; foreach ( $ this -> _widgets as $ widget ) { $ out .= $ widget -> render ( ) ; } $ out .= $ this -> after ( ) ; $ this -> content = $ out ; return $ this -> template ? render ( $ this -> template , $ this -> getAttributes ( ) ) : $ out ; }
Render all widgets
11,284
private function maybeLoadChoices ( ) : bool { if ( ! $ this -> isLoaded ( ) ) { $ callback = $ this -> callback ; $ this -> choices = $ callback ( ) ; $ this -> isLoaded = true ; return true ; } return false ; }
Internal function to ensure that the choices are loaded the right time .
11,285
private function parse ( array $ data ) { $ enumId = EnumId :: fromString ( sprintf ( '%s:%s' , $ data [ 'namespace' ] , $ data [ 'name' ] ) ) ; if ( ! isset ( $ data [ 'type' ] ) ) { $ data [ 'type' ] = 'string' ; } $ values = [ ] ; $ keys = $ this -> fixArray ( $ data [ 'option' ] , 'key' ) ; foreach ( $ keys as $ ke...
Builds an Enum instance from a given set of data .
11,286
protected function findTargetByArguments ( $ targetOrEvent ) { if ( $ targetOrEvent instanceof Bus ) { return $ targetOrEvent ; } if ( $ this -> target instanceof Bus ) { return $ this -> target ; } if ( $ this -> source instanceof Bus ) { return $ this -> source ; } throw new LogicException ( 'No suitable source found...
Helps the to method to find the right target .
11,287
protected function checkSourceAndPattern ( ) { if ( ! $ this -> sourcePatterns ) { throw new LogicException ( "No source events (or patterns) found, Call from() before calling to()" ) ; } if ( $ this -> source instanceof Bus ) { return ; } foreach ( $ this -> sourcePatterns as $ pattern ) { if ( $ this -> isPattern ( $...
Checks if patterns are used on a not pattern supporting source
11,288
protected function newHookableListener ( $ sourceEvent , $ targetEventName ) { return function ( ) use ( $ sourceEvent , $ targetEventName ) { $ args = func_get_args ( ) ; $ targetEventName = $ this -> buildTargetEventName ( $ sourceEvent , $ targetEventName ) ; return $ this -> target -> fire ( $ targetEventName , $ a...
Creates a listener for a hookable object
11,289
protected function newSubscribableListener ( $ event , $ targetEventName ) { return function ( ) use ( $ targetEventName , $ event ) { $ args = func_get_args ( ) ; $ targetEventName = $ this -> buildTargetEventName ( $ event , $ targetEventName ) ; return $ this -> target -> fire ( $ targetEventName , $ args ) ; } ; }
Creates a listener for a subscribable object
11,290
protected function newBusListener ( $ sourcePattern , $ targetEventName ) { return function ( ) use ( $ targetEventName , $ sourcePattern ) { $ args = func_get_args ( ) ; $ originalEventName = array_shift ( $ args ) ; if ( ! $ this -> matchesPattern ( $ originalEventName , $ sourcePattern ) ) { return null ; } $ target...
Creates a listener for a bus .
11,291
public function actionToDev ( ) { Output :: line ( 'Set dev-master package version...' ) ; \ App :: $ domain -> vendor -> package -> versionToDev ( ) ; Output :: block ( 'Success converted version to dev-master' ) ; }
Set dev - master package version
11,292
public function actionUpdate ( ) { Output :: line ( 'Getting package info...' ) ; \ App :: $ domain -> vendor -> package -> versionUpdate ( ) ; Output :: block ( 'Packages version updated' ) ; }
Set new package version
11,293
protected function handle ( $ item , callable $ filter = null ) { if ( null !== $ filter ) { return call_user_func ( $ filter , $ item ) ; } return $ item ; }
Filter an item with a callback
11,294
public function get ( ) : array { $ result = [ ] ; $ filter = $ this -> jory -> getFilter ( ) ; if ( $ filter !== null ) { $ result [ $ this -> keyRepository -> get ( 'flt' ) ] = $ this -> getFilterArray ( $ filter ) ; } $ sorts = $ this -> jory -> getSorts ( ) ; if ( ! empty ( $ sorts ) ) { $ result [ $ this -> keyRep...
Get the array based on given Jory object .
11,295
protected function getFilterArray ( FilterInterface $ filter ) : array { $ result = [ ] ; if ( $ filter instanceof Filter ) { $ result [ $ this -> keyRepository -> get ( 'f' ) ] = $ filter -> getField ( ) ; if ( $ filter -> getOperator ( ) !== null ) { $ result [ $ this -> keyRepository -> get ( 'o' ) ] = $ filter -> g...
Get the filter part of the array .
11,296
protected function getRelationsArray ( array $ relations ) : array { $ relationsArray = [ ] ; foreach ( $ relations as $ relation ) { $ key = $ relation -> getName ( ) ; $ relationsArray [ $ key ] = ( new self ( $ relation -> getJory ( ) , $ this -> minified ) ) -> get ( ) ; } return $ relationsArray ; }
Turn an array of relation objects into an array .
11,297
protected function getSortsArray ( array $ sorts ) : array { $ sortsArray = [ ] ; foreach ( $ sorts as $ sort ) { $ sortsArray [ ] = ( $ sort -> getOrder ( ) === 'desc' ? '-' : '' ) . $ sort -> getField ( ) ; } return $ sortsArray ; }
Turn an array of sort objects into an array .
11,298
public function curry ( $ parameters ) { $ parameters = is_array ( $ parameters ) ? $ parameters : func_get_args ( ) ; return $ this -> append ( static :: currify ( $ parameters ) ) ; }
Same as append but replace all callables with lambdas .
11,299
public static function callFast ( callable $ callable , $ args = null ) { if ( ! is_array ( $ args ) ) { return call_user_func ( $ callable , $ args === null ? [ ] : [ $ args ] ) ; } switch ( count ( $ args ) ) { case 0 : return call_user_func ( $ callable ) ; case 1 : return call_user_func ( $ callable , $ args [ 0 ] ...
Just call a callable without parsing any lambdas