idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
31,700
protected function readPreferences ( ) { $ storedPreferences = null ; if ( Doozr_Kernel :: RUNTIME_ENVIRONMENT_CLI !== self :: $ runtimeEnvironment ) { foreach ( self :: $ storages as $ storage ) { $ method = 'read' . ucfirst ( $ storage ) ; $ storedPreferences = $ this -> { $ method } ( ) ; if ( $ storedPreferences ) { break ; } } } return $ storedPreferences ; }
This method is intend to return the user s preferred previously stored locale from store .
31,701
protected function detectByRequestHeader ( ) { if ( ! isset ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ) { return false ; } $ acceptedLanguages = explode ( ',' , $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ; if ( count ( $ acceptedLanguages ) < 1 ) { return false ; } foreach ( $ acceptedLanguages as $ acceptedLanguage ) { $ parts = explode ( ';' , $ acceptedLanguage ) ; $ locale = strtolower ( trim ( $ parts [ 0 ] ) ) ; $ weight = 1 ; if ( count ( $ parts ) > 1 ) { $ weight = trim ( str_replace ( 'q=' , '' , $ parts [ 1 ] ) ) ; } if ( $ this -> isValidLocaleCode ( $ locale ) && $ weight >= 0 ) { $ this -> addLocale ( $ locale , $ weight ) ; } } $ this -> detectedLocales = $ this -> sortByWeight ( $ this -> detectedLocales ) ; foreach ( $ this -> detectedLocales as $ localeSet ) { $ parts = explode ( '-' , $ localeSet [ 'locale' ] ) ; $ parts [ 1 ] = ( isset ( $ parts [ 1 ] ) ) ? $ parts [ 1 ] : $ parts [ 0 ] ; $ language = ( $ this -> isValidLocaleCode ( $ parts [ 0 ] ) ) ? $ parts [ 0 ] : null ; $ country = ( $ this -> isValidLocaleCode ( $ parts [ 1 ] ) ) ? $ parts [ 1 ] : null ; $ this -> detectedLanguages [ ] = $ language ; $ this -> detectedCountries [ ] = $ country ; } return [ 'locale' => $ this -> detectedLocales [ 0 ] [ 'locale' ] , 'weight' => $ this -> detectedLocales [ 0 ] [ 'weight' ] , 'language' => $ this -> detectedLanguages [ 0 ] , 'country' => $ this -> detectedCountries [ 0 ] , ] ; }
This method is intend to detect the available locales by request - header .
31,702
protected function sortByWeight ( array $ locales ) { $ index = [ ] ; foreach ( $ locales as $ localeSet ) { $ index [ $ localeSet [ 'locale' ] ] = ( int ) $ localeSet [ 'weight' ] ; } $ index = array_flip ( $ index ) ; krsort ( $ index ) ; $ locales = [ ] ; foreach ( $ index as $ weight => $ locale ) { $ locales [ ] = [ 'locale' => $ locale , 'weight' => ( $ weight / 10 ) , ] ; } return $ locales ; }
This method is intend to sort the detected locales by it s weight .
31,703
protected function readSession ( ) { try { $ storedSettings = $ this -> getSession ( ) -> get ( self :: $ identifier ) ; } catch ( Doozr_Session_Service_Exception $ e ) { $ storedSettings = null ; } if ( ! $ storedSettings || ! $ this -> isValidLocaleCode ( $ storedSettings [ 'locale' ] ) ) { $ storedSettings = null ; } return $ storedSettings ; }
This method is intend to read a previous stored locale - configuration from session .
31,704
protected function writeCookie ( array $ preferences ) { $ data = implode ( ',' , $ preferences ) ; $ lifetime = time ( ) + self :: $ preferenceLifetime ; $ path = '/' ; $ server = explode ( '.' , $ _SERVER [ 'SERVER_NAME' ] ) ; $ domain = '' ; for ( $ i = 2 ; $ i > 0 ; -- $ i ) { $ domain = '.' . $ server [ $ i ] . $ domain ; } return setcookie ( self :: $ identifier , $ data , $ lifetime , $ path , $ domain ) ; }
This method is intend to write preferences to a cookie on user s client .
31,705
private function CreateUrlset ( ) { $ this -> urlset = $ this -> domDoc -> createElement ( "urlset" ) ; $ this -> SetAttribute ( $ this -> urlset , "xmlns" , "http://www.sitemaps.org/schemas/sitemap/0.9" ) ; }
Creates the urlset element
31,706
function AddUrl ( $ url , ChangeFrequency $ changeFreq = null , $ priority = null , Date $ lastMod = null ) { $ elm = $ this -> domDoc -> createElement ( "url" ) ; $ this -> AppendTextChild ( $ elm , "loc" , $ url ) ; if ( $ changeFreq ) $ this -> AppendTextChild ( $ elm , "changefreq" , ( string ) $ changeFreq ) ; if ( $ priority ) $ this -> AppendTextChild ( $ elm , "priority" , $ priority ) ; if ( $ lastMod ) $ this -> AppendTextChild ( $ elm , "lastmod" , $ lastMod -> ToString ( 'c' ) ) ; $ this -> urlset -> appendChild ( $ elm ) ; }
Adds an url to the sitemap
31,707
protected static function & _flat ( & $ target , & $ data , $ key = '' ) { foreach ( $ data as $ k => $ d ) { if ( is_array ( $ d ) ) { self :: _flat ( $ target , $ d , $ key . '.' . $ k ) ; } else { $ target [ ltrim ( $ key . '.' . $ k , '.' ) ] = $ d ; } } return $ target ; }
Pomocnicza metoda dla flat .
31,708
public function install ( ) : OperationResult { $ result = new OperationResult ( ) ; $ sourcePath = "{$this->packageInstallDir}/.installer/%s/bundles.php" ; foreach ( $ this -> projectType -> getProjectDirs ( ) as $ projectDir ) { $ bundleFile = sprintf ( $ sourcePath , $ projectDir ) ; if ( is_file ( $ bundleFile ) ) { $ data = require $ bundleFile ; if ( ! is_array ( $ data ) ) { $ result -> addErrorMessage ( '<error>The bundles.php file in installer must return an array</error>' ) ; break ; } $ installedBundlesFile = "{$this->projectRootDir}/config/bundles.php" ; if ( file_exists ( $ installedBundlesFile ) ) { $ installedBundles = require $ installedBundlesFile ; if ( is_array ( $ installedBundles ) ) { $ resultingBundleData = array_merge ( $ installedBundles , $ data ) ; $ export = $ this -> dumpConfig ( $ resultingBundleData ) ; if ( ! file_put_contents ( $ installedBundlesFile , $ export , LOCK_EX ) ) { $ result -> addErrorMessage ( "<error>Could not copy bundle content from {$this->packageName}</error>" ) ; } } } } } if ( ! $ result -> isFailure ( ) ) { $ result -> addStatusMessage ( "Successfully copied Bundle information from {$this->packageName}" ) ; } return $ result ; }
Handle installation for given operation
31,709
static function cli_read ( $ format , $ first = false ) { $ stdin = fopen ( 'php://stdin' , 'r' ) ; $ result = fscanf ( $ stdin , $ format ) ; if ( $ first ) { return empty ( $ result [ 0 ] ) ? '' : $ result [ 0 ] ; } return $ result ; }
Read a line from cli
31,710
static function cli_write ( $ str ) { if ( gettype ( $ str ) != 'string' ) { return false ; } $ stdout = fopen ( 'php://stdout' , 'w' ) ; return fwrite ( $ stdout , $ str ) ; }
write a string to cli
31,711
public function parseRequest ( $ request ) { if ( count ( $ this -> availableLanguages ) > 0 ) { if ( preg_match ( '/\/(' . implode ( '|' , $ this -> availableLanguages ) . ')(.*)/si' , $ request -> url , $ matches ) ) { Yii :: $ app -> language = $ matches [ 1 ] ; } } $ res = parent :: parseRequest ( $ request ) ; if ( is_array ( $ res ) ) { if ( isset ( $ res [ 1 ] [ 'language' ] ) && in_array ( $ res [ 1 ] [ 'language' ] , $ this -> availableLanguages ) ) { Yii :: $ app -> language = $ res [ 1 ] [ 'language' ] ; } } return $ res ; }
Parse request and set application language
31,712
public function getClientByName ( string $ name ) : Client { if ( ! isset ( $ this -> clientsConfig [ $ name ] ) ) { throw new RuntimeException ( sprintf ( 'Contentful client with "%s" name does not exist.' , $ name ) ) ; } return $ this -> clientsConfig [ $ name ] [ 'service' ] ; }
Returns the Contentful client with provided name .
31,713
public function getClientBySpaceId ( string $ spaceId ) : ? Client { foreach ( $ this -> clientsConfig as $ clientConfig ) { if ( $ clientConfig [ 'space' ] === $ spaceId ) { return $ clientConfig [ 'service' ] ; } } return null ; }
Returns the Contentful client which serves the space with provided ID .
31,714
public function getContentType ( string $ id ) : ? ContentType { foreach ( $ this -> clientsConfig as $ clientConfig ) { $ client = $ clientConfig [ 'service' ] ; foreach ( $ client -> getContentTypes ( ) -> getItems ( ) as $ contentType ) { if ( $ contentType -> getId ( ) === $ id ) { return $ contentType ; } } } return null ; }
Returns the content type with specified ID .
31,715
public function loadContentfulEntry ( string $ id ) : ContentfulEntry { $ idList = explode ( '|' , $ id ) ; if ( count ( $ idList ) !== 2 ) { throw new NotFoundException ( sprintf ( 'Item ID %s not valid.' , $ id ) ) ; } $ client = $ this -> getClientBySpaceId ( $ idList [ 0 ] ) ; if ( $ client === null ) { throw new NotFoundException ( sprintf ( 'Item ID %s not valid.' , $ idList [ 0 ] ) ) ; } $ contentfulEntry = $ this -> findContentfulEntry ( $ id ) ; if ( $ contentfulEntry instanceof ContentfulEntry ) { $ contentfulEntry -> reviveRemoteEntry ( $ client ) ; } else { $ contentfulEntry = $ this -> buildContentfulEntry ( $ client -> getEntry ( $ idList [ 1 ] ) , $ id ) ; } if ( $ contentfulEntry -> getIsDeleted ( ) ) { throw new NotFoundException ( sprintf ( 'Entry with ID %s deleted.' , $ id ) ) ; } return $ contentfulEntry ; }
Returns the Contentful entry with provided ID .
31,716
public function getContentfulEntries ( int $ offset = 0 , ? int $ limit = null , ? Client $ client = null , ? Query $ query = null ) : array { $ client = $ client ?? $ this -> defaultClient ; $ query = $ query ?? new Query ( ) ; $ query -> setSkip ( $ offset ) ; if ( $ limit !== null ) { $ query -> setLimit ( $ limit ) ; } return $ this -> buildContentfulEntries ( $ client -> getEntries ( $ query ) , $ client ) ; }
Returns the list of Contentful entries .
31,717
public function getContentfulEntriesCount ( ? Client $ client = null , ? Query $ query = null ) : int { $ client = $ client ?? $ this -> defaultClient ; return count ( $ client -> getEntries ( $ query ) ) ; }
Returns the count of Contentful entries .
31,718
public function searchContentfulEntries ( string $ searchText , int $ offset = 0 , int $ limit = 25 , ? Client $ client = null ) : array { $ client = $ client ?? $ this -> defaultClient ; $ query = new Query ( ) ; $ query -> setLimit ( $ limit ) ; $ query -> setSkip ( $ offset ) ; $ query -> where ( 'query' , $ searchText ) ; return $ this -> buildContentfulEntries ( $ client -> getEntries ( $ query ) , $ client ) ; }
Searches for Contentful entries .
31,719
public function searchContentfulEntriesCount ( string $ searchText , ? Client $ client = null ) : int { $ client = $ client ?? $ this -> defaultClient ; $ query = new Query ( ) ; $ query -> where ( 'query' , $ searchText ) ; return count ( $ client -> getEntries ( $ query ) ) ; }
Returns the count of searched Contentful entries .
31,720
public function getClientsAndContentTypesAsChoices ( ) : array { $ clientsAndContentTypes = [ ] ; foreach ( $ this -> clientsConfig as $ clientName => $ clientConfig ) { $ client = $ clientConfig [ 'service' ] ; $ clientsAndContentTypes [ $ client -> getSpace ( ) -> getName ( ) ] = $ clientName ; foreach ( $ client -> getContentTypes ( ) -> getItems ( ) as $ contentType ) { $ clientsAndContentTypes [ '> ' . $ contentType -> getName ( ) ] = $ clientName . '|' . $ contentType -> getId ( ) ; } } return $ clientsAndContentTypes ; }
Returns the list of clients and content types for usage in Symfony Forms .
31,721
public function getSpacesAsChoices ( ) : array { $ spaces = [ ] ; foreach ( $ this -> clientsConfig as $ clientConfig ) { $ client = $ clientConfig [ 'service' ] ; $ spaces [ $ client -> getSpace ( ) -> getName ( ) ] = $ clientConfig [ 'space' ] ; } return $ spaces ; }
Returns the list of spaces for usage in Symfony Forms .
31,722
public function getSpacesAndContentTypesAsChoices ( ) : array { $ spaces = [ ] ; foreach ( $ this -> clientsConfig as $ clientConfig ) { $ client = $ clientConfig [ 'service' ] ; $ contentTypes = [ ] ; foreach ( $ client -> getContentTypes ( ) -> getItems ( ) as $ contentType ) { $ contentTypes [ $ contentType -> getName ( ) ] = $ contentType -> getId ( ) ; } $ spaces [ $ client -> getSpace ( ) -> getName ( ) ] = $ contentTypes ; } return $ spaces ; }
Returns the list of spaces and content types for usage in Symfony Forms .
31,723
public function refreshContentfulEntry ( Entry $ remoteEntry ) : ? ContentfulEntry { $ id = $ remoteEntry -> getSpace ( ) -> getId ( ) . '|' . $ remoteEntry -> getId ( ) ; $ contentfulEntry = $ this -> findContentfulEntry ( $ id ) ; if ( $ contentfulEntry instanceof ContentfulEntry ) { $ contentfulEntry -> setJson ( ( string ) json_encode ( $ remoteEntry ) ) ; $ contentfulEntry -> setIsPublished ( true ) ; $ this -> entityManager -> persist ( $ contentfulEntry ) ; $ this -> entityManager -> flush ( ) ; } else { $ contentfulEntry = $ this -> buildContentfulEntry ( $ remoteEntry , $ id ) ; } return $ contentfulEntry ; }
Refreshes the Contentful entry for provided remote entry .
31,724
public function unpublishContentfulEntry ( DeletedEntry $ remoteEntry ) : void { $ systemProperties = $ remoteEntry -> getSystemProperties ( ) ; $ space = $ systemProperties -> getSpace ( ) ; if ( $ space === null ) { return ; } $ id = $ space -> getId ( ) . '|' . $ remoteEntry -> getId ( ) ; $ contentfulEntry = $ this -> findContentfulEntry ( $ id ) ; if ( $ contentfulEntry instanceof ContentfulEntry ) { $ contentfulEntry -> setIsPublished ( false ) ; $ this -> entityManager -> persist ( $ contentfulEntry ) ; $ this -> entityManager -> flush ( ) ; } }
Unpublishes the Contentful entry for provided remote entry .
31,725
public function deleteContentfulEntry ( DeletedEntry $ remoteEntry ) : void { $ systemProperties = $ remoteEntry -> getSystemProperties ( ) ; $ space = $ systemProperties -> getSpace ( ) ; if ( $ space === null ) { return ; } $ id = $ space -> getId ( ) . '|' . $ remoteEntry -> getId ( ) ; $ contentfulEntry = $ this -> findContentfulEntry ( $ id ) ; if ( $ contentfulEntry instanceof ContentfulEntry ) { $ contentfulEntry -> setIsDeleted ( true ) ; $ this -> entityManager -> persist ( $ contentfulEntry ) ; foreach ( $ contentfulEntry -> getRoutes ( ) as $ route ) { $ this -> entityManager -> remove ( $ route ) ; } $ this -> entityManager -> flush ( ) ; } }
Deletes the Contentful entry for provided remote entry .
31,726
public function refreshSpaceCache ( Client $ client ) : void { $ spacePath = $ this -> getSpaceCachePath ( $ client ) ; $ this -> fileSystem -> dumpFile ( $ spacePath . '/space.json' , ( string ) json_encode ( $ client -> getSpace ( ) ) ) ; }
Refreshes space caches for provided client .
31,727
public function refreshContentTypeCache ( Client $ client ) : void { $ spacePath = $ this -> getSpaceCachePath ( $ client ) ; $ contentTypes = $ client -> getContentTypes ( ) ; foreach ( $ contentTypes as $ contentType ) { $ this -> fileSystem -> dumpFile ( $ spacePath . '/ct-' . $ contentType -> getId ( ) . '.json' , ( string ) json_encode ( $ contentType ) ) ; } }
Refreshes content type caches for provided client .
31,728
public function getSpaceCachePath ( Client $ client ) : string { $ space = $ client -> getSpace ( ) ; $ spacePath = $ this -> cacheDir . $ space -> getId ( ) ; if ( ! $ this -> fileSystem -> exists ( $ spacePath ) ) { $ this -> fileSystem -> mkdir ( $ spacePath ) ; } return $ spacePath ; }
Returns the cache path for provided client .
31,729
private function findContentfulEntry ( string $ id ) : ? ContentfulEntry { return $ this -> entityManager -> getRepository ( ContentfulEntry :: class ) -> find ( $ id ) ; }
Returns the Contentful entry with provided ID from the repository .
31,730
private function buildContentfulEntry ( Entry $ remoteEntry , string $ id ) : ContentfulEntry { $ contentfulEntry = new ContentfulEntry ( $ remoteEntry ) ; $ contentfulEntry -> setIsPublished ( true ) ; $ contentfulEntry -> setJson ( ( string ) json_encode ( $ remoteEntry ) ) ; $ route = new Route ( ) ; $ route -> setName ( $ id ) ; $ route -> setStaticPrefix ( $ this -> entrySlugger -> getSlug ( $ contentfulEntry ) ) ; $ route -> setDefault ( RouteObjectInterface :: CONTENT_ID , ContentfulEntry :: class . ':' . $ id ) ; $ route -> setContent ( $ contentfulEntry ) ; $ contentfulEntry -> addRoute ( $ route ) ; $ this -> entityManager -> persist ( $ contentfulEntry ) ; $ this -> entityManager -> persist ( $ route ) ; $ this -> entityManager -> flush ( ) ; return $ contentfulEntry ; }
Builds the Contentful entry from provided remote entry .
31,731
private function buildContentfulEntries ( ResourceArray $ entries , Client $ client ) : array { $ contentfulEntries = [ ] ; foreach ( $ entries as $ remoteEntry ) { $ id = $ remoteEntry -> getSpace ( ) -> getId ( ) . '|' . $ remoteEntry -> getId ( ) ; $ contentfulEntry = $ this -> findContentfulEntry ( $ id ) ; if ( ! $ contentfulEntry instanceof ContentfulEntry ) { $ contentfulEntry = $ this -> buildContentfulEntry ( $ remoteEntry , $ id ) ; } else { $ contentfulEntry -> reviveRemoteEntry ( $ client ) ; } $ contentfulEntries [ ] = $ contentfulEntry ; } return $ contentfulEntries ; }
Builds the Contentful entries from provided remote entries .
31,732
public function offsetSet ( $ offset , $ value ) { if ( NULL === $ offset ) { $ this -> container [ ] = [ $ value , NULL ] ; return ; } $ this -> container [ $ this -> getHash ( $ offset ) ] = [ $ value , $ offset ] ; }
Store the given key and value into the container and its hash to the hashes list .
31,733
protected function flushWrites ( ) { foreach ( $ this -> queuedForWrite as $ style ) { if ( $ style -> value && $ this -> uploadedFile -> isImage ( ) ) { $ file = $ this -> resizer -> resize ( $ this -> uploadedFile , $ style ) ; } else { $ file = $ this -> uploadedFile -> getRealPath ( ) ; } $ filePath = $ this -> path ( $ style -> name ) ; $ this -> move ( $ file , $ filePath ) ; } $ this -> queuedForWrite = array ( ) ; }
Process the queuedForWrite que .
31,734
public function getModels ( $ entities ) { $ models = array ( ) ; foreach ( $ entities as $ entity ) { $ models [ ] = $ this -> getModel ( $ entity ) ; } return $ models ; }
Convert given entities to models
31,735
public function getCreateForm ( $ requestOrDataArray , array $ options = array ( ) , $ entity = false ) { $ formBuilder = $ this -> Core -> getFormFactory ( ) ; if ( false === $ entity ) { $ newEntity = new $ this -> entityClass ( ) ; } else { $ newEntity = $ entity ; } $ createForm = $ formBuilder -> create ( new $ this -> createFormClass ( ) , $ newEntity , $ options ) ; if ( is_array ( $ requestOrDataArray ) ) { $ createForm -> submit ( $ requestOrDataArray ) ; } else { $ createForm -> handleRequest ( $ requestOrDataArray ) ; } return $ createForm ; }
Instantiate createForm populate it with request data if applicable
31,736
public function isFormValid ( $ form , $ throws = false ) { if ( ! $ form -> isValid ( ) ) { if ( $ throws ) { throw new ValidationException ( "Data validation failure" ) ; } return false ; } else { return true ; } }
Validate form with embedded data - is it valid?
31,737
public function delete ( $ Model ) { $ entity = $ Model -> getEntity ( ) ; $ entityId = $ entity -> getId ( ) ; if ( isset ( $ this -> cache [ $ entityId ] ) ) { unset ( $ this -> cache [ $ entityId ] ) ; } $ this -> em -> remove ( $ entity ) ; $ this -> em -> flush ( ) ; }
Delete given model instance handle cache invalidation too
31,738
public function __isset ( $ name ) { $ name = $ this -> convertToPrimaryKeyName ( $ name ) ; $ meta = self :: getMeta ( ) ; return $ meta -> hasField ( $ name ) ; }
Checks if a property value is null . This method overrides the parent implementation by checking if the named attribute is null or not .
31,739
public function updateRelated ( ) { foreach ( $ this -> related as $ name => $ value ) { if ( $ value instanceof Manager ) { continue ; } $ field = $ this -> getField ( $ name ) ; if ( $ field instanceof HasManyField ) { continue ; } if ( empty ( $ value ) ) { $ field -> getManager ( ) -> clean ( ) ; } else { $ field -> setValue ( $ value ) ; } } $ this -> related = [ ] ; }
Update related models .
31,740
public static function pluck ( array $ array , $ directions , $ safe = false ) { if ( ( is_string ( $ directions ) || is_int ( $ directions ) ) && isset ( $ array [ $ directions ] ) ) { return $ array [ $ directions ] ; } elseif ( is_array ( $ directions ) ) { if ( count ( $ directions ) === 1 ) { return static :: pluck ( $ array , $ directions [ 0 ] , $ safe ) ; } elseif ( isset ( $ array [ $ directions [ 0 ] ] ) ) { $ key = array_shift ( $ directions ) ; return static :: pluck ( $ array [ $ key ] , $ directions , $ safe ) ; } } if ( $ safe === true ) { return null ; } else { return new ZenodorusError ( [ 'code' => "pluck::not-found" , 'description' => "Arrays::pluck() could not find the value you're looking for." , 'data' => [ 'array' => $ array , 'directions' => $ directions ] , ] ) ; } }
Recursive function to get things from deep in multi - dimensional arrays .
31,741
public static function flatten ( $ array ) { if ( ! is_array ( $ array ) ) { return array ( $ array ) ; } $ result = array ( ) ; foreach ( $ array as $ value ) { $ result = array_merge ( $ result , static :: flatten ( $ value ) ) ; } return $ result ; }
Flatten a multidimensional array .
31,742
public static function isEmpty ( array $ array ) { $ flattened = static :: flatten ( $ array ) ; foreach ( $ flattened as $ item ) { if ( null === $ item || '' === $ item ) { continue ; } else { return false ; } } return true ; }
Tests if an array is empty .
31,743
public static function compact ( array $ array , bool $ treatNullAsTrue = false ) { $ compacted = array ( ) ; foreach ( $ array as $ key => $ field ) { if ( true === $ treatNullAsTrue ) { if ( $ field || null === $ field ) { $ compacted [ $ key ] = $ field ; } } else { if ( $ field ) { $ compacted [ $ key ] = $ field ; } } } return $ compacted ; }
This removes all falsey values from an array .
31,744
public static function removeByValue ( array $ array , ... $ values ) { foreach ( $ array as $ key => $ value ) { if ( in_array ( $ value , $ values , true ) ) { unset ( $ array [ $ key ] ) ; } } return $ array ; }
Remove items from an array based on their value . Keys are not changed .
31,745
public static function mapKeys ( callable $ function , array $ array ) { $ new_array = array ( ) ; foreach ( $ array as $ key => $ value ) { $ result = call_user_func ( $ function , $ value , $ key ) ; if ( is_array ( $ result ) ) { if ( 1 === count ( $ result ) ) { $ new_array [ $ key ] = array_shift ( $ result ) ; } elseif ( 2 === count ( $ result ) ) { $ new_array [ array_shift ( $ result ) ] = array_shift ( $ result ) ; } } unset ( $ result ) ; } return $ new_array ; }
array_map with keys OR array_walk but functional
31,746
public function missingIngredient ( ) : callable { return function ( IngredientInterface $ ingredient , string $ message ) : ChefInterface { $ this -> missingIngredients [ $ message ] = $ ingredient ; return $ this ; } ; }
To memorize a missing ingredients to stop the cooking of the recipe .
31,747
private function getNextStep ( ) : callable { return function ( string $ nextStep = null ) : ? BowlInterface { if ( ! empty ( $ nextStep ) && isset ( $ this -> stepsNames [ $ nextStep ] ) ) { $ this -> position = $ this -> stepsNames [ $ nextStep ] ; } if ( count ( $ this -> steps ) > $ this -> position ) { $ position = $ this -> position ; $ step = $ this -> steps [ $ position ] ; $ this -> position ++ ; return $ step ; } return null ; } ; }
To get the next step in the cooking to execute
31,748
public function continueRecipe ( ) : callable { return function ( array $ with = [ ] , string $ nextStep = null ) : ChefInterface { $ this -> updateMyWorkPlan ( $ with ) ; while ( ( $ callable = $ this -> getNextStep ( $ nextStep ) ) instanceof BowlInterface ) { try { $ callable -> execute ( $ this , $ this -> workPlan ) ; } catch ( \ Throwable $ error ) { $ this -> position = \ count ( $ this -> steps ) + 1 ; $ this -> callErrors ( $ error ) ; } $ nextStep = null ; } return $ this ; } ; }
Called by a step to continue the execution of the recipe but before update ingredients available on the workplan
31,749
public function finishRecipe ( ) : callable { return function ( $ result ) : ChefInterface { $ this -> recipe -> validate ( $ result ) ; $ this -> position = \ count ( $ this -> steps ) + 1 ; return $ this ; } ; }
Called by a step to stop the execution of the recipe and check if the dish is the result excepted .
31,750
private function prepare ( ) : callable { return function ( ) : void { $ this -> recipe -> prepare ( $ this -> workPlan , $ this ) ; $ this -> checkMissingIngredients ( ) ; $ this -> position = 0 ; } ; }
Internal method to prepare a cooking check is all ingredients are available .
31,751
private function checkMissingIngredients ( ) : callable { return function ( ) : void { if ( empty ( $ this -> missingIngredients ) ) { return ; } throw new \ RuntimeException ( 'Error, missing some ingredients : ' . implode ( ', ' , \ array_keys ( $ this -> missingIngredients ) ) ) ; } ; }
To check if the chef has memorized some missing ingredients
31,752
public function authorizationGrant ( & $ user , & $ user_auth_data , $ consumers , $ ldap_entry = NULL , $ user_save = TRUE ) { $ this -> filterOffPastAuthorizationRecords ( $ user , $ user_auth_data ) ; $ this -> grantsAndRevokes ( 'grant' , $ user , $ user_auth_data , $ consumers , $ ldap_entry , $ user_save ) ; }
grant authorizations to a user
31,753
public function authorizationRevoke ( & $ user , & $ user_auth_data , $ consumers , $ ldap_entry , $ user_save = TRUE ) { $ this -> filterOffPastAuthorizationRecords ( $ user , $ user_auth_data ) ; $ this -> grantsAndRevokes ( 'revoke' , $ user , $ user_auth_data , $ consumers , $ ldap_entry , $ user_save ) ; }
revoke authorizations to a user
31,754
public function filterOffPastAuthorizationRecords ( & $ user , & $ user_auth_data , $ time = NULL ) { if ( $ time != NULL || variable_get ( 'ldap_help_user_data_clear' , 0 ) ) { $ clear_time = ( $ time ) ? $ time : variable_get ( 'ldap_help_user_data_clear_set_date' , 0 ) ; if ( $ clear_time > 0 && $ clear_time < time ( ) ) { foreach ( $ user_auth_data as $ consumer_id => $ entry ) { if ( $ entry [ 'date_granted' ] < $ clear_time ) { unset ( $ user_auth_data [ $ consumer_id ] ) ; if ( isset ( $ user -> data [ 'ldap_authorizations' ] [ $ this -> consumerType ] [ $ consumer_id ] ) ) { unset ( $ user -> data [ 'ldap_authorizations' ] [ $ this -> consumerType ] [ $ consumer_id ] ) ; } } } } } }
this is a function to clear off
31,755
public function validateAuthorizationMappingTarget ( $ mapping , $ form_values = NULL , $ clear_cache = FALSE ) { $ message_type = NULL ; $ message_text = NULL ; return array ( $ message_type , $ message_text ) ; }
Validate authorization mappings on LDAP Authorization OG Admin form .
31,756
protected function loadAnnotationRoute ( $ pathinfo ) { @ list ( $ empty , $ pack , $ controller , $ method ) = explode ( '/' , $ pathinfo ) ; if ( ! isset ( $ this -> packs [ $ pack ] ) ) { return ; } if ( isset ( $ this -> map [ $ controller ] ) ) { $ controller = $ this -> map [ $ controller ] ; } $ controller = $ this -> underscoreToCamelCase ( $ controller , true ) ; $ fullClassName = $ this -> packs [ $ pack ] -> getNameSpace ( ) . '\\Controller\\' . $ controller ; if ( class_exists ( $ fullClassName ) ) { $ this -> resolver -> resolveController ( $ fullClassName , $ this -> packs [ $ pack ] ) ; } }
Tenta carregar uma rota anotada em um controlador de acordo com o pathinfo .
31,757
private function underscoreToCamelCase ( $ string , $ firstCharCaps = false ) { if ( $ firstCharCaps == true ) { $ string [ 0 ] = strtoupper ( $ string [ 0 ] ) ; } $ func = create_function ( '$c' , 'return strtoupper($c[1]);' ) ; return preg_replace_callback ( '/_([a-z])/' , $ func , $ string ) ; }
Convert strings with underscores into CamelCase .
31,758
public function check ( \ SplFileInfo $ file , Tokens $ tokens ) { $ classes = array_keys ( $ tokens -> findGivenKind ( T_CLASS ) ) ; $ numClasses = count ( $ classes ) ; for ( $ i = 0 ; $ i < $ numClasses ; ++ $ i ) { $ index = $ classes [ $ i ] ; $ classStart = $ tokens -> getNextTokenOfKind ( $ index , array ( '{' ) ) ; $ classEnd = $ tokens -> findBlockEnd ( Tokens :: BLOCK_TYPE_CURLY_BRACE , $ classStart ) ; $ this -> checkMethods ( $ tokens , $ classStart , $ classEnd ) ; } }
Checks a file .
31,759
public function getPeriodFirstDate ( $ periodValue ) { $ result = $ periodValue ; if ( $ this -> isPeriodYear ( $ periodValue ) ) { $ dt = date_create_from_format ( 'Y' , $ periodValue ) ; $ ts = strtotime ( 'first day of January' , $ dt -> getTimestamp ( ) ) ; $ dt = $ this -> toDateTime ( $ ts ) ; $ result = date_format ( $ dt , 'Ymd' ) ; } else { if ( $ this -> isPeriodMonth ( $ periodValue ) ) { $ dt = date_create_from_format ( 'Ymd' , $ periodValue . '01' ) ; $ ts = strtotime ( 'first day of' , $ dt -> getTimestamp ( ) ) ; $ dt = $ this -> toDateTime ( $ ts ) ; $ result = date_format ( $ dt , 'Ymd' ) ; } } return $ result ; }
Return the datestamp for the first date of the month or year period .
31,760
protected function initDerivedProperties ( $ bindpw ) { if ( ! $ this -> basedn ) { $ this -> basedn = array ( ) ; } elseif ( is_array ( $ this -> basedn ) ) { } else { $ basedn_unserialized = @ unserialize ( $ this -> basedn ) ; if ( is_array ( $ basedn_unserialized ) ) { $ this -> basedn = $ basedn_unserialized ; } else { $ this -> basedn = array ( ) ; $ token = is_scalar ( $ basedn_unserialized ) ? $ basedn_unserialized : print_r ( $ basedn_unserialized , TRUE ) ; debug ( "basednb desearialization error" . $ token ) ; watchdog ( 'ldap_server' , 'Failed to deserialize LdapServer::basedn of !basedn' , array ( '!basedn' => $ token ) , WATCHDOG_ERROR ) ; } } if ( $ this -> followrefs && ! function_exists ( 'ldap_set_rebind_proc' ) ) { $ this -> followrefs = FALSE ; } if ( $ bindpw ) { $ this -> bindpw = ldap_servers_decrypt ( $ bindpw ) ; } $ this -> paginationEnabled = ( boolean ) ( ldap_servers_php_supports_pagination ( ) && $ this -> searchPagination ) ; $ this -> queriableWithoutUserCredentials = ( boolean ) ( $ this -> bind_method == LDAP_SERVERS_BIND_METHOD_SERVICE_ACCT || $ this -> bind_method == LDAP_SERVERS_BIND_METHOD_ANON_USER ) ; $ this -> editPath = ( ! $ this -> sid ) ? '' : 'admin/config/people/ldap/servers/edit/' . $ this -> sid ; $ this -> groupGroupEntryMembershipsConfigured = ( $ this -> groupMembershipsAttrMatchingUserAttr && $ this -> groupMembershipsAttr ) ; $ this -> groupUserMembershipsConfigured = ( $ this -> groupUserMembershipsAttrExists && $ this -> groupUserMembershipsAttr ) ; }
this method sets properties that don t directly map from db record . it is split out so it can be shared with ldapServerTest . class . php
31,761
public function createLdapEntry ( $ attributes , $ dn = NULL ) { if ( ! $ this -> connection ) { $ this -> connect ( ) ; $ this -> bind ( ) ; } if ( isset ( $ attributes [ 'dn' ] ) ) { $ dn = $ attributes [ 'dn' ] ; unset ( $ attributes [ 'dn' ] ) ; } elseif ( ! $ dn ) { return FALSE ; } $ result = @ ldap_add ( $ this -> connection , $ dn , $ attributes ) ; if ( ! $ result ) { $ error = "LDAP Server ldap_add(%dn) Error Server ID = %sid, LDAP Err No: %ldap_errno LDAP Err Message: %ldap_err2str " ; $ tokens = array ( '%dn' => $ dn , '%sid' => $ this -> sid , '%ldap_errno' => ldap_errno ( $ this -> connection ) , '%ldap_err2str' => ldap_err2str ( ldap_errno ( $ this -> connection ) ) ) ; debug ( t ( $ error , $ tokens ) ) ; watchdog ( 'ldap_server' , $ error , $ tokens , WATCHDOG_ERROR ) ; } return $ result ; }
create ldap entry .
31,762
static public function removeUnchangedAttributes ( $ new_entry , $ old_entry ) { foreach ( $ new_entry as $ key => $ new_val ) { $ old_value = FALSE ; $ key_lcase = drupal_strtolower ( $ key ) ; if ( isset ( $ old_entry [ $ key_lcase ] ) ) { if ( $ old_entry [ $ key_lcase ] [ 'count' ] == 1 ) { $ old_value = $ old_entry [ $ key_lcase ] [ 0 ] ; $ old_value_is_scalar = TRUE ; } else { unset ( $ old_entry [ $ key_lcase ] [ 'count' ] ) ; $ old_value = $ old_entry [ $ key_lcase ] ; $ old_value_is_scalar = FALSE ; } } if ( is_array ( $ new_val ) && is_array ( $ old_value ) && count ( array_diff ( $ new_val , $ old_value ) ) == 0 ) { unset ( $ new_entry [ $ key ] ) ; } elseif ( $ old_value_is_scalar && ! is_array ( $ new_val ) && drupal_strtolower ( $ old_value ) == drupal_strtolower ( $ new_val ) ) { unset ( $ new_entry [ $ key ] ) ; } } return $ new_entry ; }
given 2 ldap entries old and new removed unchanged values to avoid security errors and incorrect date modifieds
31,763
public function delete ( $ dn ) { if ( ! $ this -> connection ) { $ this -> connect ( ) ; $ this -> bind ( ) ; } $ result = @ ldap_delete ( $ this -> connection , $ dn ) ; if ( ! $ result ) { $ error = "LDAP Server delete(%dn) in LdapServer::delete() Error Server ID = %sid, LDAP Err No: %ldap_errno LDAP Err Message: %ldap_err2str " ; $ tokens = array ( '%dn' => $ dn , '%sid' => $ this -> sid , '%ldap_errno' => ldap_errno ( $ this -> connection ) , '%ldap_err2str' => ldap_err2str ( ldap_errno ( $ this -> connection ) ) ) ; watchdog ( 'ldap_server' , $ error , $ tokens , WATCHDOG_ERROR ) ; } return $ result ; }
Perform an LDAP delete .
31,764
public function searchAllBaseDns ( $ filter , $ attributes = array ( ) , $ attrsonly = 0 , $ sizelimit = 0 , $ timelimit = 0 , $ deref = NULL , $ scope = LDAP_SCOPE_SUBTREE ) { $ all_entries = array ( ) ; foreach ( $ this -> basedn as $ base_dn ) { $ entries = $ this -> search ( $ base_dn , $ filter , $ attributes , $ attrsonly , $ sizelimit , $ timelimit , $ deref , $ scope ) ; if ( $ entries === FALSE ) { return FALSE ; } if ( count ( $ all_entries ) == 0 ) { $ all_entries = $ entries ; unset ( $ all_entries [ 'count' ] ) ; } else { $ existing_count = count ( $ all_entries ) ; unset ( $ entries [ 'count' ] ) ; foreach ( $ entries as $ i => $ entry ) { $ all_entries [ $ existing_count + $ i ] = $ entry ; } } } $ all_entries [ 'count' ] = count ( $ all_entries ) ; return $ all_entries ; }
Perform an LDAP search on all base dns and aggregate into one result
31,765
function ldapQuery ( $ scope , $ params ) { $ this -> connectAndBindIfNotAlready ( ) ; switch ( $ scope ) { case LDAP_SCOPE_SUBTREE : $ result = @ ldap_search ( $ this -> connection , $ params [ 'base_dn' ] , $ params [ 'filter' ] , $ params [ 'attributes' ] , $ params [ 'attrsonly' ] , $ params [ 'sizelimit' ] , $ params [ 'timelimit' ] , $ params [ 'deref' ] ) ; if ( $ params [ 'sizelimit' ] && $ this -> ldapErrorNumber ( ) == LDAP_SIZELIMIT_EXCEEDED ) { } elseif ( $ this -> hasError ( ) ) { watchdog ( 'ldap_server' , 'ldap_search() function error. LDAP Error: %message, ldap_search() parameters: %query' , array ( '%message' => $ this -> errorMsg ( 'ldap' ) , '%query' => $ params [ 'query_display' ] ) , WATCHDOG_ERROR ) ; } break ; case LDAP_SCOPE_BASE : $ result = @ ldap_read ( $ this -> connection , $ params [ 'base_dn' ] , $ params [ 'filter' ] , $ params [ 'attributes' ] , $ params [ 'attrsonly' ] , $ params [ 'sizelimit' ] , $ params [ 'timelimit' ] , $ params [ 'deref' ] ) ; if ( $ params [ 'sizelimit' ] && $ this -> ldapErrorNumber ( ) == LDAP_SIZELIMIT_EXCEEDED ) { } elseif ( $ this -> hasError ( ) ) { watchdog ( 'ldap_server' , 'ldap_read() function error. LDAP Error: %message, ldap_read() parameters: %query' , array ( '%message' => $ this -> errorMsg ( 'ldap' ) , '%query' => @ $ params [ 'query_display' ] ) , WATCHDOG_ERROR ) ; } break ; case LDAP_SCOPE_ONELEVEL : $ result = @ ldap_list ( $ this -> connection , $ params [ 'base_dn' ] , $ params [ 'filter' ] , $ params [ 'attributes' ] , $ params [ 'attrsonly' ] , $ params [ 'sizelimit' ] , $ params [ 'timelimit' ] , $ params [ 'deref' ] ) ; if ( $ params [ 'sizelimit' ] && $ this -> ldapErrorNumber ( ) == LDAP_SIZELIMIT_EXCEEDED ) { } elseif ( $ this -> hasError ( ) ) { watchdog ( 'ldap_server' , 'ldap_list() function error. LDAP Error: %message, ldap_list() parameters: %query' , array ( '%message' => $ this -> errorMsg ( 'ldap' ) , '%query' => $ params [ 'query_display' ] ) , WATCHDOG_ERROR ) ; } break ; } return $ result ; }
execute ldap query and return ldap records
31,766
function userUserNameToExistingLdapEntry ( $ drupal_user_name , $ ldap_context = NULL ) { $ watchdog_tokens = array ( '%drupal_user_name' => $ drupal_user_name ) ; $ ldap_username = $ this -> userUsernameToLdapNameTransform ( $ drupal_user_name , $ watchdog_tokens ) ; if ( ! $ ldap_username ) { return FALSE ; } if ( ! $ ldap_context ) { $ attributes = array ( ) ; } else { $ attribute_maps = ldap_servers_attributes_needed ( $ this -> sid , $ ldap_context ) ; $ attributes = array_keys ( $ attribute_maps ) ; } foreach ( $ this -> basedn as $ basedn ) { if ( empty ( $ basedn ) ) continue ; $ filter = '(' . $ this -> user_attr . '=' . ldap_server_massage_text ( $ ldap_username , 'attr_value' , LDAP_SERVER_MASSAGE_QUERY_LDAP ) . ')' ; $ result = $ this -> search ( $ basedn , $ filter , $ attributes ) ; if ( ! $ result || ! isset ( $ result [ 'count' ] ) || ! $ result [ 'count' ] ) continue ; if ( $ result [ 'count' ] != 1 ) { $ count = $ result [ 'count' ] ; watchdog ( 'ldap_servers' , "Error: !count users found with $filter under $basedn." , array ( '!count' => $ count ) , WATCHDOG_ERROR ) ; continue ; } $ match = $ result [ 0 ] ; $ name_attr = $ this -> user_attr ; if ( isset ( $ match [ $ name_attr ] [ 0 ] ) ) { } elseif ( isset ( $ match [ drupal_strtolower ( $ name_attr ) ] [ 0 ] ) ) { $ name_attr = drupal_strtolower ( $ name_attr ) ; } else { if ( $ this -> bind_method == LDAP_SERVERS_BIND_METHOD_ANON_USER ) { $ result = array ( 'dn' => $ match [ 'dn' ] , 'mail' => $ this -> userEmailFromLdapEntry ( $ match ) , 'attr' => $ match , 'sid' => $ this -> sid , ) ; return $ result ; } else { continue ; } } foreach ( $ match [ $ name_attr ] as $ value ) { if ( drupal_strtolower ( trim ( $ value ) ) == drupal_strtolower ( $ ldap_username ) ) { $ result = array ( 'dn' => $ match [ 'dn' ] , 'mail' => $ this -> userEmailFromLdapEntry ( $ match ) , 'attr' => $ match , 'sid' => $ this -> sid , ) ; return $ result ; } } } }
Queries LDAP server for the user .
31,767
public function groupIsMember ( $ group_dn , $ user , $ nested = NULL ) { $ nested = ( $ nested === TRUE || $ nested === FALSE ) ? $ nested : $ this -> groupNested ; $ group_dns = $ this -> groupMembershipsFromUser ( $ user , 'group_dns' , $ nested ) ; return ( is_array ( $ group_dns ) && in_array ( drupal_strtolower ( $ group_dn ) , $ this -> dnArrayToLowerCase ( $ group_dns ) ) ) ; }
Is a user a member of group?
31,768
public function groupAddGroup ( $ group_dn , $ attributes = array ( ) ) { if ( $ this -> dnExists ( $ group_dn , 'boolean' ) ) { return FALSE ; } $ attributes = array_change_key_case ( $ attributes , CASE_LOWER ) ; $ objectclass = ( empty ( $ attributes [ 'objectclass' ] ) ) ? $ this -> groupObjectClass : $ attributes [ 'objectclass' ] ; $ attributes [ 'objectclass' ] = $ objectclass ; $ context = array ( 'action' => 'add' , 'corresponding_drupal_data' => array ( $ group_dn => $ attributes ) , 'corresponding_drupal_data_type' => 'group' , ) ; $ ldap_entries = array ( $ group_dn => $ attributes ) ; drupal_alter ( 'ldap_entry_pre_provision' , $ ldap_entries , $ this , $ context ) ; $ attributes = $ ldap_entries [ $ group_dn ] ; $ ldap_entry_created = $ this -> createLdapEntry ( $ attributes , $ group_dn ) ; if ( $ ldap_entry_created ) { module_invoke_all ( 'ldap_entry_post_provision' , $ ldap_entries , $ this , $ context ) ; return TRUE ; } else { return FALSE ; } }
NOT TESTED add a group entry
31,769
public function groupRemoveGroup ( $ group_dn , $ only_if_group_empty = TRUE ) { if ( $ only_if_group_empty ) { $ members = $ this -> groupAllMembers ( $ group_dn ) ; if ( is_array ( $ members ) && count ( $ members ) > 0 ) { return FALSE ; } } return $ this -> delete ( $ group_dn ) ; }
NOT TESTED remove a group entry
31,770
public function groupAddMember ( $ group_dn , $ user ) { $ user_ldap_entry = $ this -> userUserToExistingLdapEntry ( $ user ) ; $ result = FALSE ; if ( $ user_ldap_entry && $ this -> groupGroupEntryMembershipsConfigured ) { $ add = array ( ) ; $ add [ $ this -> groupMembershipsAttr ] = $ user_ldap_entry [ 'dn' ] ; $ this -> connectAndBindIfNotAlready ( ) ; $ result = @ ldap_mod_add ( $ this -> connection , $ group_dn , $ add ) ; } return $ result ; }
NOT TESTED add a member to a group
31,771
public function groupRemoveMember ( $ group_dn , $ user ) { $ user_ldap_entry = $ this -> userUserToExistingLdapEntry ( $ user ) ; $ result = FALSE ; if ( $ user_ldap_entry && $ this -> groupGroupEntryMembershipsConfigured ) { $ del = array ( ) ; $ del [ $ this -> groupMembershipsAttr ] = $ user_ldap_entry [ 'dn' ] ; $ this -> connectAndBindIfNotAlready ( ) ; $ result = @ ldap_mod_del ( $ this -> connection , $ group_dn , $ del ) ; } return $ result ; }
NOT TESTED remove a member from a group
31,772
public function groupMembersResursive ( $ current_member_entries , & $ all_member_dns , & $ tested_group_ids , $ level , $ max_levels , $ object_classes = FALSE ) { if ( ! $ this -> groupGroupEntryMembershipsConfigured || ! is_array ( $ current_member_entries ) || count ( $ current_member_entries ) == 0 ) { return FALSE ; } if ( isset ( $ current_member_entries [ 'count' ] ) ) { unset ( $ current_member_entries [ 'count' ] ) ; } ; foreach ( $ current_member_entries as $ i => $ member_entry ) { $ objectClassMatch = ( ! $ object_classes || ( count ( array_intersect ( array_values ( $ member_entry [ 'objectclass' ] ) , $ object_classes ) ) > 0 ) ) ; $ objectIsGroup = in_array ( $ this -> groupObjectClass , array_values ( $ member_entry [ 'objectclass' ] ) ) ; if ( $ objectClassMatch && ! in_array ( $ member_entry [ 'dn' ] , $ all_member_dns ) ) { $ all_member_dns [ ] = $ member_entry [ 'dn' ] ; } if ( $ objectIsGroup && $ level < $ max_levels ) { if ( $ this -> groupMembershipsAttrMatchingUserAttr == 'dn' ) { $ group_id = $ member_entry [ 'dn' ] ; } else { $ group_id = $ member_entry [ $ this -> groupMembershipsAttrMatchingUserAttr ] [ 0 ] ; } if ( ! in_array ( $ group_id , $ tested_group_ids ) ) { $ tested_group_ids [ ] = $ group_id ; $ member_ids = $ member_entry [ $ this -> groupMembershipsAttr ] ; if ( isset ( $ member_ids [ 'count' ] ) ) { unset ( $ member_ids [ 'count' ] ) ; } ; $ ors = array ( ) ; foreach ( $ member_ids as $ i => $ member_id ) { $ ors [ ] = $ this -> groupMembershipsAttr . '=' . ldap_pear_escape_filter_value ( $ member_id ) ; } if ( count ( $ ors ) ) { $ query_for_child_members = '(|(' . join ( ")(" , $ ors ) . '))' ; if ( count ( $ object_classes ) ) { $ object_classes_ors = array ( '(objectClass=' . $ this -> groupObjectClass . ')' ) ; foreach ( $ object_classes as $ object_class ) { $ object_classes_ors [ ] = '(objectClass=' . $ object_class . ')' ; } $ query_for_child_members = '&(|' . join ( $ object_classes_ors ) . ')(' . $ query_for_child_members . ')' ; } foreach ( $ this -> basedn as $ base_dn ) { $ child_member_entries = $ this -> search ( $ base_dn , $ query_for_child_members , array ( 'objectclass' , $ this -> groupMembershipsAttr , $ this -> groupMembershipsAttrMatchingUserAttr ) ) ; if ( $ child_member_entries !== FALSE ) { $ this -> groupMembersResursive ( $ child_member_entries , $ all_member_dns , $ tested_group_ids , $ level + 1 , $ max_levels , $ object_classes ) ; } } } } } } }
NOT IMPLEMENTED recurse through all child groups and add members .
31,773
public function groupUserMembershipsFromUserAttr ( $ user , $ nested = NULL ) { if ( ! $ this -> groupUserMembershipsConfigured ) { return FALSE ; } if ( $ nested === NULL ) { $ nested = $ this -> groupNested ; } $ not_user_ldap_entry = empty ( $ user [ 'attr' ] [ $ this -> groupUserMembershipsAttr ] ) ; if ( $ not_user_ldap_entry ) { $ user = $ this -> userUserToExistingLdapEntry ( $ user ) ; $ not_user_ldap_entry = empty ( $ user [ 'attr' ] [ $ this -> groupUserMembershipsAttr ] ) ; if ( $ not_user_ldap_entry ) { return FALSE ; } } $ user_ldap_entry = $ user ; $ all_group_dns = array ( ) ; $ tested_group_ids = array ( ) ; $ level = 0 ; $ member_group_dns = $ user_ldap_entry [ 'attr' ] [ $ this -> groupUserMembershipsAttr ] ; if ( isset ( $ member_group_dns [ 'count' ] ) ) { unset ( $ member_group_dns [ 'count' ] ) ; } $ ors = array ( ) ; foreach ( $ member_group_dns as $ i => $ member_group_dn ) { $ all_group_dns [ ] = $ member_group_dn ; if ( $ nested ) { if ( $ this -> groupMembershipsAttrMatchingUserAttr == 'dn' ) { $ member_value = $ member_group_dn ; } else { $ member_value = ldap_servers_get_first_rdn_value_from_dn ( $ member_group_dn , $ this -> groupMembershipsAttrMatchingUserAttr ) ; } $ ors [ ] = $ this -> groupMembershipsAttr . '=' . ldap_pear_escape_filter_value ( $ member_value ) ; } } if ( $ nested && count ( $ ors ) ) { $ count = count ( $ ors ) ; for ( $ i = 0 ; $ i < $ count ; $ i = $ i + LDAP_SERVER_LDAP_QUERY_CHUNK ) { $ current_ors = array_slice ( $ ors , $ i , LDAP_SERVER_LDAP_QUERY_CHUNK ) ; $ or = '(|(' . join ( ")(" , $ current_ors ) . '))' ; $ query_for_parent_groups = '(&(objectClass=' . $ this -> groupObjectClass . ')' . $ or . ')' ; foreach ( $ this -> basedn as $ base_dn ) { $ group_entries = $ this -> search ( $ base_dn , $ query_for_parent_groups ) ; if ( $ group_entries !== FALSE && $ level < LDAP_SERVER_LDAP_QUERY_RECURSION_LIMIT ) { $ this -> groupMembershipsFromEntryRecursive ( $ group_entries , $ all_group_dns , $ tested_group_ids , $ level + 1 , LDAP_SERVER_LDAP_QUERY_RECURSION_LIMIT ) ; } } } } return $ all_group_dns ; }
get list of all groups that a user is a member of by using memberOf attribute first then if nesting is true using group entries to find parent groups
31,774
public function groupUserMembershipsFromEntry ( $ user , $ nested = NULL ) { if ( ! $ this -> groupGroupEntryMembershipsConfigured ) { return FALSE ; } if ( $ nested === NULL ) { $ nested = $ this -> groupNested ; } $ user_ldap_entry = $ this -> userUserToExistingLdapEntry ( $ user ) ; $ all_group_dns = array ( ) ; $ tested_group_ids = array ( ) ; $ level = 0 ; if ( $ this -> groupMembershipsAttrMatchingUserAttr == 'dn' ) { $ member_value = $ user_ldap_entry [ 'dn' ] ; } else { $ member_value = $ user_ldap_entry [ 'attr' ] [ $ this -> groupMembershipsAttrMatchingUserAttr ] [ 0 ] ; } $ member_value = ldap_pear_escape_filter_value ( $ member_value ) ; if ( $ this -> groupObjectClass == '' ) { $ group_query = '(' . $ this -> groupMembershipsAttr . "=$member_value)" ; } else { $ group_query = '(&(objectClass=' . $ this -> groupObjectClass . ')(' . $ this -> groupMembershipsAttr . "=$member_value))" ; } foreach ( $ this -> basedn as $ base_dn ) { $ group_entries = $ this -> search ( $ base_dn , $ group_query , array ( ) ) ; if ( $ group_entries !== FALSE ) { $ max_levels = ( $ nested ) ? LDAP_SERVER_LDAP_QUERY_RECURSION_LIMIT : 0 ; $ this -> groupMembershipsFromEntryRecursive ( $ group_entries , $ all_group_dns , $ tested_group_ids , $ level , $ max_levels ) ; } } return $ all_group_dns ; }
get list of all groups that a user is a member of by querying groups
31,775
public function groupUserMembershipsFromDn ( $ user ) { if ( ! $ this -> groupDeriveFromDn || ! $ this -> groupDeriveFromDnAttr ) { return FALSE ; } elseif ( $ user_ldap_entry = $ this -> userUserToExistingLdapEntry ( $ user ) ) { return ldap_servers_get_all_rdn_values_from_dn ( $ user_ldap_entry [ 'dn' ] , $ this -> groupDeriveFromDnAttr ) ; } else { return FALSE ; } }
get groups from derived from DN . Has limited usefulness
31,776
function Check ( $ value ) { $ success = true ; $ strings = System \ Str :: SplitLines ( $ value ) ; foreach ( $ strings as $ string ) { $ success = parent :: Check ( $ string ) ; if ( ! $ success ) break ; } $ this -> SetValue ( $ value ) ; return $ success ; }
Checks each line of the given value with the given validators
31,777
public function getPublication ( ) { if ( is_null ( $ this -> getStartedAt ( ) ) && is_null ( $ this -> getEndedAt ( ) ) ) { return 'Never published' ; } elseif ( ! is_null ( $ this -> getStartedAt ( ) ) && $ this -> getStartedAt ( ) -> getTimestamp ( ) <= time ( ) && is_null ( $ this -> getEndedAt ( ) ) ) { return 'Published' ; } elseif ( ! is_null ( $ this -> getStartedAt ( ) ) && $ this -> getStartedAt ( ) -> getTimestamp ( ) > time ( ) ) { return 'Pre-published' ; } elseif ( ! is_null ( $ this -> getStartedAt ( ) ) && $ this -> getStartedAt ( ) -> getTimestamp ( ) < time ( ) && ! is_null ( $ this -> getEndedAt ( ) ) && $ this -> getEndedAt ( ) -> getTimestamp ( ) < time ( ) ) { return 'Post-published' ; } elseif ( ! is_null ( $ this -> getStartedAt ( ) ) && $ this -> getStartedAt ( ) -> getTimestamp ( ) <= time ( ) && ! is_null ( $ this -> getEndedAt ( ) ) && $ this -> getEndedAt ( ) -> getTimestamp ( ) >= time ( ) ) { return 'Published temp' ; } }
Get publication state
31,778
public function isPublicationValid ( ExecutionContextInterface $ context ) { if ( ! $ this -> getStartedAt ( ) && $ this -> getEndedAt ( ) ) { $ context -> addViolationAt ( 'startedAt' , 'Start publication date is required when setting end publication date.' ) ; } if ( $ this -> getEndedAt ( ) && $ this -> getStartedAt ( ) && $ this -> getStartedAt ( ) -> getTimestamp ( ) >= $ this -> getEndedAt ( ) -> getTimestamp ( ) ) { $ context -> addViolationAt ( 'endedAt' , 'End publication date must be later than start publication date.' ) ; } }
Check if publication is correct
31,779
public function isPublished ( ) { return $ this -> getStartedAt ( ) && $ this -> getStartedAt ( ) -> getTimestamp ( ) <= time ( ) && ( ! $ this -> getEndedAt ( ) || $ this -> getEndedAt ( ) -> getTimestamp ( ) >= time ( ) ) ; }
Check if element is published
31,780
public function setOptions ( iterable $ options ) : void { foreach ( $ options as $ optionKey => $ optionValue ) { $ this -> setOption ( $ optionKey , $ optionValue ) ; } }
Sets multiple loader options at once
31,781
public function setOption ( string $ key , $ value ) : void { if ( array_key_exists ( $ key , $ this -> options ) ) { $ this -> options [ $ key ] = $ value ; return ; } throw new Exception ( 'Invalid option key "' . $ key . '".' , Exception :: INVALID_OPTION ) ; }
Sets an loader option value
31,782
public function getOption ( string $ key ) { if ( array_key_exists ( $ key , $ this -> options ) ) { return $ this -> options [ $ key ] ; } throw new Exception ( 'Invalid option key "' . $ key . '".' , Exception :: INVALID_OPTION ) ; }
Gets an loader option value
31,783
public function setLocalFile ( string $ filename ) : void { if ( empty ( $ filename ) ) { throw new Exception ( 'the filename can not be empty' , Exception :: LOCAL_FILE_MISSING ) ; } $ this -> localFile = $ filename ; $ this -> loader = null ; }
sets the name of the local file
31,784
private function getLoader ( ) : LoaderInterface { if ( null !== $ this -> loader ) { return $ this -> loader ; } if ( null !== $ this -> localFile ) { $ this -> loader = new Local ( $ this -> localFile ) ; return $ this -> loader ; } if ( extension_loaded ( 'curl' ) ) { $ this -> loader = new Curl ( $ this ) ; return $ this -> loader ; } $ streamHelper = new StreamCreator ( $ this ) ; if ( ini_get ( 'allow_url_fopen' ) ) { $ this -> loader = new FopenLoader ( $ this , $ streamHelper ) ; return $ this -> loader ; } $ this -> loader = new SocketLoader ( $ this , $ streamHelper ) ; return $ this -> loader ; }
return the actual used loader
31,785
public function objectsList ( $ filter = null , $ params = null ) { Splash :: log ( ) -> trace ( ) ; $ queryBuilder = $ this -> repository -> createQueryBuilder ( 'c' ) ; if ( isset ( $ params [ 'offset' ] ) && is_int ( $ params [ 'offset' ] ) ) { $ queryBuilder -> setFirstResult ( $ params [ 'offset' ] ) ; } if ( isset ( $ params [ 'max' ] ) && is_int ( $ params [ 'max' ] ) ) { $ queryBuilder -> setMaxResults ( $ params [ 'max' ] ) ; } if ( ! empty ( $ filter ) ) { } $ rawData = $ queryBuilder -> getQuery ( ) -> getResult ( ) ; $ response = array ( ) ; foreach ( $ rawData as $ object ) { $ response [ ] = $ this -> getObjectListArray ( $ object ) ; } $ response [ 'meta' ] = array ( 'total' => count ( $ rawData ) , 'current' => $ this -> getTotalCount ( ) , ) ; return $ response ; }
Return List Of Objects with required filters
31,786
final public function getHandleStack ( $ request = null ) { if ( ! is_array ( $ this -> handleStack ) ) { $ this -> handleStack = [ ] ; $ request || $ request = static :: getApp ( ) -> getRequest ( ) ; $ handler = $ this -> getHandler ( ) ; $ requestMethod = ucfirst ( strtolower ( $ request -> getMethod ( ) ) ) ; $ action = $ this -> getCamelCaseAction ( ) ; if ( ! $ this -> handleStack ) { if ( $ requestMethod === 'Options' ) { array_push ( $ this -> handleStack , 'doOptions' ) ; } else { $ actions = [ ] ; $ actions [ ] = 'do' . $ requestMethod . ( $ action && $ action !== 'index' ? ucfirst ( $ action ) : '' ) ; if ( $ requestMethod === 'Get' ) { if ( ! $ action || $ action == 'index' ) { $ actions [ ] = 'index' ; } else { if ( ! $ this -> isForbiddenMethod ( $ action ) ) { $ actions [ ] = $ action ; } } } foreach ( $ actions as $ method ) { if ( method_exists ( $ handler , $ method ) ) { array_push ( $ this -> handleStack , $ method ) ; break ; } } } if ( $ this -> handleStack && in_array ( $ requestMethod , [ 'Get' , 'Post' ] ) && $ this -> getHandler ( ) instanceof \ Wslim \ Common \ Controller ) { $ this -> handleStack = array_merge ( [ 'init' , 'before' . $ requestMethod ] , $ this -> handleStack ) ; } } } return $ this -> handleStack ; }
get handle stack
31,787
protected function _outputHandle ( $ output = null ) { if ( $ output === null ) { } elseif ( $ output instanceof ResponseInterface ) { $ this -> response = $ output ; } elseif ( $ output ) { if ( is_scalar ( $ output ) ) { $ this -> response = $ this -> renderText ( $ output ) ; } elseif ( is_array ( $ output ) ) { $ this -> response = $ this -> renderJson ( $ output ) ; } elseif ( $ output instanceof Collection ) { $ this -> response = $ this -> renderJson ( $ output -> all ( ) ) ; } } if ( $ data = $ this -> getRenderBuffer ( ) ) { $ this -> response -> write ( $ data ) ; } return $ this -> response ; }
final handle output
31,788
protected function beforeRender ( $ data = null ) { if ( ! Config :: get ( 'debug' ) ) { } $ this -> clearRenderBuffer ( ) ; $ data && $ this -> responseData ( $ data ) ; }
before render handle ob and response data .
31,789
public static function getFromString ( $ perm ) { list ( $ app , $ code ) = explode ( '.' , trim ( $ perm ) ) ; $ sql = new Pluf_SQL ( 'code_name=%s AND application=%s' , array ( $ code , $ app ) ) ; $ permModel = new User_Role ( ) ; $ perms = $ permModel -> getList ( array ( 'filter' => $ sql -> gen ( ) ) ) ; if ( $ perms -> count ( ) != 1 ) { if ( Pluf :: f ( 'core_permession_autoCreate' , true ) ) { $ permModel -> code_name = $ code ; $ permModel -> application = $ app ; if ( $ permModel -> create ( ) ) { return $ permModel ; } } return false ; } return $ perms [ 0 ] ; }
Get the matching permission object from the permission string .
31,790
public function setDate ( \ DateTimeInterface $ date ) { $ this -> getDomElement ( ) -> nodeValue = $ date -> format ( \ DateTime :: RFC3339 ) ; $ this -> setCachedProperty ( 'content' , $ date ) ; }
Set new date .
31,791
public function addDependency ( $ id , $ className , $ constructor , Doozr_Di_Dependency $ dependency ) { $ this -> initDependenciesById ( $ id ) ; $ this -> initIndexByClassName ( $ className ) ; $ this -> dependenciesById [ $ id ] [ ] = $ dependency ; $ index = count ( $ this -> dependenciesById [ $ id ] ) - 1 ; $ this -> indexedByClassName [ $ className ] [ ] = & $ this -> dependenciesById [ $ id ] [ $ index ] ; $ this -> classNameById [ $ id ] = $ className ; $ this -> constructorById [ $ id ] = $ constructor ; $ this -> numericalIndex = array_keys ( $ this -> dependenciesById ) ; return true ; }
Adds a dependency to collection and indexes it by id className .
31,792
public function reset ( ) { $ this -> position = 0 ; $ this -> mapIdToClassName = [ ] ; $ this -> numericalIndex = [ ] ; $ this -> argumentsById = [ ] ; $ this -> constructorById = [ ] ; $ this -> classNameById = [ ] ; $ this -> dependenciesById = [ ] ; $ this -> indexedByClassName = [ ] ; }
Resets the internal state from ? to clean .
31,793
public function addDependencies ( $ id , $ className , $ constructor , array $ dependencies ) { $ result = true ; foreach ( $ dependencies as $ dependency ) { $ result = $ result && $ this -> addDependency ( $ id , $ className , $ constructor , $ dependency ) ; if ( false === $ result ) { throw new Doozr_Di_Exception ( sprintf ( 'Dependencies could not be added! The dependency with target: "%s" produced an error. ' . 'No Dependencies added.' , $ dependency -> getTarget ( ) ) ) ; } } return $ result ; }
Adds a collection of dependencies to existing collection .
31,794
public function getArguments ( $ id ) { return ( isset ( $ this -> argumentsById [ $ id ] ) ) ? $ this -> argumentsById [ $ id ] : null ; }
Returns the arguments required to pass to a class having dependencies .
31,795
public function getConstructorById ( $ id ) { return ( isset ( $ this -> constructorById [ $ id ] ) ) ? $ this -> constructorById [ $ id ] : null ; }
Getter for constructor .
31,796
public function getRecipeById ( $ id ) { $ result = [ 'className' => ( isset ( $ this -> classNameById [ $ id ] ) ) ? $ this -> classNameById [ $ id ] : null , 'arguments' => ( isset ( $ this -> argumentsById [ $ id ] ) ) ? $ this -> argumentsById [ $ id ] : null , 'constructor' => ( isset ( $ this -> constructorById [ $ id ] ) ) ? $ this -> constructorById [ $ id ] : null , 'dependencies' => ( isset ( $ this -> dependenciesById [ $ id ] ) ) ? $ this -> dependenciesById [ $ id ] : null , ] ; return $ result ; }
Returns the recipe by id .
31,797
public function getClassNameById ( $ id ) { return ( isset ( $ this -> classNameById [ $ id ] ) ) ? $ this -> classNameById [ $ id ] : null ; }
Returns the className for a passed Id .
31,798
public function getDependencies ( $ id ) { return ( isset ( $ this -> dependenciesById [ $ id ] ) ) ? $ this -> dependenciesById [ $ id ] : null ; }
Returns dependencies for passed id .
31,799
protected function initDependenciesById ( $ id ) { if ( false === isset ( $ this -> dependenciesById [ $ id ] ) ) { $ this -> dependenciesById [ $ id ] = [ ] ; } }
Initializes the index by id .