idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
27,500
public function setServiceLocator ( ContainerInterface $ container ) { trigger_error ( sprintf ( 'Usage of %s is deprecated since v3.0.0; please pass the container to the constructor instead' , __METHOD__ ) , E_USER_DEPRECATED ) ; $ this -> creationContext = $ container ; }
Implemented for backwards compatibility only .
27,501
public static function getCategoryAssociations ( $ id = 0 , $ extension = 'com_content' ) { $ return = array ( ) ; if ( $ id ) { jimport ( 'helper.route' , JPATH_COMPONENT_SITE ) ; $ helperClassname = ucfirst ( substr ( $ extension , 4 ) ) . 'HelperRoute' ; $ associations = CategoriesHelper :: getAssociations ( $ id , $ extension ) ; foreach ( $ associations as $ tag => $ item ) { if ( class_exists ( $ helperClassname ) && is_callable ( array ( $ helperClassname , 'getCategoryRoute' ) ) ) { $ return [ $ tag ] = $ helperClassname :: getCategoryRoute ( $ item , $ tag ) ; } else { $ return [ $ tag ] = 'index.php?option=' . $ extension . '&view=category&id=' . $ item ; } } } return $ return ; }
Method to get the associations for a given category
27,502
public function connect ( ) { parent :: connect ( ) ; $ this -> resource -> setAttribute ( \ PDO :: ATTR_ERRMODE , \ PDO :: ERRMODE_SILENT ) ; return $ this ; }
Extended to set error mode to silent .
27,503
public function bindEventObject ( $ object , $ filter = FALSE ) { $ this -> bound_event_objects [ ] = [ $ filter === FALSE ? FALSE : ( array ) $ filter , $ object ] ; $ this -> event_cache_state = [ ] ; }
Registers all event listener of an object to this object .
27,504
public function addListener ( $ name , callable $ callback ) { if ( ! array_key_exists ( $ name , $ this -> registered_events ) ) { $ this -> registered_events [ $ name ] = [ ] ; } $ this -> registered_events [ $ name ] [ ] = $ callback ; }
Manually adds a listener
27,505
public function setBaseURL ( $ urlString ) { if ( ! is_string ( $ urlString ) && ! is_null ( $ urlString ) ) { throw new InvalidArgumentException ( "Please provide a string as parameter!" ) ; } else { $ this -> base_url = $ urlString ; } return $ this ; }
Sets the base URL for the package .
27,506
public function setConfiguration ( $ config ) { if ( is_string ( $ config ) ) { $ this -> config = new Config ( array ( 'language' => $ config ) ) ; $ this -> translator = new Translator ( $ this -> config ) ; } else if ( is_array ( $ config ) ) { $ this -> translator = new Translator ( $ config ) ; } else { throw new InvalidArgumentException ( "Please provide a string or an array as parameter!" ) ; } return $ this ; }
Dynamic Package configuration
27,507
public function disable ( $ pos = null ) { if ( $ pos === null || ! in_array ( $ pos , array_keys ( $ this -> segments ) ) ) { throw new OutOfRangeException ( 'Refering to non existent Segment position!' ) ; } else { $ selectedSegment = $ this -> segments [ $ pos ] ; $ selectedSegment -> disable ( ) ; } return $ this ; }
Disables a Segment at the given position .
27,508
public function map ( array $ rawArray ) { $ map = new Map ( $ rawArray ) ; $ this -> segments = $ map -> getSegments ( ) ; return $ this ; }
Registers a list of title = > link pairs with the package .
27,509
public function cleanParamsForLog ( $ data ) { foreach ( $ data as $ key => & $ value ) { if ( in_array ( $ key , $ this -> obfuscationFields ) ) { $ value = self :: OBFUSCATION_STRING ; } if ( in_array ( $ key , $ this -> removeFields ) ) { $ value = self :: REMOVED_STRING ; } } return $ data ; }
Function to prepare the parameters of an API request for logging .
27,510
private function isValidLogLevel ( $ level ) { return in_array ( $ level , array ( LogLevel :: EMERGENCY , LogLevel :: ALERT , LogLevel :: CRITICAL , LogLevel :: ERROR , LogLevel :: WARNING , LogLevel :: NOTICE , LogLevel :: INFO , LogLevel :: DEBUG , ) ) ; }
Returns true if the level is a valid log level .
27,511
public function add ( $ original , $ alias ) { $ alias = Input :: checkAlias ( $ alias ) ; $ this -> aliases [ $ alias ] = $ original ; }
Adds a class alias to the aliases array
27,512
public function enable ( ) { if ( $ this -> isLoaderRegistered ( $ last ) ) { if ( $ last ) { return ; } $ this -> disable ( ) ; } spl_autoload_register ( $ this -> aliasLoader ) ; }
Enables static proxying by registering the autoloader .
27,513
public function loader ( $ class ) { if ( isset ( $ this -> aliases [ $ class ] ) ) { class_alias ( $ this -> aliases [ $ class ] , $ class ) ; return ; } if ( $ this -> namespacing ) { if ( $ alias = $ this -> getNamespaceAlias ( $ class ) ) { class_alias ( $ this -> aliases [ $ alias ] , $ class ) ; } } }
Registered class loader to manage lazy class aliasing .
27,514
protected function getRegisteredAlias ( $ class ) { $ alias = basename ( str_replace ( '\\' , '/' , $ class ) ) ; return isset ( $ this -> aliases [ $ alias ] ) ? $ alias : null ; }
Returns the class alias if it is registered .
27,515
protected function isLoaderRegistered ( & $ last ) { $ result = false ; $ last = false ; if ( $ funcs = spl_autoload_functions ( ) ) { $ index = array_search ( $ this -> aliasLoader , $ funcs , true ) ; if ( false !== $ index ) { $ result = true ; $ last = $ index === count ( $ funcs ) - 1 ; } } return $ result ; }
Reports whether the alias loader is registered and at the end of the stack .
27,516
private function rebuildFilter ( $ uid ) { $ filter = new BloomFilter ( $ this -> size , $ this -> probability ) ; foreach ( $ this -> listFor ( $ uid ) as $ item ) { $ filter -> set ( $ item -> getNodeId ( ) ) ; } $ this -> cache -> set ( $ this -> getCacheId ( $ uid ) , $ filter ) ; return $ filter ; }
Rebuild new filter from 0 for the given user
27,517
private function getFilter ( $ uid ) { if ( isset ( $ this -> filters [ $ uid ] ) ) { return $ this -> filters [ $ uid ] ; } $ entry = $ this -> cache -> get ( $ this -> getCacheId ( $ uid ) ) ; if ( $ entry && $ entry -> data instanceof BloomFilter ) { return $ this -> filters [ $ uid ] = $ entry -> data ; } return $ this -> filters [ $ uid ] = $ this -> rebuildFilter ( $ uid ) ; }
Get filter for user
27,518
private function deleteFilter ( $ uid ) { unset ( $ this -> filters [ $ uid ] ) ; $ this -> cache -> delete ( $ this -> getCacheId ( $ uid ) ) ; }
Save filter for user
27,519
public function read ( ) : \ Generator { if ( $ key = $ this -> firstKey ( ) ) { yield $ key => $ this -> get ( $ key ) ; } while ( $ key = $ this -> nextKey ( ) ) { yield $ key => $ this -> get ( $ key ) ; } }
Read database keys .
27,520
public function handle ( ) { $ error = $ this -> lastErrorProvider -> get ( ) ; if ( $ error === null ) { return ; } if ( ! ( $ error [ 'type' ] & ( E_ERROR | E_USER_ERROR ) ) ) { return ; } $ this -> logging -> log ( 'Script stopped due to FATAL error in ' . $ error [ 'file' ] . ' in line ' . $ error [ 'line' ] . ' with message: ' . $ error [ 'message' ] ) ; }
Handles errors upon shutdown of PHP .
27,521
public function onCollectLayout ( CollectLayoutEvent $ event ) { if ( ! $ this -> siteManager -> hasContext ( ) ) { return ; } $ layoutIds = [ ] ; $ context = $ event -> getContext ( ) ; $ site = $ this -> siteManager -> getContext ( ) ; $ theme = $ site -> getTheme ( ) ; $ storage = $ context -> getLayoutStorage ( ) ; $ siteLayoutIds = $ this -> database -> query ( "select id from {layout} where site_id = ? and node_id is null" , [ $ site -> getId ( ) ] ) -> fetchCol ( ) ; if ( ! $ siteLayoutIds ) { foreach ( RegionConfig :: getSiteRegionList ( $ theme ) as $ region ) { $ layoutIds [ ] = $ storage -> create ( [ 'site_id' => $ site -> getId ( ) , 'region' => $ region ] ) -> getId ( ) ; } } else { $ layoutIds = array_merge ( $ layoutIds , $ siteLayoutIds ) ; } if ( arg ( 0 ) === 'node' && ! arg ( 2 ) && ( $ node = menu_get_object ( ) ) ) { $ nodeLayoutIds = $ this -> database -> query ( "select id from {layout} where node_id = ? and site_id = ?" , [ $ node -> nid , $ site -> getId ( ) ] ) -> fetchCol ( ) ; if ( ! $ nodeLayoutIds ) { foreach ( RegionConfig :: getPageRegionList ( $ theme ) as $ region ) { $ layoutIds [ ] = $ storage -> create ( [ 'node_id' => $ node -> nid , 'site_id' => $ site -> getId ( ) , 'region' => $ region ] ) -> getId ( ) ; } } else { $ layoutIds = array_merge ( $ layoutIds , $ nodeLayoutIds ) ; } } if ( $ layoutIds ) { $ event -> addLayoutList ( $ layoutIds ) ; } }
Collects current page layout
27,522
public static function messageName ( ) : string { if ( array_key_exists ( $ class = static :: class , self :: $ hmlbDDDMessageNamesCache ) ) { return self :: $ hmlbDDDMessageNamesCache [ $ class ] ; } self :: $ hmlbDDDMessageNamesCache [ $ class ] = $ name = static :: generateMessageNameFromClassName ( ) ; return $ name ; }
Guesses the message name from the class name . Keeps it in memory after first call . If you want to optimize performance override this method .
27,523
private function findMostRelevantGroupId ( ) { if ( $ this -> siteManager -> hasDependentContext ( 'group' ) ) { $ group = $ this -> siteManager -> getDependentContext ( 'group' ) ; if ( $ group ) { return ( int ) $ group -> getId ( ) ; } } $ accessList = $ this -> groupManager -> getUserGroups ( $ this -> currentUser ) ; if ( $ accessList ) { return ( int ) reset ( $ accessList ) -> getGroupId ( ) ; } }
Find most relevant group in context
27,524
private function findMostRelevantGhostValue ( NodeInterface $ node ) { if ( ! empty ( $ node -> group_id ) ) { return ( int ) $ this -> groupManager -> findOne ( $ node -> group_id ) -> isGhost ( ) ; } return 1 ; }
Find most relevant ghost value for node
27,525
public function setMessage ( int $ code , string $ message , string $ keyAttributeSession = 'Slim3Auth' , array $ attributesSession = [ ] ) { $ this -> message -> setCode ( $ code ) ; $ this -> message -> setMessage ( $ message ) ; $ this -> message -> setKeysession ( $ keyAttributeSession ) ; $ this -> message -> setAttrsession ( $ attributesSession ) ; }
Set message Auth Response
27,526
public function onSitePreCreate ( SiteEvent $ event ) { $ site = $ event -> getSite ( ) ; if ( ! empty ( $ site -> group_id ) ) { return ; } $ site -> group_id = $ this -> findMostRelevantGroupId ( ) ; }
Sets the most relevant group_id property values
27,527
public function onAllowedThemeList ( AllowListEvent $ event ) { if ( $ group = $ this -> findMostRelevantGroup ( ) ) { if ( $ themes = $ group -> getAttribute ( 'allowed_themes' ) ) { $ event -> removeNotIn ( $ themes ) ; } } }
Restrict theme list to what group supports
27,528
public function cie76 ( $ color1 , $ color2 ) { $ f1 = $ this -> toLab ( $ color1 ) ; $ f2 = $ this -> toLab ( $ color2 ) ; $ deltaL = $ f2 -> l - $ f1 -> l ; $ deltaA = $ f2 -> a - $ f1 -> a ; $ deltaB = $ f2 -> b - $ f1 -> b ; $ deltaE = $ deltaL * $ deltaL + $ deltaA * $ deltaA + $ deltaB * $ deltaB ; return $ deltaE < 0 ? 0 : sqrt ( $ deltaE ) ; }
DeltaE calculation using the CIE76 formula . Delta = 2 . 3 corresponds to a just noticeable difference .
27,529
public function cie94 ( $ color1 , $ color2 ) { $ Kl = 1.0 ; $ K1 = .045 ; $ K2 = 0.015 ; $ Kc = 1.0 ; $ Kh = 1.0 ; $ f1 = $ this -> toLab ( $ color1 ) ; $ f2 = $ this -> toLab ( $ color2 ) ; $ deltaL = $ f2 -> l - $ f1 -> l ; $ deltaA = $ f2 -> a - $ f1 -> a ; $ deltaB = $ f2 -> b - $ f1 -> b ; $ c1 = sqrt ( $ f1 -> a * $ f1 -> a + $ f1 -> b * $ f1 -> b ) ; $ c2 = sqrt ( $ f2 -> a * $ f2 -> a + $ f2 -> b * $ f2 -> b ) ; $ deltaC = $ c2 - $ c1 ; $ deltaH = $ deltaA * $ deltaA + $ deltaB * $ deltaB - $ deltaC * $ deltaC ; $ deltaH = $ deltaH < 0 ? 0 : sqrt ( $ deltaH ) ; $ Sl = 1.0 ; $ Sc = 1 + $ K1 * $ c1 ; $ Sh = 1 + $ K2 * $ c1 ; $ deltaLKlsl = $ deltaL / ( $ Kl * $ Sl ) ; $ deltaCkcsc = $ deltaC / ( $ Kc * $ Sc ) ; $ deltaHkhsh = $ deltaH / ( $ Kh * $ Sh ) ; $ deltaE = $ deltaLKlsl * $ deltaLKlsl + $ deltaCkcsc * $ deltaCkcsc + $ deltaHkhsh * $ deltaHkhsh ; return $ deltaE < 0 ? 0 : sqrt ( $ deltaE ) ; }
DeltaE calculation using the CIE94 formula . Delta = 2 . 3 corresponds to a just noticeable difference .
27,530
public function simpleRgbDistance ( $ color1 , $ color2 ) { $ deltaR = ( $ color2 -> r - $ color1 -> r ) / 255 ; $ deltaG = ( $ color2 -> g - $ color1 -> g ) / 255 ; $ deltaB = ( $ color2 -> b - $ color1 -> b ) / 255 ; $ deltaE = $ deltaR * $ deltaR + $ deltaG * $ deltaG + $ deltaB * $ deltaB ; return ( $ deltaE < 0 ) ? $ deltaE : sqrt ( $ deltaE ) * 57.73502691896258 ; }
Not very useful but interesting to compare .
27,531
public function setContext ( Site $ site , Request $ request , $ disablePostDispatch = false ) { $ doDispatch = false ; if ( ! $ this -> context || $ this -> context -> getId ( ) !== $ site -> getId ( ) ) { $ doDispatch = true ; } $ this -> context = $ site ; if ( $ doDispatch ) { $ this -> dependentContext = [ ] ; $ this -> dispatcher -> dispatch ( SiteEvents :: EVENT_INIT , new SiteInitEvent ( $ this -> context , $ request ) ) ; if ( $ disablePostDispatch ) { $ this -> postInitRun = false ; } else { $ this -> dispatchPostInit ( ) ; } } }
Set current site context
27,532
public function dispatchPostInit ( ) { if ( ! $ this -> postInitRun && $ this -> context ) { $ this -> postInitRun = true ; $ this -> dispatcher -> dispatch ( SiteEvents :: EVENT_POST_INIT , new SiteEvent ( $ this -> context ) ) ; } }
This is public because it must be run manually from Drupal code but please never ever run this manually or I ll do kill you . Slowly .
27,533
public function dropContext ( ) { $ oldContext = false ; if ( $ this -> context ) { $ oldContext = $ this -> context ; } $ this -> context = null ; $ this -> dependentContext = [ ] ; if ( $ oldContext ) { $ this -> dispatcher -> dispatch ( SiteEvents :: EVENT_DROP , new SiteEvent ( $ oldContext ) ) ; } }
Remove current context
27,534
public function getDependentContext ( $ name ) { if ( ! isset ( $ this -> dependentContext [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( "there is no dependent context '%s'" , $ name ) ) ; } return $ this -> dependentContext [ $ name ] ; }
Get dependent context
27,535
public function setDependentContext ( $ name , $ value , $ allowOverride = false ) { if ( ! $ allowOverride && isset ( $ this -> dependentContext [ $ name ] ) ) { throw new \ LogicException ( sprintf ( "you are overriding an existing dependent context '%s', are you sure you meant to do this?" , $ name ) ) ; } $ this -> dependentContext [ $ name ] = $ value ; }
Set dependent context
27,536
public function getAllowedThemes ( ) { $ event = new AllowListEvent ( AllowListEvent :: THEMES , variable_get ( 'ucms_site_allowed_themes' , [ ] ) ) ; $ this -> dispatcher -> dispatch ( AllowListEvent :: EVENT_THEMES , $ event ) ; return $ event -> getAllowedItems ( ) ; }
Get allowed front - end themes
27,537
public function getTypeName ( $ type ) { $ allowedTypes = $ this -> getAllowedTypes ( ) ; if ( $ type && isset ( $ allowedTypes [ $ type ] ) ) { return $ allowedTypes [ $ type ] ; } return t ( "None" ) ; }
Get type human readable name
27,538
public function getTemplateList ( ) { $ templates = [ ] ; foreach ( $ this -> storage -> findTemplates ( ) as $ site ) { $ templates [ $ site -> id ] = $ site -> title ; } return $ templates ; }
Get allowed template sites identifiers along with their title
27,539
public function loadWebmasterSites ( AccountInterface $ account ) { $ roles = $ this -> getAccess ( ) -> getUserRoles ( $ account ) ; foreach ( $ roles as $ grant ) { if ( $ grant -> getRole ( ) !== Access :: ROLE_WEBMASTER ) { unset ( $ roles [ $ grant -> getSiteId ( ) ] ) ; } } return $ this -> getStorage ( ) -> loadAll ( array_keys ( $ roles ) ) ; }
Load sites for which the user is webmaster
27,540
public function loadOwnSites ( AccountInterface $ account ) { $ roles = $ this -> getAccess ( ) -> getUserRoles ( $ account ) ; return $ this -> getStorage ( ) -> loadAll ( array_keys ( $ roles ) ) ; }
Load sites for which the user is a part of
27,541
public function add ( $ message , $ type , $ group = '0' ) { if ( ! is_array ( $ message ) ) { $ message = [ $ message ] ; } $ this -> populateMessages ( $ message , $ type , $ group ) ; session ( ) -> flash ( $ this -> session_key , $ this -> messages ) ; return $ this ; }
Set new message for the next request .
27,542
public function byGroup ( $ group ) { $ filtered_messages = $ this -> filterMessage ( 'group' , $ group ) ; $ this -> filtered = $ filtered_messages ; return $ this ; }
Filter messages by group .
27,543
public function byType ( $ type ) { $ filtered_messages = $ this -> filterMessage ( 'type' , $ type ) ; $ this -> filtered = $ filtered_messages ; return $ this ; }
Filter messages by type .
27,544
public function toHTML ( $ custom_template = null ) { $ custom_template = is_null ( $ custom_template ) ? 'laravel-notifications/' . config ( 'laravel-notifications.view' ) : $ custom_template ; if ( view ( ) -> exists ( $ custom_template ) ) { return view ( $ custom_template , [ 'messages' => $ this -> filtered ] ) -> render ( ) ; } else { return view ( 'laravel-notifications::bootstrap3' , [ 'messages' => $ this -> filtered ] ) -> render ( ) ; } }
Format filtered messages as Twitter Bootstrap alerts .
27,545
private function filterMessage ( $ param , $ value ) { $ messages = session ( $ this -> session_key , [ ] ) ; $ filtered_messages = [ ] ; foreach ( $ messages as $ message ) { if ( $ message [ $ param ] == $ value ) { $ filtered_messages [ ] = $ message ; } } return $ filtered_messages ; }
Filter messages by param .
27,546
private function populateMessages ( array $ messages , $ type , $ group ) { foreach ( $ messages as $ message ) { $ this -> messages [ ] = [ 'message' => $ message , 'type' => $ type , 'group' => $ group ] ; } }
Put messages in object messages stack .
27,547
public static function hasCommand ( $ command ) { if ( ! is_string ( $ command ) || strlen ( $ command ) < 1 ) { throw new BadMethodCallException ( 'Parameter command is not a valid string' ) ; } $ instance = self :: getInstance ( ) ; return isset ( $ instance -> commands [ $ command ] ) ; }
command registry has command
27,548
public static function getCommand ( $ command ) { if ( ! is_string ( $ command ) || strlen ( $ command ) < 1 ) { throw new BadMethodCallException ( 'Parameter command is not a valid string' ) ; } $ instance = self :: getInstance ( ) ; if ( ! isset ( $ instance -> commands [ $ command ] ) ) { throw new BadMethodCallException ( 'Command "' . $ command . '" is not a registered command' ) ; } return $ instance -> commands [ $ command ] ; }
get command callback
27,549
public static function register ( $ command , $ callback ) { if ( ! is_string ( $ command ) || strlen ( $ command ) < 1 ) { throw new BadMethodCallException ( 'Parameter command is not a valid string' ) ; } if ( ! is_callable ( $ callback ) ) { throw new BadMethodCallException ( 'Parameter callback is not a valid callback' ) ; } $ instance = self :: getInstance ( ) ; $ instance -> commands [ $ command ] = $ callback ; return $ instance ; }
register a image command
27,550
public function onNodeAccess ( NodeAccessEvent $ event ) { $ node = $ event -> getNode ( ) ; $ account = $ event -> getAccount ( ) ; $ op = $ event -> getOperation ( ) ; $ access = $ this -> siteManager -> getAccess ( ) ; if ( 'create' === $ op ) { if ( $ this -> siteManager -> hasContext ( ) ) { $ site = $ this -> siteManager -> getContext ( ) ; if ( ! in_array ( $ site -> getState ( ) , [ SiteState :: INIT , SiteState :: OFF , SiteState :: ON ] ) ) { return $ event -> deny ( ) ; } } return $ event -> ignore ( ) ; } if ( Permission :: UPDATE === $ op && $ account -> uid && $ node -> uid == $ account -> uid ) { if ( $ node -> ucms_sites ) { foreach ( $ access -> getUserRoles ( $ account ) as $ grant ) { if ( in_array ( $ grant -> getSiteId ( ) , $ node -> ucms_sites ) ) { return $ event -> allow ( ) ; } } } } if ( Permission :: CLONE === $ op ) { if ( $ node -> ucms_sites ) { foreach ( array_intersect_key ( $ access -> getUserRoles ( $ account ) , array_flip ( $ node -> ucms_sites ) ) as $ role ) { if ( $ role -> getRole ( ) == Access :: ROLE_WEBMASTER ) { return true ; } } } } return $ event -> ignore ( ) ; }
Check node access event listener
27,551
protected function defineAttributes ( ) { return array ( 'bucketRegion' => array ( AttributeType :: String , 'required' => true ) , 'bucketName' => array ( AttributeType :: String , 'required' => true ) , 'bucketPath' => array ( AttributeType :: String , 'required' => false ) , 'awsKey' => array ( AttributeType :: String , 'required' => false ) , 'awsSecret' => array ( AttributeType :: String , 'required' => false ) ) ; }
Define model attributes .
27,552
public function loadPlugins ( ) { $ activePlugins = $ this -> getActivePlugins ( ) ; foreach ( $ activePlugins as $ plugin ) { if ( $ class = $ this -> load ( $ plugin ) ) { $ class -> run ( ) ; } } }
Run activated plugins
27,553
protected function getNamespace ( $ path ) { return str_replace ( " " , "" , str_replace ( "/" , "\\" , ucwords ( str_replace ( '-' , ' ' , str_replace ( '/ ' , '/' , ucwords ( str_replace ( '/' , '/ ' , $ path ) ) ) ) ) ) ) ; }
Clean a Simple Plugin s parent folder name to load it
27,554
protected function checkSimple ( $ plugin ) { return ForumEnv :: get ( 'FORUM_ROOT' ) . 'plugins' . DIRECTORY_SEPARATOR . $ plugin . DIRECTORY_SEPARATOR . $ this -> getNamespace ( $ plugin ) . '.php' ; }
For plugins that don t need to provide a Composer autoloader check if it can be loaded
27,555
private function assignPermissions ( Collection $ permissions ) { $ roles = Role :: whereIn ( 'id' , $ this -> role_ids ) -> get ( ) ; if ( $ roles && $ permissions ) { $ permission_ids = $ permissions -> lists ( 'id' ) -> all ( ) ; foreach ( $ roles as $ role ) { $ role -> permissions ( ) -> attach ( $ permission_ids ) ; } } }
Assign permissions to roles
27,556
private function getProtectedRoutes ( ) { $ protected = new Collection ( ) ; $ routes = RouteList :: instance ( ) -> getRoutes ( ) ; foreach ( $ routes as $ route ) { if ( $ route [ 'middleware' ] -> has ( 'acl' ) || $ route [ 'middleware' ] -> search ( 'acl' , true ) !== false ) { $ protected -> put ( $ route [ 'resource' ] , new Collection ( $ route ) ) ; } } return $ protected ; }
Get protected routes only
27,557
private function getPermissionData ( $ route ) { $ description = '' ; $ chunks = explode ( '\\' , $ route [ 'controller' ] ) ; $ module = strtolower ( end ( $ chunks ) ) ; $ module = str_replace ( 'controller' , '' , $ module ) ; $ messages = [ 'index' => 'List all :modules' , 'create' => 'Create :modules' , 'show' => 'Preview :module' , 'edit' => 'Update :modules' , 'destroy' => 'Delete :modules' ] ; $ pattern = [ '#:module#' , '#:modules#' ] ; $ replacement = [ $ module , str_plural ( $ module ) ] ; if ( array_key_exists ( $ route [ 'action' ] , $ messages ) ) { $ description = preg_replace ( $ pattern , $ replacement , $ messages [ $ route [ 'action' ] ] ) ; } return [ 'resource' => $ route [ 'resource' ] , 'controller' => $ route [ 'controller' ] , 'method' => $ route [ 'action' ] , 'description' => $ description , ] ; }
Setup permission data
27,558
public function message ( $ protocolVersion , $ headers , $ body ) { return new Messages \ Message \ Implementation ( $ protocolVersion , $ headers , $ body ) ; }
Build a PSR - 7 message
27,559
public function request ( $ protocolVersion , $ headers , $ body , $ method , $ uri ) { return new Messages \ Message \ Request \ Implementation ( $ protocolVersion , $ headers , $ body , $ method , $ uri ) ; }
Build a PSR - 7 request
27,560
public function serverRequest ( $ protocolVersion , $ headers , $ body , $ method , $ uri , $ serverParams , $ queryParams , $ parsedBody , $ cookieParams , $ uploadedFiles , $ attributes = array ( ) ) { return new Messages \ Message \ Request \ ServerRequest \ Implementation ( $ protocolVersion , $ headers , $ body , $ method , $ uri , $ serverParams , $ queryParams , $ parsedBody , $ cookieParams , $ uploadedFiles , $ attributes ) ; }
Build a PSR - 7 serverRequest
27,561
public function sapiServerRequest ( $ server = null , $ get = null , $ post = null , $ cookie = null , $ files = null , $ attributes = array ( ) ) { return new Messages \ Message \ Request \ ServerRequest \ SAPI ( $ this , $ server !== null ? $ server : $ _SERVER , $ get !== null ? $ get : $ _GET , $ post !== null ? $ post : $ _POST , $ cookie !== null ? $ cookie : $ _COOKIE , $ files !== null ? $ files : $ _FILES , $ attributes ) ; }
Build a server request from SAPI with the ability to override individual attributes
27,562
public function response ( $ protocolVersion , $ headers , $ body , $ statusCode = 200 , $ reasonPhrase = null ) { return new Messages \ Message \ Response ( $ protocolVersion , $ headers , $ body , $ statusCode , $ reasonPhrase ) ; }
Build a PSR - 7 response
27,563
public function uploadedFile ( $ file , $ clientFilename = null , $ clientMediaType = null , $ size = null , $ error = UPLOAD_ERR_OK ) { return new Messages \ UploadedFile \ Implementation ( $ this , $ file , $ clientFilename , $ clientMediaType , $ size , $ error ) ; }
Build a PSR - 7 uploaded file representation
27,564
public function match ( $ alias , $ class ) { foreach ( [ '*' , $ alias ] as $ key ) { if ( $ props = $ this -> getNamespace ( $ key ) ) { if ( $ this -> matchGroup ( $ props , $ alias , $ class ) ) { return true ; } } } return false ; }
Returns true if a matching namespace is found .
27,565
protected function matchGroup ( $ props , $ alias , $ class ) { if ( $ props [ 'any' ] ) { return true ; } foreach ( [ 'path' , 'name' ] as $ group ) { if ( $ this -> matchClass ( $ props [ $ group ] , $ group , $ alias , $ class ) ) { return true ; } } return false ; }
Returns true if a namespace entry is matched .
27,566
protected function matchClass ( $ array , $ group , $ alias , $ class ) { $ match = false ; foreach ( $ array as $ test ) { if ( 'path' === $ group ) { $ match = 0 === strpos ( $ class , $ test ) ; } else { $ match = $ test . '\\' . $ alias === $ class ; } if ( $ match ) { break ; } } return $ match ; }
Returns true if a class matches a namespace item
27,567
protected function getNamespace ( $ alias , $ default = false ) { $ result = isset ( $ this -> namespaces [ $ alias ] ) ? $ this -> namespaces [ $ alias ] : [ ] ; if ( $ result || $ default ) { $ result = array_merge ( $ this -> getDefaultGroups ( ) , $ result ) ; } return $ result ; }
Returns the namespace groups for an alias .
27,568
protected function setNamespace ( $ alias , $ props ) { array_walk ( $ props , function ( & $ value ) { if ( is_array ( $ value ) ) { $ value = array_unique ( $ value ) ; } } ) ; $ this -> namespaces [ $ alias ] = array_filter ( $ props ) ; }
Adds a namespace array group to the namespaces array .
27,569
public function getAdminPageBaseQuery ( $ tab , $ page ) { if ( ! isset ( $ this -> tabs [ $ tab ] ) ) { throw new \ RuntimeException ( "content admin tab '%s' does not exist" , $ tab ) ; } if ( ! isset ( $ this -> adminPages [ $ page ] ) ) { throw new \ RuntimeException ( "content admin page '%s' does not exist" , $ page ) ; } if ( isset ( $ this -> adminPages [ $ page ] [ 'base_query' ] ) ) { $ baseQuery = $ this -> adminPages [ $ page ] [ 'base_query' ] ; } else { $ baseQuery = [ ] ; } switch ( $ tab ) { case 'content' : $ baseQuery [ 'type' ] = $ this -> getContentTypes ( ) ; break ; case 'media' : $ baseQuery [ 'type' ] = $ this -> getMediaTypes ( ) ; break ; default : throw new \ RuntimeException ( "only 'content' and 'media' tabs are supported as of now" , $ page ) ; } return $ baseQuery ; }
Get admin page base query
27,570
public function indexAction ( ) { $ this -> di -> session ( ) ; $ form = new \ Anax \ HTMLForm \ CFormExample ( ) ; $ form -> setDI ( $ this -> di ) ; $ form -> check ( ) ; $ this -> di -> theme -> setTitle ( "Testing CForm with Anax" ) ; $ this -> di -> views -> add ( 'default/page' , [ 'title' => "Try out a form using CForm" , 'content' => $ form -> getHTML ( ) ] ) ; }
Index action using external form .
27,571
protected function generateSlugOnCreate ( ) { $ this -> slugOptions = $ this -> getSlugOptions ( ) ; if ( ! $ this -> slugOptions -> generateSlugOnCreate ) { return ; } $ this -> createSlug ( ) ; }
Generate a slug on create
27,572
protected function generateSlugOnUpdate ( ) { $ this -> slugOptions = $ this -> getSlugOptions ( ) ; if ( ! $ this -> slugOptions -> generateSlugOnUpdate ) { return ; } $ slugNew = $ this -> generateNonUniqueSlug ( ) ; $ slugCurrent = $ this -> attributes [ $ this -> slugOptions -> slugField ] ; if ( strpos ( $ slugCurrent , $ slugNew ) === 0 ) { $ slugUpdate = $ this -> checkUpdatingSlug ( $ slugCurrent ) ; if ( $ slugUpdate !== false ) { return ; } } $ this -> createSlug ( ) ; }
Handle adding slug on model update .
27,573
protected function createSlug ( ) { $ slug = $ this -> generateNonUniqueSlug ( ) ; if ( $ this -> slugOptions -> generateUniqueSlug ) { $ slug = $ this -> makeSlugUnique ( $ slug ) ; } $ this -> attributes [ $ this -> slugOptions -> slugField ] = $ slug ; }
Add the slug to the model .
27,574
protected function getSlugSourceString ( ) { if ( is_callable ( $ this -> slugOptions -> generateSlugFrom ) ) { $ slug = call_user_func ( $ this -> slugOptions -> generateSlugFrom , $ this ) ; return substr ( $ slug , 0 , $ this -> slugOptions -> maximumLength ) ; } $ slug = collect ( $ this -> slugOptions -> generateSlugFrom ) -> map ( function ( $ fieldName = '' ) { return $ this -> $ fieldName ; } ) -> implode ( $ this -> slugOptions -> slugSeparator ) ; return substr ( $ slug , 0 , $ this -> slugOptions -> maximumLength ) ; }
Get the string that should be used as base for the slug .
27,575
protected function makeSlugUnique ( $ slug ) { $ i = 1 ; $ slugIsUnique = false ; $ list = $ this -> getExistingSlugs ( $ slug ) ; if ( $ list -> count ( ) === 0 ) { return $ slug ; } if ( ! is_array ( $ list ) ) { $ list = $ list -> toArray ( ) ; } while ( ! $ slugIsUnique ) { $ uniqueSlug = $ slug . $ this -> slugOptions -> slugSeparator . ( $ i ++ ) ; if ( ! in_array ( $ uniqueSlug , $ list ) ) { $ slugIsUnique = true ; } } return $ uniqueSlug ; }
Make the slug unique with suffix
27,576
protected function addDefaultRules ( ) { if ( $ this -> isProduction ) { $ this -> collection -> addUserAgentRules ( ( new UserAgentRule ( '*' ) ) -> setAllow ( [ '/' ] ) ) ; } else { $ this -> collection -> addUserAgentRules ( ( new UserAgentRule ( '*' ) ) -> setDisallow ( [ '/' ] ) ) ; } }
Add default rules environment - dependant .
27,577
protected function getCacheKey ( $ itemkey ) { $ key = self :: CACHE_PREFIX ; if ( $ this -> config ( ) -> get ( 'lock_bypage' ) ) { $ key .= '_' . md5 ( $ itemkey ) ; } if ( $ this -> config ( ) -> get ( 'lock_byuserip' ) && Controller :: has_curr ( ) ) { $ ip = Controller :: curr ( ) -> getRequest ( ) -> getIP ( ) ; $ key .= '_' . md5 ( $ ip ) ; } return $ key ; }
Determines the key to use for saving the current rate
27,578
public function isCallableOrException ( ) { $ validController = $ this -> isValidController ( ) ; $ isMethod = null ; $ isCallable = null ; if ( $ validController ) { $ isMethod = method_exists ( $ this -> controller , $ this -> action ) ; $ isCallable = $ this -> isCallable ( ) ; } if ( ! ( $ isMethod && $ isCallable ) ) { $ msg = "Trying to dispatch/forward to a non callable item. Controllername = '" . $ this -> controllerName . "', Action = '" . $ this -> action . "'." ; $ not = $ validController ? "" : "NOT" ; $ msg .= " The controller named '$this->controllerName' does $not exist as part of of the service-container \$di. " ; $ services = $ this -> di -> getServices ( ) ; natcasesort ( $ services ) ; $ services = implode ( "\n" , $ services ) ; $ msg .= " Loaded services are: <pre>$services</pre>\n" ; if ( $ validController ) { $ not = $ isMethod ? "" : "NOT" ; $ msg .= " The method '$this->action' does $not exist in the class '$this->controllerName'." ; $ not = $ isCallable ? "" : "NOT" ; $ msg .= " The method '$this->action' is $not callable in the class '$this->controllerName' (taking magic methods into consideration)." ; } throw new \ Exception ( $ msg ) ; } }
Inspect if callable and throw exception if parts is not callable .
27,579
public function shortCode ( $ text ) { $ patterns = [ '/\[(FIGURE)[\s+](.+)\]/' , '/\[(BASEURL)\]/' , '/\[(RELURL)\]/' , '/\[(ASSET)\]/' , ] ; return preg_replace_callback ( $ patterns , function ( $ matches ) { switch ( $ matches [ 1 ] ) { case 'FIGURE' : return CTextFilter :: shortCodeFigure ( $ matches [ 2 ] ) ; break ; case 'BASEURL' : return CTextFilter :: shortCodeBaseurl ( ) ; break ; case 'RELURL' : return CTextFilter :: shortCodeRelurl ( ) ; break ; case 'ASSET' : return CTextFilter :: shortCodeAsset ( ) ; break ; default : return "{$matches[1]} is unknown shortcode." ; } } , $ text ) ; }
Shortcode to to quicker format text as HTML .
27,580
public function inject ( & $ page , $ theme ) { $ contextes = [ ContextManager :: CONTEXT_PAGE => $ this -> contextManager -> getPageContext ( ) , ContextManager :: CONTEXT_SITE => $ this -> contextManager -> getSiteContext ( ) ] ; foreach ( $ contextes as $ contextType => $ context ) { $ this -> collectNodeIdList ( $ context , $ this -> contextManager -> getThemeRegionConfigFor ( $ theme , $ contextType ) ) ; } if ( $ this -> nidList ) { $ this -> nodes = $ this -> entityManager -> getStorage ( 'node' ) -> loadMultiple ( $ this -> nidList ) ; } foreach ( $ contextes as $ contextType => $ context ) { $ this -> processContext ( $ page , $ theme , $ context , $ contextType ) ; } }
Inject given regions into the given page
27,581
public function find ( $ type ) { if ( ! isset ( $ this -> instances [ $ type ] ) ) { trigger_error ( sprintf ( "type '%s' is unregistered" , $ type ) , E_USER_WARNING ) ; return $ this -> nullInstance ; } $ instance = $ this -> instances [ $ type ] ; if ( $ instance instanceof TypeInterface ) { return $ instance ; } if ( is_string ( $ instance ) && class_exists ( $ this -> instances [ $ type ] ) ) { return $ this -> instances [ $ type ] = new $ instance ( ) ; } trigger_error ( sprintf ( "class '%s' does not exists" , ( string ) $ instance ) , E_USER_WARNING ) ; unset ( $ this -> instances [ $ type ] ) ; return $ this -> nullInstance ; }
Find converter for given ElasticSearch type
27,582
protected static function getReferrerOwnList ( $ Bot_Referrer_List = false ) { if ( false === $ Bot_Referrer_List ) { return false ; } $ found = false ; $ botreferrerlist = array ( ) ; if ( file_exists ( $ Bot_Referrer_List ) ) { include ( $ Bot_Referrer_List ) ; } else { return false ; } return $ botreferrerlist ; }
Get Referrer List delivered with this extension
27,583
protected static function getReferrerDns ( $ Referrer = false ) { if ( $ Referrer === false ) { $ http_referrer = isset ( $ _SERVER [ 'HTTP_REFERER' ] ) ? $ _SERVER [ 'HTTP_REFERER' ] : 'unknown' ; } else { $ http_referrer = $ Referrer ; } $ referrer_DNS = parse_url ( $ http_referrer , PHP_URL_HOST ) ; if ( $ referrer_DNS === NULL ) { $ referrer_DNS = @ parse_url ( 'http://' . $ http_referrer , PHP_URL_HOST ) ; if ( $ referrer_DNS === NULL || $ referrer_DNS === false ) { return false ; } } return $ referrer_DNS ; }
Get Root Domain from Referrer
27,584
protected static function checkReferrerList ( $ botreferrerlist , $ referrer_DNS ) { foreach ( $ botreferrerlist as $ botreferrer ) { $ CheckBotRef = str_ireplace ( $ botreferrer , '#' , $ referrer_DNS ) ; if ( $ referrer_DNS != $ CheckBotRef ) { return true ; } ; } return false ; }
Compare Referrer List With Referrer Domain
27,585
static public function output ( E $ e , $ channel ) { Artisan :: queue ( 'slack:post' , [ 'to' => $ channel , 'attach' => self :: exceptionToSlackAttach ( $ e ) , 'message' => "Thrown exception" ] ) ; }
Report an exception to slack
27,586
static protected function exceptionToSlackAttach ( E $ e ) { $ fields = [ ] ; $ addToField = function ( $ name , $ value , $ short = false ) use ( & $ fields ) { if ( ! empty ( $ value ) ) { $ fields [ ] = [ "title" => $ name , "value" => $ value , "short" => $ short ] ; } } ; $ addToField ( "Exception" , get_class ( $ e ) , true ) ; $ addToField ( "Hash" , ExceptionHelper :: hash ( $ e ) , true ) ; $ addToField ( "Http code" , ExceptionHelper :: statusCode ( $ e ) , true ) ; $ addToField ( "Code" , $ e -> getCode ( ) , true ) ; $ addToField ( "File" , $ e -> getFile ( ) , true ) ; $ addToField ( "Line" , $ e -> getLine ( ) , true ) ; $ addToField ( "Request url" , Request :: url ( ) , true ) ; $ addToField ( "Request method" , Request :: method ( ) , true ) ; $ addToField ( "Request param" , json_encode ( Request :: all ( ) ) , true ) ; return [ "color" => "danger" , "title" => $ e -> getMessage ( ) , "fallback" => ! empty ( $ e -> getMessage ( ) ) ? $ e -> getMessage ( ) : get_class ( $ e ) , "fields" => $ fields , "text" => $ e -> getTraceAsString ( ) ] ; }
Transform an exception to attachment array for slack post
27,587
public function log ( $ msg , $ type = ShopgateLogger :: LOGTYPE_ERROR ) { return $ this -> loggingStrategy -> log ( $ msg , $ type ) ; }
Logs a message to the according log file .
27,588
public function tail ( $ type = ShopgateLogger :: LOGTYPE_ERROR , $ lines = 20 ) { return $ this -> loggingStrategy -> tail ( $ type , $ lines ) ; }
Returns the requested number of lines of the requested log file s end .
27,589
public function setMemoryAnalyserLoggingSizeUnit ( $ sizeUnit ) { switch ( strtoupper ( trim ( $ sizeUnit ) ) ) { case 'GB' : case 'GIGABYTE' : case 'GIGABYTES' : $ this -> memoryAnalyserLoggingSizeUnit = 'GB' ; break ; case 'MB' : case 'MEGABYTE' : case 'MEGABYTES' : $ this -> memoryAnalyserLoggingSizeUnit = 'MB' ; break ; case 'KB' : case 'KILOBYTE' : case 'KILOBYTES' : $ this -> memoryAnalyserLoggingSizeUnit = 'KB' ; break ; default : $ this -> memoryAnalyserLoggingSizeUnit = 'BYTES' ; break ; } }
Sets the unit in which the memory usage logger outputs its values in
27,590
public function treeListAction ( Request $ request ) { if ( ! $ this -> getMenuAccess ( ) -> canAccessMenuAdmin ( $ this -> getCurrentUser ( ) ) ) { throw $ this -> createAccessDeniedException ( ) ; } return $ this -> renderPage ( 'ucms_tree.list_all' , $ request ) ; }
Administrative tree list
27,591
public function addContentHere ( Request $ request ) { $ links = [ ] ; $ handler = $ this -> getTypeHandler ( ) ; foreach ( $ this -> getTypeHandler ( ) -> getTypesAsHumanReadableList ( $ handler -> getContentTypes ( ) ) as $ type => $ name ) { if ( node_access ( 'create' , $ type ) ) { $ options = [ 'query' => [ 'destination' => $ request -> get ( 'destination' ) , 'menu_name' => $ request -> get ( 'menu' ) , 'parent' => $ request -> get ( 'parent' ) , 'position' => $ request -> get ( 'position' ) , ] , ] ; $ links [ ] = l ( $ name , 'node/add/' . strtr ( $ type , '_' , '-' ) , $ options ) ; } } return [ '#theme' => 'item_list' , '#items' => $ links , ] ; }
Provides minidialog for creating content at a specific position
27,592
public function roll ( $ times ) { $ this -> lastRoll = array ( ) ; for ( $ i = 0 ; $ i < $ times ; $ i ++ ) { $ this -> lastRoll [ ] = rand ( 1 , 6 ) ; } }
Roll the dice
27,593
public static function generateBrowscapCache ( $ force = false , $ arrProxy = false ) { \ Crossjoin \ Browscap \ Cache \ File :: setCacheDirectory ( __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'cache' ) ; \ Crossjoin \ Browscap \ Browscap :: setDatasetType ( \ Crossjoin \ Browscap \ Browscap :: DATASET_TYPE_LARGE ) ; $ updater = new \ Crossjoin \ Browscap \ Updater \ Curl ( ) ; if ( false !== $ arrProxy ) { $ updater -> setOptions ( array ( 'ProxyProtocol' => $ arrProxy [ 'ProxyProtocol' ] , 'ProxyHost' => $ arrProxy [ 'ProxyHost' ] , 'ProxyPort' => $ arrProxy [ 'ProxyPort' ] , 'ProxyUser' => $ arrProxy [ 'ProxyUser' ] , 'ProxyPassword' => $ arrProxy [ 'ProxyPassword' ] ) ) ; } \ Crossjoin \ Browscap \ Browscap :: setUpdater ( $ updater ) ; $ parser = new \ Crossjoin \ Browscap \ Parser \ IniLt55 ( ) ; \ Crossjoin \ Browscap \ Browscap :: setParser ( $ parser ) ; \ Crossjoin \ Browscap \ Browscap :: update ( $ force ) ; $ browscap = new \ Crossjoin \ Browscap \ Browscap ( ) ; $ settings = $ browscap -> getBrowser ( 'Googlebot-Image/1.0' ) -> getData ( ) ; return $ settings -> crawler ; }
Generate Browscap Cache
27,594
public function handle ( $ e ) { if ( ! ( $ e instanceof ShopgateLibraryException ) ) { return ; } $ this -> logging -> log ( 'FATAL: Uncaught ShopgateLibraryException' , Shopgate_Helper_Logging_Strategy_LoggingInterface :: LOGTYPE_ERROR , $ this -> stackTraceGenerator -> generate ( $ e ) ) ; }
Handles uncaught exceptions of type ShopgateLibraryException .
27,595
protected function initOptions ( ) { $ this -> containerOptions = array_merge ( [ 'id' => $ this -> getId ( ) ] , $ this -> containerOptions ) ; Html :: addCssClass ( $ this -> containerOptions , 'owl-carousel' ) ; }
Intialises the plugin options
27,596
public function registerAssets ( $ view ) { OwlCarouselAsset :: register ( $ view ) ; $ js = 'jQuery("#' . $ this -> containerOptions [ 'id' ] . '").owlCarousel(' . "\n" ; $ js .= json_encode ( $ this -> pluginOptions ) . "\n" ; $ js .= ");\n" ; $ view -> registerJs ( $ js , $ view :: POS_READY ) ; }
Registers the needed assets .
27,597
public function isPageContextRegion ( $ region , $ theme ) { $ regions = $ this -> getThemeRegionConfig ( $ theme ) ; return ( isset ( $ regions [ $ region ] ) && ( $ regions [ $ region ] === self :: CONTEXT_PAGE ) ) ; }
Does the given region belong to the page context?
27,598
public function isTransversalContextRegion ( $ region , $ theme ) { $ regions = $ this -> getThemeRegionConfig ( $ theme ) ; return ( isset ( $ regions [ $ region ] ) && ( $ regions [ $ region ] === self :: CONTEXT_SITE ) ) ; }
Does the given region belong to the transversal context?
27,599
public function isRegionInEditMode ( $ region ) { if ( $ site = $ this -> siteManager -> getContext ( ) ) { return ( $ this -> getPageContext ( ) -> isTemporary ( ) && $ this -> isPageContextRegion ( $ region , $ site -> theme ) ) || ( $ this -> getSiteContext ( ) -> isTemporary ( ) && $ this -> isTransversalContextRegion ( $ region , $ site -> theme ) ) ; } return false ; }
Is the given region in edit mode?