idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
20,800 | public function getAllSearchableFieldsFor ( $ classNames ) { $ allfields = array ( ) ; foreach ( $ classNames as $ className ) { $ fields = $ this -> getSearchableFieldsFor ( $ className ) ; $ allfields = array_merge ( $ allfields , $ fields ) ; } return $ allfields ; } | Get all the searchable fields for a given set of classes |
20,801 | protected function buildSearchableFieldCache ( ) { if ( ! $ this -> searchableCache ) { $ objects = DataObject :: get ( 'SolrTypeConfiguration' ) ; if ( $ objects ) { foreach ( $ objects as $ obj ) { $ this -> searchableCache [ $ obj -> Title ] = $ obj -> FieldMappings -> getValues ( ) ; } } } return $ this -> searchableCache ; } | Builds up the searchable fields configuration baased on the solrtypeconfiguration objects |
20,802 | public function getSolrFieldName ( $ field , $ classNames = null ) { if ( ! $ classNames ) { $ classNames = Config :: inst ( ) -> get ( 'SolrSearch' , 'default_searchable_types' ) ; } if ( ! is_array ( $ classNames ) ) { $ classNames = array ( $ classNames ) ; } foreach ( $ classNames as $ className ) { if ( ! class_exists ( $ className ) ) { continue ; } $ dummy = singleton ( $ className ) ; $ fields = $ this -> objectToFields ( $ dummy ) ; if ( $ field == 'ID' ) { $ field = 'SS_ID' ; } if ( isset ( $ fields [ $ field ] ) ) { $ configForType = $ this -> getSearchableFieldsFor ( $ className ) ; $ hint = isset ( $ configForType [ $ field ] ) ? $ configForType [ $ field ] : false ; return $ this -> mapper -> mapFieldNameFromType ( $ field , $ fields [ $ field ] [ 'Type' ] , $ hint ) ; } } } | Return the field name for a given property within a given set of data object types |
20,803 | public function mapFieldNameFromType ( $ field , $ type , $ hint = '' ) { if ( isset ( $ this -> solrFields [ $ field ] ) ) { return $ this -> solrFields [ $ field ] ; } if ( strpos ( $ type , '(' ) ) { $ type = substr ( $ type , 0 , strpos ( $ type , '(' ) ) ; } if ( $ hint && is_string ( $ hint ) && $ hint != 'default' ) { return str_replace ( ':field' , $ field , $ hint ) ; } if ( $ pos = strpos ( $ field , ':' ) ) { $ field = substr ( $ field , 0 , $ pos ) ; } switch ( $ type ) { case 'MultiValueField' : { return $ field . '_ms' ; } case 'Text' : case 'HTMLText' : { return $ field . '_t' ; } case 'Date' : case 'SS_Datetime' : { return $ field . '_dt' ; } case 'Str' : case 'Enum' : { return $ field . '_ms' ; } case 'Attr' : { return 'attr_' . $ field ; } case 'Double' : case 'Decimal' : case 'Currency' : case 'Float' : case 'Money' : { return $ field . '_f' ; } case 'Int' : case 'Integer' : { return $ field . '_i' ; } case 'SolrGeoPoint' : { return $ field . '_p' ; } case 'String' : { return $ field . '_s' ; } case 'Varchar' : default : { return $ field . '_as' ; } } } | Map a SilverStripe field to a Solr field |
20,804 | public function mapValueToType ( $ name , $ value ) { $ type = 'String' ; if ( strpos ( $ name , ':' ) ) { list ( $ name , $ type ) = explode ( ':' , $ name ) ; return $ type ; } if ( is_array ( $ value ) ) { $ type = 'MultiValueField' ; } if ( is_double ( $ value ) ) { return 'Double' ; } if ( is_int ( $ value ) ) { return 'Int' ; } return $ type ; } | Map a raw PHP value to a type |
20,805 | public function convertValue ( $ value , $ type ) { if ( is_array ( $ value ) ) { $ newReturn = array ( ) ; foreach ( $ value as $ v ) { $ newReturn [ ] = $ this -> convertValue ( $ v , $ type ) ; } return $ newReturn ; } else { switch ( $ type ) { case 'Date' : case 'SS_Datetime' : { $ hoursToRemove = date ( 'Z' ) ; $ ts = strtotime ( $ value ) ; $ tsHTR = $ ts - $ hoursToRemove ; $ date = date ( 'Y-m-d\TH:i:s\Z' , $ tsHTR ) ; return $ date ; } case 'HTMLText' : { return strip_tags ( $ value ) ; } case 'SolrGeoPoint' : { return $ value -> y . ',' . $ value -> x ; } default : { return $ value ; } } } } | Convert a value to a format handled by solr |
20,806 | public function get ( $ property ) { if ( ! $ this -> exists ( $ property ) ) { throw new UndefinedPropertyException ( $ property ) ; } return $ this -> data ( ) -> $ property ; } | Get the value of the specified property . |
20,807 | private function fig_include ( Context $ context ) { $ file = $ this -> includedFile ; $ realFilename = dirname ( $ context -> getFilename ( ) ) . '/' . $ file ; $ view = new View ( ) ; if ( $ context -> view -> getCachePath ( ) && $ context -> view -> getTemplatesRoot ( ) ) { $ view -> setCachePath ( $ context -> view -> getCachePath ( ) , $ context -> view -> getTemplatesRoot ( ) ) ; } $ view -> loadFile ( $ realFilename ) ; $ context -> pushInclude ( $ realFilename , $ view -> figNamespace ) ; $ view -> parse ( ) ; if ( $ view -> getRootNode ( ) instanceof ViewElementTag ) { $ doctype = $ view -> getRootNode ( ) -> getAttribute ( $ context -> figNamespace . 'doctype' ) ; if ( $ doctype ) { $ context -> setDoctype ( $ doctype ) ; } } $ result = $ view -> getRootNode ( ) -> render ( $ context ) ; $ context -> popInclude ( ) ; return $ result ; } | Creates a sub - view object invokes its parsing phase and renders it as the child of the current tag . |
20,808 | public static function getUserDefaultLocation ( ) { try { $ user = self :: getLoggedInUser ( ) ; if ( $ user -> PrimaryLocation ) { return $ user -> PrimaryLocation ; } if ( $ user -> Locations && $ user -> Locations -> count ( ) ) { $ user -> PrimaryLocationID = $ user -> Locations [ 0 ] -> UniqueIdentifier ; $ user -> save ( ) ; return $ user -> PrimaryLocation ; } } catch ( NotLoggedInException $ ex ) { } $ basket = Basket :: getCurrentBasket ( ) ; if ( $ basket -> Locations && $ basket -> Locations -> count ( ) ) { if ( isset ( $ user ) ) { $ user -> PrimaryLocationID = $ basket -> Locations [ 0 ] ; $ user -> save ( ) ; return $ user -> PrimaryLocation ; } return $ basket -> Locations [ 0 ] ; } return null ; } | First tries to load a location from the user setting primary location if one isn t set And then attempts to load from basket . |
20,809 | public function theResponseIsGraphQLErrorWith ( string $ message ) { $ this -> assertResponseStatus ( Response :: HTTP_OK ) ; if ( $ this -> client -> getGraphQL ( ) ) { if ( $ this -> isValidGraphQLResponse ( ) && $ errors = $ this -> getGraphQLResponseError ( ) ) { $ errorsStack = '' ; foreach ( $ errors as $ error ) { $ errorsStack .= $ error -> message . "\n" ; } Assert :: assertContains ( $ message , $ errorsStack ) ; } else { $ this -> graphQLContext -> debugLastQuery ( ) ; throw new AssertionFailedError ( 'The response is not the expected error response.' ) ; } } } | Assert that latest response is a GraphQL error with the given message |
20,810 | public function newPassword ( $ id = null ) { $ user = $ this -> Users -> get ( $ id , [ 'contain' => [ ] ] ) ; $ user -> accessible ( 'send_mail' , true ) ; if ( $ this -> request -> is ( [ 'patch' , 'post' , 'put' ] ) ) { $ user = $ this -> Users -> patchEntity ( $ user , $ this -> request -> data ) ; if ( $ this -> Users -> save ( $ user ) ) { if ( $ user -> send_mail ) { $ this -> EmailListener -> passwordConfirmation ( $ user ) ; } $ this -> Flash -> success ( __ ( 'The user has been saved.' ) ) ; return $ this -> redirect ( $ this -> referer ( ) ) ; } else { $ this -> Flash -> error ( __ ( 'The password could not be saved. Please, try again.' ) ) ; } } $ this -> set ( compact ( 'user' ) ) ; $ this -> render ( Configure :: read ( 'CM.AdminUserViews.newPassword' ) ) ; } | New Password method |
20,811 | public function sendActivationMail ( $ id = null ) { $ user = $ this -> Users -> get ( $ id , [ 'contain' => [ ] ] ) ; $ user -> set ( 'active' , false ) ; $ user -> set ( 'activation_key' , $ this -> Users -> generateActivationKey ( ) ) ; if ( $ this -> Users -> save ( $ user ) ) { $ this -> EmailListener -> activation ( $ user ) ; $ this -> Flash -> success ( __ ( 'The e-mail has been sent.' ) ) ; return $ this -> redirect ( $ this -> referer ( ) ) ; } else { $ this -> Flash -> error ( __ ( 'The e-mail could not be sent. Please, try again.' ) ) ; } } | Send Activation Mail method |
20,812 | public function withCredentials ( $ username , $ password ) { $ this -> cookie = null ; $ this -> credentials = array ( 'username' => $ username , 'password' => $ password ) ; return $ this ; } | Upload media by using credentials . |
20,813 | public function upload ( $ file , $ format = 'json' ) { $ url = filter_var ( $ file , FILTER_VALIDATE_URL ) !== false ; $ data = array ( 'key' => $ this -> key , 'format' => $ format ) ; if ( $ url ) { $ data [ 'url' ] = $ file ; } else { $ data [ 'fileupload' ] = $ file ; } if ( $ this -> credentials ) { $ data [ 'a_username' ] = $ this -> credentials [ 'username' ] ; $ data [ 'a_password' ] = $ this -> credentials [ 'password' ] ; } else if ( $ this -> cookie ) { $ data [ 'cookie' ] = $ this -> cookie ; } return $ this -> post ( 'https://post.imageshack.us/upload_api.php' , $ data ) ; } | Upload an image to Imageshack |
20,814 | protected function copyFieldsFromInterface ( InterfaceDefinition $ intDef , FieldsAwareDefinitionInterface $ fieldsAwareDefinition ) { foreach ( $ intDef -> getFields ( ) as $ field ) { if ( ! $ fieldsAwareDefinition -> hasField ( $ field -> getName ( ) ) ) { $ newField = clone $ field ; $ newField -> addInheritedFrom ( $ intDef -> getName ( ) ) ; $ fieldsAwareDefinition -> addField ( $ newField ) ; } else { $ fieldsAwareDefinition -> getField ( $ field -> getName ( ) ) -> addInheritedFrom ( $ intDef -> getName ( ) ) ; } } } | Copy all fields from interface to given object implementor |
20,815 | protected function isExposed ( ObjectDefinitionInterface $ definition , $ prop ) : bool { $ exposed = $ definition -> getExclusionPolicy ( ) === ObjectDefinitionInterface :: EXCLUDE_NONE ; if ( $ prop instanceof \ ReflectionMethod ) { $ exposed = false ; if ( $ this -> getFieldAnnotation ( $ prop , Annotation \ Field :: class ) ) { $ exposed = true ; } } if ( $ exposed && $ this -> getFieldAnnotation ( $ prop , Annotation \ Exclude :: class ) ) { $ exposed = false ; } elseif ( ! $ exposed && $ this -> getFieldAnnotation ( $ prop , Annotation \ Expose :: class ) ) { $ exposed = true ; } if ( $ fieldAnnotation = $ this -> getFieldAnnotation ( $ prop , Annotation \ Field :: class ) ) { $ exposed = true ; if ( $ fieldAnnotation -> in ) { $ exposed = \ in_array ( $ definition -> getName ( ) , $ fieldAnnotation -> in ) ; } elseif ( ( $ fieldAnnotation -> notIn ) ) { $ exposed = ! \ in_array ( $ definition -> getName ( ) , $ fieldAnnotation -> notIn ) ; } } return $ exposed ; } | Verify if a given property for given definition is exposed or not |
20,816 | protected function getFieldAnnotation ( $ prop , string $ annotationClass ) { if ( $ prop instanceof \ ReflectionProperty ) { return $ this -> reader -> getPropertyAnnotation ( $ prop , $ annotationClass ) ; } return $ this -> reader -> getMethodAnnotation ( $ prop , $ annotationClass ) ; } | Get field specific annotation matching given implementor |
20,817 | public function verify ( $ ip , array $ user , $ userAgent = null , array $ source = null , array $ session = null , array $ device = null ) { $ event = [ self :: PARAM_IP => $ ip ] ; if ( ! is_null ( $ userAgent ) ) { $ event [ self :: PARAM_USER_AGENT ] = $ userAgent ; } $ event [ self :: PARAM_USER ] = array_filter ( [ self :: PARAM_USER__ID => $ this -> findValue ( self :: PARAM_USER__ID , $ user ) , self :: PARAM_USER__NAME => $ this -> findValue ( self :: PARAM_USER__NAME , $ user ) , self :: PARAM_USER__EMAIL => $ this -> findValue ( self :: PARAM_USER__EMAIL , $ user ) , self :: PARAM_USER__MOBILE => $ this -> findValue ( self :: PARAM_USER__MOBILE , $ user ) , self :: PARAM_USER__AUTHENTICATED => $ this -> findValue ( self :: PARAM_USER__AUTHENTICATED , $ user ) , ] ) ; if ( ! is_null ( $ source ) ) { $ event [ self :: PARAM_SOURCE ] = array_filter ( [ self :: PARAM_SOURCE__NAME => $ this -> findValue ( self :: PARAM_SOURCE__NAME , $ source ) , self :: PARAM_SOURCE__LOGO_URL => $ this -> findValue ( self :: PARAM_SOURCE__LOGO_URL , $ source ) ] ) ; } $ event [ self :: PARAM_SESSION ] = array_filter ( [ self :: PARAM_SESSION__ID => $ this -> findValue ( self :: PARAM_SESSION__ID , $ session ) ] ) ; if ( isset ( $ _COOKIE [ ThisData :: TD_COOKIE_NAME ] ) ) { $ event [ self :: PARAM_SESSION ] [ self :: PARAM_SESSION__TD_COOKIE_ID ] = $ _COOKIE [ ThisData :: TD_COOKIE_NAME ] ; } if ( $ this -> configuration [ Builder :: CONF_EXPECT_JS_COOKIE ] ) { $ event [ self :: PARAM_SESSION ] [ self :: PARAM_SESSION__TD_COOKIE_EXPECTED ] = $ this -> configuration [ Builder :: CONF_EXPECT_JS_COOKIE ] ; } if ( ! is_null ( $ device ) ) { $ event [ self :: PARAM_DEVICE ] = array_filter ( [ self :: PARAM_DEVICE__ID => $ this -> findValue ( self :: PARAM_DEVICE__ID , $ device ) ] ) ; } $ response = $ this -> synchronousExecute ( 'POST' , ThisData :: ENDPOINT_VERIFY , array_filter ( $ event ) ) ; return json_decode ( $ response -> getBody ( ) , TRUE ) ; } | Verify the current user to get the risk that their account is being hijacked . |
20,818 | public function clean ( $ domain ) { $ domain = trim ( $ domain ) ; $ domain = preg_replace ( '#^https?://#' , '' , $ domain ) ; if ( substr ( strtolower ( $ domain ) , 0 , 4 ) == "www." ) $ domain = substr ( $ domain , 4 ) ; return $ domain ; } | Cleans domain name of empty spaces www http and https . |
20,819 | public function lookup ( ) { if ( $ this -> ip ) { $ result = $ this -> lookupIp ( $ this -> ip ) ; } else { $ result = $ this -> lookupDomain ( $ this -> domain ) ; } return $ result ; } | Looks up the current domain or IP . |
20,820 | public function lookupDomain ( $ domain ) { $ serverObj = new Server ( ) ; $ server = $ serverObj -> getServerByTld ( $ this -> tld ) ; if ( ! $ server ) { throw new Exception ( "Error: No appropriate Whois server found for $domain domain!" ) ; } $ result = $ this -> queryServer ( $ server , $ domain ) ; if ( ! $ result ) { throw new Exception ( "Error: No results retrieved from $server server for $domain domain!" ) ; } else { while ( strpos ( $ result , "Whois Server:" ) !== false ) { preg_match ( "/Whois Server: (.*)/" , $ result , $ matches ) ; $ secondary = $ matches [ 1 ] ; if ( $ secondary ) { $ result = $ this -> queryServer ( $ secondary , $ domain ) ; $ server = $ secondary ; } } } return "$domain domain lookup results from $server server:\n\n" . $ result ; } | Domain lookup . |
20,821 | public function lookupIp ( $ ip ) { $ results = array ( ) ; $ continentServer = new Server ( ) ; foreach ( $ continentServer -> getContinentServers ( ) as $ server ) { $ result = $ this -> queryServer ( $ server , $ ip ) ; if ( $ result && ! in_array ( $ result , $ results ) ) { $ results [ $ server ] = $ result ; } } $ res = "RESULTS FOUND: " . count ( $ results ) ; foreach ( $ results as $ server => $ result ) { $ res .= "Lookup results for " . $ ip . " from " . $ server . " server: " . $ result ; } return $ res ; } | IP lookup . |
20,822 | public function queryServer ( $ server , $ domain ) { $ port = 43 ; $ timeout = 10 ; $ fp = @ fsockopen ( $ server , $ port , $ errno , $ errstr , $ timeout ) ; if ( ! $ fp ) { throw new Exception ( "Socket Error " . $ errno . " - " . $ errstr ) ; } fputs ( $ fp , $ domain . "\r\n" ) ; $ out = "" ; while ( ! feof ( $ fp ) ) { $ out .= fgets ( $ fp ) ; } fclose ( $ fp ) ; $ res = "" ; if ( ( strpos ( strtolower ( $ out ) , "error" ) === false ) && ( strpos ( strtolower ( $ out ) , "not allocated" ) === false ) ) { $ rows = explode ( "\n" , $ out ) ; foreach ( $ rows as $ row ) { $ row = trim ( $ row ) ; if ( ( $ row != '' ) && ( $ row { 0 } != '#' ) && ( $ row { 0 } != '%' ) ) { $ res .= $ row . "\n" ; } } } return $ res ; } | Queries the whois server . |
20,823 | private function getRegistrationClient ( $ number ) { $ file = $ this -> customPath ? $ this -> customPath . '/phone-id-' . $ number . '.dat' : null ; $ registration = new Registration ( $ number , $ this -> debug , $ file ) ; $ this -> listener -> registerRegistrationEvents ( $ registration ) ; return $ registration ; } | Get WhatsProt instance for given number |
20,824 | public function isAvailable ( ) : bool { foreach ( $ this -> items as $ item ) { if ( $ item -> isVisible ( ) ) { return true ; } } return false ; } | Must return true is section has at least one available item . |
20,825 | public static function ResourceLoaderRegisterModules ( \ ResourceLoader $ rl ) { self :: $ _modulesRegistered = true ; $ rl -> register ( self :: $ modules ) ; return true ; } | Register resources with the ResourceLoader . |
20,826 | public function initPage ( \ OutputPage $ out ) { parent :: initPage ( $ out ) ; $ out -> addModules ( self :: $ autoloadModules ) ; } | Load required modules with ResourceLoader |
20,827 | function setupSkinUserCss ( \ OutputPage $ out ) { parent :: setupSkinUserCss ( $ out ) ; $ layoutClass = self :: getLayoutClass ( ) ; $ layoutTree = \ Skinny :: getClassAncestors ( $ layoutClass ) ; $ styles = array ( 'mediawiki.skinning.interface' ) ; foreach ( $ layoutTree as $ lc ) { $ styles = array_merge ( $ styles , $ lc :: getHeadModules ( ) ) ; } $ out -> addModuleStyles ( $ styles ) ; } | Loads skin and user CSS files . |
20,828 | public function addToBodyAttributes ( $ out , & $ attrs ) { $ classes = array ( ) ; $ layout = $ this -> getLayout ( ) ; $ attrs [ 'class' ] .= ' sitename-' . strtolower ( str_replace ( ' ' , '_' , $ GLOBALS [ 'wgSitename' ] ) ) ; $ layoutClass = self :: getLayoutClass ( ) ; $ layoutTree = \ Skinny :: getClassAncestors ( $ layoutClass ) ; $ layoutNames = array_flip ( self :: $ layouts ) ; foreach ( $ layoutTree as $ lc ) { if ( isset ( $ layoutNames [ $ lc ] ) ) { $ classes [ ] = 'layout-' . $ layoutNames [ $ lc ] ; } } if ( $ GLOBALS [ 'wgUser' ] -> isLoggedIn ( ) ) { $ classes [ ] = 'user-loggedin' ; } else { $ classes [ ] = 'user-anonymous' ; } $ attrs [ 'class' ] .= ' ' . implode ( ' ' , $ classes ) ; } | Called by OutputPage to provide opportunity to add to body attrs |
20,829 | public static function addLayout ( $ name , $ className ) { if ( ! class_exists ( $ className ) ) { throw new \ Exception ( 'Invalid Layout class: ' . $ className ) ; } static :: $ layouts [ $ name ] = $ className ; self :: addModules ( $ className :: getResourceModules ( ) ) ; } | Add a new skin layout for this skin |
20,830 | public static function addModules ( $ modules = array ( ) , $ load = false ) { if ( static :: $ _modulesRegistered ) { throw new Exception ( 'Skin is attempting to add modules after modules have already been registered.' ) ; } if ( empty ( $ modules ) ) { return ; } static :: $ modules += ( array ) $ modules ; if ( $ load ) { static :: $ autoloadModules += array_keys ( $ modules ) ; } } | Build a list of modules to be registered to the ResourceLoader when it initializes . |
20,831 | public function validateIp ( $ ip ) { $ ipnums = explode ( "." , $ ip ) ; if ( count ( $ ipnums ) != 4 ) { return false ; } foreach ( $ ipnums as $ ipnum ) { if ( ! is_numeric ( $ ipnum ) || ( $ ipnum > 255 ) ) { return false ; } } return $ ip ; } | Validates if string is IP . |
20,832 | private function prepareRequestParams ( array $ data ) { $ has_resource = false ; $ multipart = [ ] ; foreach ( $ data as $ key => $ value ) { if ( ! is_array ( $ value ) ) { $ multipart [ ] = [ 'name' => $ key , 'contents' => $ value ] ; continue ; } foreach ( $ value as $ multiKey => $ multiValue ) { is_resource ( $ multiValue ) && $ has_resource = true ; $ multiName = $ key . '[' . $ multiKey . ']' . ( is_array ( $ multiValue ) ? '[' . key ( $ multiValue ) . ']' : '' ) . '' ; $ multipart [ ] = [ 'name' => $ multiName , 'contents' => ( is_array ( $ multiValue ) ? reset ( $ multiValue ) : $ multiValue ) ] ; } } if ( $ has_resource ) { return [ 'multipart' => $ multipart ] ; } return [ 'form_params' => $ data ] ; } | Prepare request params for POST request convert to multipart when needed |
20,833 | private function debugLog ( $ message ) { $ this -> debug_log_handler !== null && is_callable ( $ this -> debug_log_handler ) && call_user_func ( $ this -> debug_log_handler , $ message ) ; } | Write to debug log |
20,834 | private function endDebugStream ( ) { if ( is_resource ( $ this -> debug_log_stream_handle ) ) { rewind ( $ this -> debug_log_stream_handle ) ; $ this -> debugLog ( 'E621 API Verbose HTTP Request output:' . PHP_EOL . stream_get_contents ( $ this -> debug_log_stream_handle ) . PHP_EOL ) ; fclose ( $ this -> debug_log_stream_handle ) ; $ this -> debug_log_stream_handle = null ; } } | Write the temporary debug stream to log and close the stream handle |
20,835 | public function setProgressHandler ( $ progress_handler ) { if ( $ progress_handler !== null && is_callable ( $ progress_handler ) ) { $ this -> progress_handler = $ progress_handler ; } elseif ( $ progress_handler === null ) { $ this -> progress_handler = null ; } else { throw new \ InvalidArgumentException ( 'Argument "progress_handler" must be a callable' ) ; } } | Set progress handler |
20,836 | public function setDebugLogHandler ( $ debug_log_handler ) { if ( $ debug_log_handler !== null && is_callable ( $ debug_log_handler ) ) { $ this -> debug_log_handler = $ debug_log_handler ; } elseif ( $ debug_log_handler === null ) { $ this -> debug_log_handler = null ; } else { throw new \ InvalidArgumentException ( 'Argument "debug_log_handler" must be a callable' ) ; } } | Set debug log handler |
20,837 | public function login ( $ login , $ api_key ) { if ( empty ( $ login ) || ! is_string ( $ login ) ) { throw new \ InvalidArgumentException ( 'Argument "login" cannot be empty and must be a string' ) ; } if ( empty ( $ login ) || ! is_string ( $ api_key ) ) { throw new \ InvalidArgumentException ( 'Argument "api_key" cannot be empty and must be a string' ) ; } $ this -> auth = [ 'login' => $ login , 'password_hash' => $ api_key , ] ; } | Set login data globally |
20,838 | private function getClient ( ) : Client { if ( null !== $ this -> client ) { return $ this -> client ; } return $ this -> client = new Client ( $ this -> config [ 'carrier' ] , $ this -> config [ 'key' ] , $ this -> config [ 'cache' ] , $ this -> config [ 'debug' ] ) ; } | Returns the client . |
20,839 | public static function getCurrentBasket ( ) { $ settings = SuperCMSSession :: singleton ( ) ; try { $ user = SCmsLoginProvider :: getLoggedInUser ( ) ; try { $ basket = Basket :: findLast ( new AndGroup ( [ new Equals ( 'UserID' , $ user -> UniqueIdentifier ) , new Not ( new Equals ( 'Status' , self :: STATUS_COMPLETED ) ) ] ) ) ; } catch ( RecordNotFoundException $ ex ) { $ basket = new Basket ( ) ; $ basket -> UserID = $ user -> UniqueIdentifier ; $ basket -> save ( ) ; } if ( $ settings -> basketId != $ basket -> UniqueIdentifier ) { self :: joinAnonymousBasketItemsToUserBasket ( $ basket ) ; self :: updateSession ( $ basket ) ; } } catch ( NotLoggedInException $ ex ) { try { $ basket = new Basket ( $ settings -> basketId ) ; } catch ( RecordNotFoundException $ ex ) { $ basket = new Basket ( ) ; $ basket -> save ( ) ; self :: updateSession ( $ basket ) ; } } return $ basket ; } | Creates an instance of the basket and reloads the object . |
20,840 | public static function markBasketPaid ( Basket $ basket ) { $ basket -> Status = Basket :: STATUS_COMPLETED ; $ basket -> save ( ) ; $ session = SuperCMSSession :: singleton ( ) ; $ session -> basketId = 0 ; $ session -> storeSession ( ) ; } | Marks existing basket as paid and reloads all the settings for a new basket |
20,841 | protected function registerEvents ( WhatsApiEventsManager $ manager ) { foreach ( $ this -> events as $ event ) { if ( is_callable ( array ( $ this , $ event ) ) ) { $ manager -> bind ( $ event , [ $ this , $ event ] ) ; } } return $ this ; } | Binds events to the WhatsApiEventsManager |
20,842 | public function update ( RoleProcessor $ processor , $ roles ) { return $ processor -> update ( $ this , Input :: all ( ) , $ roles ) ; } | Update the role . |
20,843 | public function handle ( ) { $ admin = $ this -> app -> make ( 'orchestra.role' ) -> admin ( ) ; $ this -> acl -> allow ( $ admin -> name , [ 'Manage Users' , 'Manage Orchestra' , 'Manage Roles' , 'Manage Acl' ] ) ; } | Re - sync administrator access control . |
20,844 | public function get ( string $ name ) : AbstractCommand { if ( ! $ this -> has ( $ name ) ) { throw new CommandNotFoundException ( sprintf ( 'Command "%s" does not exist.' , $ name ) ) ; } return $ this -> container -> get ( $ this -> commandMap [ $ name ] ) ; } | Loads a command . |
20,845 | public function has ( $ name ) : bool { return isset ( $ this -> commandMap [ $ name ] ) && $ this -> container -> has ( $ this -> commandMap [ $ name ] ) ; } | Checks if a command exists . |
20,846 | static function getManager ( ? string $ name = null ) : \ Plasma \ Types \ TypeExtensionsManager { if ( $ name === null ) { if ( ! isset ( static :: $ instances [ static :: GLOBAL_NAME ] ) ) { static :: $ instances [ static :: GLOBAL_NAME ] = new static ( ) ; } return static :: $ instances [ static :: GLOBAL_NAME ] ; } if ( isset ( static :: $ instances [ $ name ] ) ) { return static :: $ instances [ $ name ] ; } throw new \ Plasma \ Exception ( 'Unknown name' ) ; } | Get a specific Type Extensions Manager under a specific name . |
20,847 | static function registerManager ( string $ name , ? \ Plasma \ Types \ TypeExtensionsManager $ manager = null ) : void { if ( isset ( static :: $ instances [ $ name ] ) ) { throw new \ Plasma \ Exception ( 'Name is already in use' ) ; } if ( $ manager === null ) { $ manager = new static ( ) ; } static :: $ instances [ $ name ] = $ manager ; } | Registers a specific Type Extensions Manager under a specific name . |
20,848 | function encodeType ( $ value , \ Plasma \ ColumnDefinitionInterface $ column ) : \ Plasma \ Types \ TypeExtensionResultInterface { $ type = \ gettype ( $ value ) ; if ( $ type === 'double' ) { $ type = 'float' ; } if ( $ type === 'object' ) { $ classes = \ array_merge ( array ( \ get_class ( $ value ) ) , \ class_parents ( $ value ) , \ class_implements ( $ value ) ) ; foreach ( $ this -> classTypes as $ key => $ encoder ) { if ( \ in_array ( $ key , $ classes , true ) ) { return $ encoder -> encode ( $ value , $ column ) ; } } } foreach ( $ this -> regularTypes as $ key => $ encoder ) { if ( $ type === $ key ) { return $ encoder -> encode ( $ value , $ column ) ; } } if ( $ this -> enabledFuzzySearch ) { foreach ( $ this -> classTypes as $ key => $ encoder ) { if ( $ encoder -> canHandleType ( $ value , $ column ) ) { return $ encoder -> encode ( $ value , $ column ) ; } } foreach ( $ this -> regularTypes as $ key => $ encoder ) { if ( $ encoder -> canHandleType ( $ value , $ column ) ) { return $ encoder -> encode ( $ value , $ column ) ; } } } throw new \ Plasma \ Exception ( 'Unable to encode given value' ) ; } | Tries to encode a value . |
20,849 | function decodeType ( $ type , $ value ) : \ Plasma \ Types \ TypeExtensionResultInterface { if ( $ type === null && $ this -> enabledFuzzySearch ) { foreach ( $ this -> dbTypes as $ dbType => $ decoder ) { if ( $ decoder -> canHandleType ( $ value , null ) ) { return $ decoder -> decode ( $ value ) ; } } } elseif ( isset ( $ this -> dbTypes [ $ type ] ) ) { return $ this -> dbTypes [ $ type ] -> decode ( $ value ) ; } throw new \ Plasma \ Exception ( 'Unable to decode given value' ) ; } | Tries to decode a value . |
20,850 | function parseValue ( $ value ) { try { return \ Plasma \ Types \ TypeExtensionsManager :: getManager ( ) -> decodeType ( $ this -> type , $ value ) -> getValue ( ) ; } catch ( \ Plasma \ Exception $ e ) { } return $ value ; } | Parses the row value into the field type . |
20,851 | public function updateQueryBuilder ( $ builder ) { if ( SiteTree :: has_extension ( 'SolrIndexable' ) && SiteTree :: has_extension ( 'SiteTreePermissionIndexExtension' ) && ClassInfo :: exists ( 'QueuedJob' ) ) { $ groups = array ( 'anyone' ) ; $ user = Member :: currentUser ( ) ; if ( $ user ) { if ( Permission :: checkMember ( $ user , array ( 'ADMIN' , 'SITETREE_VIEW_ALL' ) ) ) { return ; } $ groups [ ] = 'logged-in' ; foreach ( $ user -> Groups ( ) as $ group ) { $ groups [ ] = ( string ) $ group -> ID ; } } $ builder -> andWith ( 'Groups_ms' , $ groups ) ; } } | Apply the current user permissions against the solr query builder . |
20,852 | public function sendQuery ( ) : Response { $ data = [ 'query' => $ this -> getGraphQL ( ) , 'variables' => $ this -> getVariables ( ) , ] ; if ( $ this -> operationName ) { $ data [ 'operationName' ] = $ this -> operationName ; } $ content = json_encode ( $ data ) ; $ this -> insulated = $ this -> config [ 'insulated' ] ?? false ; $ this -> sendRequest ( Request :: METHOD_POST , $ this -> getEndpoint ( ) , $ this -> getRequestsParameters ( ) , [ ] , $ this -> getServerParameters ( ) , $ content ) ; return $ this -> response = $ this -> getResponse ( ) ; } | Send the configured query or mutation with given variables |
20,853 | public function sendRequest ( $ method , $ uri , array $ parameters = [ ] , array $ files = [ ] , array $ server = [ ] , $ content = null , $ changeHistory = true ) { set_error_handler ( function ( $ level , $ message , $ errFile , $ errLine ) { if ( $ this -> deprecationAdviser ) { $ this -> deprecationAdviser -> addWarning ( $ message , $ errFile , $ errLine ) ; } } , E_USER_DEPRECATED ) ; $ result = parent :: request ( $ method , $ uri , $ parameters , $ files , $ server , $ content , $ changeHistory ) ; restore_error_handler ( ) ; return $ result ; } | This method works like request in the parent class but has a error handler to catch all deprecation notices . Can t be named request to override the parent because in projects using symfony4 the signature for this method has been changed using strict types on each argument . |
20,854 | public function getUrl ( $ service , $ url , $ params = [ ] ) { if ( ! empty ( $ this -> stubs [ $ service ] ) ) { $ tokens = [ ] ; $ params [ 'url' ] = $ url ; foreach ( $ this -> tokens as $ token ) { $ tokens [ '/{' . $ token . '}/' ] = urlencode ( ! empty ( $ params [ $ token ] ) ? $ params [ $ token ] : '' ) ; } return preg_replace ( array_keys ( $ tokens ) , $ tokens , $ this -> stubs [ $ service ] ) ; } } | Creates a share URL |
20,855 | public function create ( $ funcName ) { $ dirname = dirname ( __FILE__ ) . '/functions' ; $ filename = "$dirname/Function_$funcName.php" ; if ( ! file_exists ( $ filename ) ) { return null ; } require_once "$dirname/Function_$funcName.php" ; $ funcClassName = '\\figdice\\classes\\functions\\Function_' . $ funcName ; $ reflection = new \ ReflectionClass ( $ funcClassName ) ; $ function = $ reflection -> newInstance ( ) ; return $ function ; } | Returns an instance of the Function class that handles the requested function . |
20,856 | protected function buildMessage ( array $ errors ) { $ errorList = array ( ) ; foreach ( $ errors as $ error ) { $ errorList [ ] = sprintf ( ' - [%s] %s' , $ error [ 'property' ] , $ error [ 'message' ] ) ; } return sprintf ( "The supplied Composer configuration is invalid:\n%s" , implode ( "\n" , $ errorList ) ) ; } | Build the exception message . |
20,857 | public function send ( Email $ email ) { $ apiKey = $ this -> config ( 'apiKey' ) ; $ adapter = new CakeHttpAdapter ( new Client ( ) ) ; $ sparkpost = new SparkPost ( $ adapter , [ 'key' => $ apiKey ] ) ; $ from = ( array ) $ email -> from ( ) ; $ sender = sprintf ( '%s <%s>' , mb_encode_mimeheader ( array_values ( $ from ) [ 0 ] ) , array_keys ( $ from ) [ 0 ] ) ; $ to = ( array ) $ email -> to ( ) ; $ replyTo = $ email -> getReplyTo ( ) ? array_values ( $ email -> getReplyTo ( ) ) [ 0 ] : null ; foreach ( $ to as $ toEmail => $ toName ) { $ recipients [ ] = [ 'address' => [ 'name' => mb_encode_mimeheader ( $ toName ) , 'email' => $ toEmail ] ] ; } $ message = [ 'from' => $ sender , 'html' => empty ( $ email -> message ( 'html' ) ) ? $ email -> message ( 'text' ) : $ email -> message ( 'html' ) , 'text' => $ email -> message ( 'text' ) , 'subject' => mb_decode_mimeheader ( $ email -> subject ( ) ) , 'recipients' => $ recipients ] ; if ( $ replyTo ) { $ message [ 'replyTo' ] = $ replyTo ; } try { $ sparkpost -> transmission -> send ( $ message ) ; } catch ( APIResponseException $ e ) { throw new BadRequestException ( sprintf ( 'SparkPost API error %d (%d): %s (%s)' , $ e -> getAPICode ( ) , $ e -> getCode ( ) , ucfirst ( $ e -> getAPIMessage ( ) ) , $ e -> getAPIDescription ( ) ) ) ; } } | Send mail via SparkPost REST API |
20,858 | protected function get ( $ place , $ args = array ( ) ) { $ sep = isset ( $ args [ 'seperator' ] ) ? $ args [ 'seperator' ] : ' ' ; $ content = '' ; if ( isset ( $ this -> content [ $ place ] ) ) { foreach ( $ this -> content [ $ place ] as $ item ) { if ( $ this -> options [ 'debug' ] === true ) { $ content .= '<!--Skinny:Place: ' . $ place . ' ; } switch ( $ item [ 'type' ] ) { case 'hook' : $ content .= call_user_method_array ( $ item [ 'hook' ] [ 0 ] , $ item [ 'hook' ] [ 1 ] , array ( $ args , $ item [ 'arguments' ] ) ) ; break ; case 'html' : $ content .= $ sep . ( string ) $ item [ 'html' ] ; break ; case 'template' : $ content .= $ this -> render ( $ item [ 'template' ] , $ item [ 'params' ] ) ; break ; } } } return $ content ; } | Run content content optionally passing arguments to provide to object methods |
20,859 | protected function configureIO ( ) { if ( $ this -> consoleInput -> hasParameterOption ( [ '--ansi' ] , true ) ) { $ this -> consoleOutput -> setDecorated ( true ) ; } elseif ( $ this -> consoleInput -> hasParameterOption ( [ '--no-ansi' ] , true ) ) { $ this -> consoleOutput -> setDecorated ( false ) ; } if ( $ this -> consoleInput -> hasParameterOption ( [ '--no-interaction' , '-n' ] , true ) ) { $ this -> consoleInput -> setInteractive ( false ) ; } if ( $ this -> consoleInput -> hasParameterOption ( [ '--quiet' , '-q' ] , true ) ) { $ this -> consoleOutput -> setVerbosity ( OutputInterface :: VERBOSITY_QUIET ) ; $ this -> consoleInput -> setInteractive ( false ) ; } else { if ( $ this -> consoleInput -> hasParameterOption ( '-vvv' , true ) || $ this -> consoleInput -> hasParameterOption ( '--verbose=3' , true ) || $ this -> consoleInput -> getParameterOption ( '--verbose' , false , true ) === 3 ) { $ this -> consoleOutput -> setVerbosity ( OutputInterface :: VERBOSITY_DEBUG ) ; } elseif ( $ this -> consoleInput -> hasParameterOption ( '-vv' , true ) || $ this -> consoleInput -> hasParameterOption ( '--verbose=2' , true ) || $ this -> consoleInput -> getParameterOption ( '--verbose' , false , true ) === 2 ) { $ this -> consoleOutput -> setVerbosity ( OutputInterface :: VERBOSITY_VERY_VERBOSE ) ; } elseif ( $ this -> consoleInput -> hasParameterOption ( '-v' , true ) || $ this -> consoleInput -> hasParameterOption ( '--verbose=1' , true ) || $ this -> consoleInput -> hasParameterOption ( '--verbose' , true ) || $ this -> consoleInput -> getParameterOption ( '--verbose' , false , true ) ) { $ this -> consoleOutput -> setVerbosity ( OutputInterface :: VERBOSITY_VERBOSE ) ; } } } | Configures the console input and output instances for the process . |
20,860 | public function findNamespace ( string $ namespace ) : string { $ allNamespaces = $ this -> getNamespaces ( ) ; $ expr = preg_replace_callback ( '{([^:]+|)}' , function ( $ matches ) { return preg_quote ( $ matches [ 1 ] ) . '[^:]*' ; } , $ namespace ) ; $ namespaces = preg_grep ( '{^' . $ expr . '}' , $ allNamespaces ) ; if ( empty ( $ namespaces ) ) { throw new NamespaceNotFoundException ( sprintf ( 'There are no commands defined in the "%s" namespace.' , $ namespace ) ) ; } $ exact = \ in_array ( $ namespace , $ namespaces , true ) ; if ( \ count ( $ namespaces ) > 1 && ! $ exact ) { throw new NamespaceNotFoundException ( sprintf ( 'The namespace "%s" is ambiguous.' , $ namespace ) ) ; } return $ exact ? $ namespace : reset ( $ namespaces ) ; } | Finds a registered namespace by a name . |
20,861 | public function getAllCommands ( string $ namespace = '' ) : array { $ this -> initCommands ( ) ; if ( $ namespace === '' ) { $ commands = $ this -> commands ; if ( ! $ this -> commandLoader ) { return $ commands ; } foreach ( $ this -> commandLoader -> getNames ( ) as $ name ) { if ( ! isset ( $ commands [ $ name ] ) ) { $ commands [ $ name ] = $ this -> getCommand ( $ name ) ; } } return $ commands ; } $ commands = [ ] ; foreach ( $ this -> commands as $ name => $ command ) { if ( $ namespace === $ this -> extractNamespace ( $ name , substr_count ( $ namespace , ':' ) + 1 ) ) { $ commands [ $ name ] = $ command ; } } if ( $ this -> commandLoader ) { foreach ( $ this -> commandLoader -> getNames ( ) as $ name ) { if ( ! isset ( $ commands [ $ name ] ) && $ namespace === $ this -> extractNamespace ( $ name , substr_count ( $ namespace , ':' ) + 1 ) ) { $ commands [ $ name ] = $ this -> getCommand ( $ name ) ; } } } return $ commands ; } | Gets all commands including those available through a command loader optionally filtered on a command namespace . |
20,862 | protected function getDefaultInputDefinition ( ) : InputDefinition { return new InputDefinition ( [ new InputArgument ( 'command' , InputArgument :: REQUIRED , 'The command to execute' ) , new InputOption ( '--help' , '-h' , InputOption :: VALUE_NONE , 'Display the help information' ) , new InputOption ( '--quiet' , '-q' , InputOption :: VALUE_NONE , 'Flag indicating that all output should be silenced' ) , new InputOption ( '--verbose' , '-v|vv|vvv' , InputOption :: VALUE_NONE , 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug' ) , new InputOption ( '--ansi' , '' , InputOption :: VALUE_NONE , 'Force ANSI output' ) , new InputOption ( '--no-ansi' , '' , InputOption :: VALUE_NONE , 'Disable ANSI output' ) , new InputOption ( '--no-interaction' , '-n' , InputOption :: VALUE_NONE , 'Flag to disable interacting with the user' ) , ] ) ; } | Builds the defauilt input definition . |
20,863 | public function getHelperSet ( ) : HelperSet { if ( ! $ this -> helperSet ) { $ this -> helperSet = $ this -> getDefaultHelperSet ( ) ; } return $ this -> helperSet ; } | Get the helper set associated with the application . |
20,864 | public function getLongVersion ( ) : string { $ name = $ this -> getName ( ) ; if ( $ name === '' ) { $ name = 'Joomla Console Application' ; } if ( $ this -> getVersion ( ) !== '' ) { return sprintf ( '%s <info>%s</info>' , $ name , $ this -> getVersion ( ) ) ; } return $ name ; } | Get the long version string for the application . |
20,865 | public function hasCommand ( string $ name ) : bool { $ this -> initCommands ( ) ; if ( isset ( $ this -> commands [ $ name ] ) ) { return true ; } if ( ! $ this -> commandLoader ) { return false ; } return $ this -> commandLoader -> has ( $ name ) ; } | Check if the application has a command with the given name . |
20,866 | private function initCommands ( ) { if ( $ this -> initialised ) { return ; } $ this -> initialised = true ; foreach ( $ this -> getDefaultCommands ( ) as $ command ) { $ this -> addCommand ( $ command ) ; } } | Internal function to initialise the command store this allows the store to be lazy loaded only when needed . |
20,867 | protected function extendCreate ( ValidatorResolver $ validator ) { $ name = Keyword :: make ( $ validator -> getData ( ) [ 'name' ] ) ; $ validator -> after ( function ( ValidatorResolver $ v ) use ( $ name ) { if ( $ this -> isRoleNameAlreadyUsed ( $ name ) ) { $ v -> errors ( ) -> add ( 'name' , trans ( 'orchestra/control::response.roles.reserved-word' ) ) ; } } ) ; } | Extend create validations . |
20,868 | protected function extendUpdate ( ValidatorResolver $ validator ) { $ name = Keyword :: make ( $ validator -> getData ( ) [ 'name' ] ) ; $ validator -> after ( function ( ValidatorResolver $ v ) use ( $ name ) { if ( $ this -> isRoleNameGuest ( $ name ) ) { $ v -> errors ( ) -> add ( 'name' , trans ( 'orchestra/control::response.roles.reserved-word' ) ) ; } } ) ; } | Extend update validations . |
20,869 | protected function isRoleNameAlreadyUsed ( Keyword $ name ) : bool { $ roles = Foundation :: acl ( ) -> roles ( ) -> get ( ) ; return $ name -> searchIn ( $ roles ) !== false ; } | Check if role name is already used . |
20,870 | protected function decorateSubreportsDataSource ( ) : void { $ builder = $ this -> getContainerBuilder ( ) ; $ subreports = $ builder -> findByTag ( self :: TAG_CACHE ) ; foreach ( $ subreports as $ service => $ tag ) { $ serviceDef = $ builder -> getDefinition ( $ service ) ; if ( ! is_subclass_of ( ( string ) $ serviceDef -> getType ( ) , DataSource :: class ) ) { throw new AssertionException ( sprintf ( 'Please use tag "%s" only on datasource (object %s found in %s).' , self :: TAG_CACHE , $ serviceDef -> getType ( ) , $ service ) ) ; } if ( ! isset ( $ tag [ 'key' ] ) ) $ tag [ 'key' ] = $ serviceDef -> getTag ( self :: TAG_SUBREPORT_DATASOURCE ) ; $ this -> validateConfig ( $ this -> scheme [ 'tags' ] [ self :: TAG_CACHE ] , $ tag , sprintf ( '%s' , self :: TAG_CACHE ) ) ; $ wrappedDef = $ builder -> addDefinition ( sprintf ( '%s_cached' , $ service ) , $ serviceDef ) ; $ builder -> removeDefinition ( $ service ) ; $ builder -> addDefinition ( $ service ) -> setFactory ( CachedDataSource :: class , [ 1 => $ wrappedDef ] ) -> addSetup ( 'setKey' , [ $ tag [ 'key' ] ] ) -> addSetup ( 'setExpiration' , [ $ tag [ 'expiration' ] ] ) -> addTag ( self :: TAG_SUBREPORT_DATASOURCE , $ wrappedDef -> getTag ( self :: TAG_SUBREPORT_DATASOURCE ) ) ; $ subreportDef = $ builder -> getDefinition ( $ wrappedDef -> getTag ( self :: TAG_SUBREPORT_DATASOURCE ) ) ; $ introspection = $ subreportDef -> getTag ( self :: TAG_INTROSPECTION ) ; $ introspection [ 'cache' ] = [ 'datasource' => $ tag ] ; $ subreportDef -> addTag ( self :: TAG_INTROSPECTION , $ introspection ) ; } } | Make subreport cachable - cache tags |
20,871 | public function evaluate ( Context $ context , $ expression ) { if ( is_numeric ( $ expression ) ) { $ expression = ( string ) $ expression ; } if ( ! isset ( $ context -> view -> lexers [ $ expression ] ) ) { $ lexer = new Lexer ( $ expression ) ; $ context -> view -> lexers [ $ expression ] = & $ lexer ; $ lexer -> parse ( $ context ) ; } else { $ lexer = & $ context -> view -> lexers [ $ expression ] ; } $ result = $ lexer -> evaluate ( $ context ) ; return $ result ; } | Evaluate the XPath - like expression on the data object associated to the view . |
20,872 | public static function el ( $ name = NULL , $ attrs = NULL ) { $ el = new static ; $ parts = explode ( ' ' , ( string ) $ name , 2 ) ; $ el -> setName ( $ parts [ 0 ] ) ; if ( is_array ( $ attrs ) ) { $ el -> attrs = $ attrs ; } elseif ( $ attrs !== NULL ) { $ el -> setText ( $ attrs ) ; } if ( isset ( $ parts [ 1 ] ) ) { $ matches = preg_match_all ( '#([a-z0-9:-]+)(?:=(["\'])?(.*?)(?(2)\\2|\s))?#i' , $ parts [ 1 ] . ' ' , $ matches , PREG_SET_ORDER ) ; foreach ( $ matches as $ m ) { $ el -> attrs [ $ m [ 1 ] ] = isset ( $ m [ 3 ] ) ? $ m [ 3 ] : TRUE ; } } return $ el ; } | Static factory . |
20,873 | public function setName ( $ name , $ isEmpty = NULL ) { if ( $ name !== NULL && ! is_string ( $ name ) ) { throw new InvalidArgumentException ( sprintf ( 'Name must be string or NULL, %s given.' , gettype ( $ name ) ) ) ; } $ this -> name = $ name ; $ this -> isEmpty = $ isEmpty === NULL ? isset ( static :: $ emptyElements [ $ name ] ) : ( bool ) $ isEmpty ; return $ this ; } | Changes element s name . |
20,874 | public function appendAttribute ( $ name , $ value , $ option = TRUE ) { if ( is_array ( $ value ) ) { $ prev = isset ( $ this -> attrs [ $ name ] ) ? ( array ) $ this -> attrs [ $ name ] : [ ] ; $ this -> attrs [ $ name ] = $ value + $ prev ; } elseif ( ( string ) $ value === '' ) { $ tmp = & $ this -> attrs [ $ name ] ; } elseif ( ! isset ( $ this -> attrs [ $ name ] ) || is_array ( $ this -> attrs [ $ name ] ) ) { $ this -> attrs [ $ name ] [ $ value ] = $ option ; } else { $ this -> attrs [ $ name ] = [ $ this -> attrs [ $ name ] => TRUE , $ value => $ option ] ; } return $ this ; } | Appends value to element s attribute . |
20,875 | public function getAttribute ( $ name ) { return isset ( $ this -> attrs [ $ name ] ) ? $ this -> attrs [ $ name ] : NULL ; } | Returns element s attribute . |
20,876 | public function href ( $ path , $ query = NULL ) { if ( $ query ) { $ query = http_build_query ( $ query , '' , '&' ) ; if ( $ query !== '' ) { $ path .= '?' . $ query ; } } $ this -> attrs [ 'href' ] = $ path ; return $ this ; } | Special setter for element s attribute . |
20,877 | public function setHtml ( $ html ) { if ( is_array ( $ html ) ) { throw new InvalidArgumentException ( sprintf ( 'Textual content must be a scalar, %s given.' , gettype ( $ html ) ) ) ; } $ this -> removeChildren ( ) ; $ this -> children [ ] = ( string ) $ html ; return $ this ; } | Sets element s HTML content . |
20,878 | public function getHtml ( ) { $ s = '' ; foreach ( $ this -> children as $ child ) { if ( is_object ( $ child ) ) { $ s .= $ child -> render ( ) ; } else { $ s .= $ child ; } } return $ s ; } | Returns element s HTML content . |
20,879 | public function setText ( $ text ) { if ( ! is_array ( $ text ) && ! $ text instanceof self ) { $ text = htmlspecialchars ( ( string ) $ text , ENT_NOQUOTES , 'UTF-8' ) ; } return $ this -> setHtml ( $ text ) ; } | Sets element s textual content . |
20,880 | public function create ( $ name , $ attrs = NULL ) { $ this -> insert ( NULL , $ child = static :: el ( $ name , $ attrs ) ) ; return $ child ; } | Creates and adds a new Html child . |
20,881 | public function insert ( $ index , $ child , $ replace = FALSE ) { if ( $ child instanceof self || is_scalar ( $ child ) ) { if ( $ index === NULL ) { $ this -> children [ ] = $ child ; } else { array_splice ( $ this -> children , ( int ) $ index , $ replace ? 1 : 0 , [ $ child ] ) ; } } else { throw new InvalidArgumentException ( sprintf ( 'Child node must be scalar or Html object, %s given.' , is_object ( $ child ) ? get_class ( $ child ) : gettype ( $ child ) ) ) ; } return $ this ; } | Inserts child node . |
20,882 | public function render ( $ indent = NULL ) { $ s = $ this -> startTag ( ) ; if ( ! $ this -> isEmpty ) { if ( $ indent !== NULL ) { $ indent ++ ; } foreach ( $ this -> children as $ child ) { if ( is_object ( $ child ) ) { $ s .= $ child -> render ( $ indent ) ; } else { $ s .= $ child ; } } $ s .= $ this -> endTag ( ) ; } if ( $ indent !== NULL ) { return "\n" . str_repeat ( "\t" , $ indent - 1 ) . $ s . "\n" . str_repeat ( "\t" , max ( 0 , $ indent - 2 ) ) ; } return $ s ; } | Renders element s start tag content and end tag . |
20,883 | public function startTag ( ) { if ( $ this -> name ) { return '<' . $ this -> name . $ this -> attributes ( ) . ( static :: $ xhtml && $ this -> isEmpty ? ' />' : '>' ) ; } else { return '' ; } } | Returns element s start tag . |
20,884 | public function attributes ( ) { if ( ! is_array ( $ this -> attrs ) ) { return '' ; } $ s = '' ; $ attrs = $ this -> attrs ; foreach ( $ attrs as $ key => $ value ) { if ( $ value === NULL || $ value === FALSE ) { continue ; } elseif ( $ value === TRUE ) { if ( static :: $ xhtml ) { $ s .= ' ' . $ key . '="' . $ key . '"' ; } else { $ s .= ' ' . $ key ; } continue ; } elseif ( is_array ( $ value ) ) { if ( strncmp ( $ key , 'data-' , 5 ) === 0 ) { $ value = json_encode ( $ value ) ; } else { $ tmp = NULL ; foreach ( $ value as $ k => $ v ) { if ( $ v != NULL ) { $ tmp [ ] = $ v === TRUE ? $ k : ( is_string ( $ k ) ? $ k . ':' . $ v : $ v ) ; } } if ( $ tmp === NULL ) { continue ; } $ value = implode ( $ key === 'style' || ! strncmp ( $ key , 'on' , 2 ) ? ';' : ' ' , $ tmp ) ; } } elseif ( is_float ( $ value ) ) { $ value = rtrim ( rtrim ( number_format ( $ value , 10 , '.' , '' ) , '0' ) , '.' ) ; } else { $ value = ( string ) $ value ; } $ q = strpos ( $ value , '"' ) === FALSE ? '"' : "'" ; $ s .= ' ' . $ key . '=' . $ q . str_replace ( [ '&' , $ q , '<' ] , [ '&' , $ q === '"' ? '"' : ''' , self :: $ xhtml ? '<' : '<' ] , $ value ) . ( strpos ( $ value , '`' ) !== FALSE && strpbrk ( $ value , ' <>"\'' ) === FALSE ? ' ' : '' ) . $ q ; } $ s = str_replace ( '@' , '@' , $ s ) ; return $ s ; } | Returns element s attributes . |
20,885 | protected function request ( $ method , $ endpoint , $ options = [ ] ) { return $ this -> unwrapResponse ( $ this -> getHttpClient ( $ this -> getBaseOptions ( ) ) -> { $ method } ( $ endpoint , $ options ) ) ; } | Make a http request . |
20,886 | public function subscribe ( $ id , string $ channel , $ args , Request $ request , \ DateTime $ expireAt = null ) : void { $ this -> convertNodes ( $ args ) ; $ this -> pubSubHandler -> sub ( $ channel , $ id , [ 'channel' => $ channel , 'arguments' => $ args , 'request' => $ request , ] , $ expireAt ) ; } | Subscribe given request to given subscription when this subscription is dispatched this request will be executed |
20,887 | private function convertNodes ( array & $ data ) : void { array_walk_recursive ( $ data , function ( & $ value ) { if ( $ value instanceof NodeInterface ) { $ value = IDEncoder :: encode ( $ value ) ; } } ) ; } | Convert nodes to ID |
20,888 | private function sendRequest ( Request $ originRequest , SubscriptionMessage $ message , OutputInterface $ output , bool $ debug = false ) : void { $ host = $ originRequest -> getHost ( ) ; $ port = $ originRequest -> getPort ( ) ; $ path = $ originRequest -> getPathInfo ( ) ; $ handle = fsockopen ( $ originRequest -> isSecure ( ) ? 'ssl://' . $ host : $ host , $ port , $ errno , $ errstr , 10 ) ; $ signer = new Sha256 ( ) ; $ subscriptionToken = ( new Builder ( ) ) -> setId ( $ message -> getId ( ) ) -> set ( 'data' , serialize ( $ message -> getData ( ) ) ) -> setIssuedAt ( time ( ) ) -> setNotBefore ( time ( ) + 60 ) -> setExpiration ( time ( ) + 60 ) -> sign ( $ signer , $ this -> secret ) -> getToken ( ) ; $ body = $ originRequest -> getContent ( ) ; $ length = strlen ( $ body ) ; $ out = "POST $path HTTP/1.1\r\n" ; $ out .= "Host: $host\r\n" ; $ auth = $ originRequest -> headers -> get ( 'Authorization' ) ; $ out .= "Authorization: $auth\r\n" ; $ out .= "Subscription: $subscriptionToken\r\n" ; $ out .= "Content-Length: $length\r\n" ; $ out .= "Content-Type: application/json\r\n" ; $ out .= "Connection: Close\r\n\r\n" ; $ out .= $ body ; fwrite ( $ handle , $ out ) ; if ( $ debug ) { $ output -> writeln ( sprintf ( '[DEBUG] Getting response for subscription %s' , $ message -> getId ( ) ) ) ; while ( true ) { $ buffer = fgets ( $ handle ) ; if ( ! $ buffer ) { break ; } $ output -> write ( $ buffer ) ; } } fclose ( $ handle ) ; } | Send a subscription request |
20,889 | public function describe ( OutputInterface $ output , $ object , array $ options = [ ] ) { $ this -> output = $ output ; switch ( true ) { case $ object instanceof Application : $ this -> describeJoomlaApplication ( $ object , $ options ) ; break ; case $ object instanceof AbstractCommand : $ this -> describeConsoleCommand ( $ object , $ options ) ; break ; default : parent :: describe ( $ output , $ object , $ options ) ; } } | Describes an object . |
20,890 | private function describeConsoleCommand ( AbstractCommand $ command , array $ options ) { $ command -> getSynopsis ( true ) ; $ command -> getSynopsis ( false ) ; $ command -> mergeApplicationDefinition ( false ) ; $ this -> writeText ( '<comment>Usage:</comment>' , $ options ) ; foreach ( array_merge ( [ $ command -> getSynopsis ( true ) ] , $ command -> getAliases ( ) ) as $ usage ) { $ this -> writeText ( "\n" ) ; $ this -> writeText ( ' ' . $ usage , $ options ) ; } $ this -> writeText ( "\n" ) ; $ definition = $ command -> getDefinition ( ) ; if ( $ definition -> getOptions ( ) || $ definition -> getArguments ( ) ) { $ this -> writeText ( "\n" ) ; $ this -> describeInputDefinition ( $ definition , $ options ) ; $ this -> writeText ( "\n" ) ; } if ( $ help = $ command -> getProcessedHelp ( ) ) { $ this -> writeText ( "\n" ) ; $ this -> writeText ( '<comment>Help:</comment>' , $ options ) ; $ this -> writeText ( "\n" ) ; $ this -> writeText ( ' ' . str_replace ( "\n" , "\n " , $ help ) , $ options ) ; $ this -> writeText ( "\n" ) ; } } | Describes a command . |
20,891 | private function describeJoomlaApplication ( Application $ app , array $ options ) { $ describedNamespace = $ options [ 'namespace' ] ?? '' ; $ description = new ApplicationDescription ( $ app , $ describedNamespace ) ; $ version = $ app -> getLongVersion ( ) ; if ( $ version !== '' ) { $ this -> writeText ( "$version\n\n" , $ options ) ; } $ this -> writeText ( "<comment>Usage:</comment>\n" ) ; $ this -> writeText ( " command [options] [arguments]\n\n" ) ; $ this -> describeInputDefinition ( new InputDefinition ( $ app -> getDefinition ( ) -> getOptions ( ) ) , $ options ) ; $ this -> writeText ( "\n" ) ; $ this -> writeText ( "\n" ) ; $ commands = $ description -> getCommands ( ) ; $ namespaces = $ description -> getNamespaces ( ) ; if ( $ describedNamespace && $ namespaces ) { $ describedNamespaceInfo = reset ( $ namespaces ) ; foreach ( $ describedNamespaceInfo [ 'commands' ] as $ name ) { $ commands [ $ name ] = $ description -> getCommand ( $ name ) ; } } $ width = $ this -> getColumnWidth ( \ call_user_func_array ( 'array_merge' , array_map ( function ( $ namespace ) use ( $ commands ) { return array_intersect ( $ namespace [ 'commands' ] , array_keys ( $ commands ) ) ; } , $ namespaces ) ) ) ; if ( $ describedNamespace ) { $ this -> writeText ( sprintf ( '<comment>Available commands for the "%s" namespace:</comment>' , $ describedNamespace ) , $ options ) ; } else { $ this -> writeText ( '<comment>Available commands:</comment>' , $ options ) ; } foreach ( $ namespaces as $ namespace ) { $ namespace [ 'commands' ] = array_filter ( $ namespace [ 'commands' ] , function ( $ name ) use ( $ commands ) { return isset ( $ commands [ $ name ] ) ; } ) ; if ( ! $ namespace [ 'commands' ] ) { continue ; } if ( ! $ describedNamespace && $ namespace [ 'id' ] !== ApplicationDescription :: GLOBAL_NAMESPACE ) { $ this -> writeText ( "\n" ) ; $ this -> writeText ( ' <comment>' . $ namespace [ 'id' ] . '</comment>' , $ options ) ; } foreach ( $ namespace [ 'commands' ] as $ name ) { $ this -> writeText ( "\n" ) ; $ spacingWidth = $ width - StringHelper :: strlen ( $ name ) ; $ command = $ commands [ $ name ] ; $ commandAliases = $ name === $ command -> getName ( ) ? $ this -> getCommandAliasesText ( $ command ) : '' ; $ this -> writeText ( sprintf ( ' <info>%s</info>%s%s' , $ name , str_repeat ( ' ' , $ spacingWidth ) , $ commandAliases . $ command -> getDescription ( ) ) , $ options ) ; } } $ this -> writeText ( "\n" ) ; } | Describes an application . |
20,892 | private function getColumnWidth ( array $ commands ) : int { $ widths = [ ] ; foreach ( $ commands as $ command ) { if ( $ command instanceof AbstractCommand ) { $ widths [ ] = StringHelper :: strlen ( $ command -> getName ( ) ) ; foreach ( $ command -> getAliases ( ) as $ alias ) { $ widths [ ] = StringHelper :: strlen ( $ alias ) ; } } else { $ widths [ ] = StringHelper :: strlen ( $ command ) ; } } return $ widths ? max ( $ widths ) + 2 : 0 ; } | Calculate the column width for a group of commands . |
20,893 | public function findValidToken ( Query $ query , array $ options ) { $ options += [ 'token' => null , 'expires >' => new DateTimeImmutable ( ) , 'status' => false ] ; return $ query -> where ( $ options ) ; } | Custom finder validToken . |
20,894 | public function setStatus ( $ id , $ status ) { if ( ! is_numeric ( $ status ) ) { throw new Exception ( 'Status argument must be an integer' ) ; } $ entity = $ this -> findById ( $ id ) -> firstOrFail ( ) ; $ entity -> status = $ status ; $ this -> save ( $ entity ) ; return $ entity ; } | Set token status . |
20,895 | public function activate ( Processor $ processor , $ type , $ id ) { return $ processor -> activate ( $ this , $ type , $ id ) ; } | Set active theme for Orchestra Platform . |
20,896 | public function themeHasActivated ( $ type , $ id ) { $ message = \ trans ( 'orchestra/control::response.themes.update' , [ 'type' => Str :: title ( $ type ) , ] ) ; return $ this -> redirectWithMessage ( \ handles ( "orchestra::control/themes/{$type}" ) , $ message ) ; } | Response when theme activation succeed . |
20,897 | private function fig_dictionary ( Context $ context ) { $ file = $ this -> dicFile ; $ filename = $ context -> view -> getTranslationPath ( ) . '/' . $ context -> view -> getLanguage ( ) . '/' . $ file ; $ dictionary = new Dictionary ( $ filename , $ this -> source ) ; if ( ( $ context -> view -> getLanguage ( ) == '' ) || ( $ this -> source == $ context -> view -> getLanguage ( ) ) ) { $ context -> addDictionary ( $ dictionary , $ this -> dicName ) ; return '' ; } try { if ( $ context -> view -> getCachePath ( ) ) { $ tmpFile = $ context -> getView ( ) -> getCachePath ( ) . '/' . 'Dictionary' . '/' . $ context -> getView ( ) -> getLanguage ( ) . '/' . $ file . '.php' ; if ( file_exists ( $ tmpFile ) ) { if ( file_exists ( $ filename ) && ( filemtime ( $ tmpFile ) < filemtime ( $ filename ) ) ) { Dictionary :: compile ( $ filename , $ tmpFile ) ; } } else { Dictionary :: compile ( $ filename , $ tmpFile ) ; } $ dictionary -> restore ( $ tmpFile ) ; } else { $ dictionary -> load ( ) ; } } catch ( FileNotFoundException $ ex ) { throw new FileNotFoundException ( 'Translation file not found: file=' . $ filename . ', language=' . $ context -> view -> getLanguage ( ) . ', source=' . $ context -> getFilename ( ) , $ context -> getFilename ( ) ) ; } $ context -> addDictionary ( $ dictionary , $ this -> dicName ) ; return '' ; } | Loads a language XML file to be used within the current view . |
20,898 | public static function decode ( $ json , $ assoc = false ) { if ( $ json instanceof Response ) { return json_decode ( $ json -> getContent ( ) , $ assoc ) ; } return json_decode ( $ json , $ assoc ) ; } | Decode a json unlike the build - in decode support a Response as argument |
20,899 | public function validate ( $ data ) { $ this -> validator -> reset ( ) ; $ this -> validator -> check ( $ data , $ this -> schema ( ) ) ; if ( ! $ this -> validator -> isValid ( ) ) { throw new InvalidConfigurationException ( $ this -> validator -> getErrors ( ) ) ; } } | Validate Composer configuration data . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.