idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
15,100 | public function actionRemoveFile ( $ fileId , $ productId , $ languageId ) { if ( \ Yii :: $ app -> user -> can ( 'updateProduct' , [ 'productOwner' => Product :: findOne ( $ productId ) -> owner ] ) ) { ProductFile :: deleteAll ( [ 'id' => $ fileId ] ) ; $ this -> trigger ( self :: EVENT_AFTER_EDIT_PRODUCT , new Produ... | Users which have updateOwnProduct permission can delete file only from Product models that have been created by their . Users which have updateProduct permission can delete file from all Product models . |
15,101 | public function createToken ( ? Authenticatable $ user , ? string $ email = null ) : Model { if ( $ user === null ) { throw new NullValueException ( "User cannot be null" ) ; } $ email = $ email ?? $ user -> email ; if ( $ this -> canInsertToken ( $ user , $ email ) ) { return $ this -> insertToken ( $ user , $ this ->... | Create and insert token |
15,102 | public function renewToken ( ? Token $ token ) : Token { if ( $ token === null ) { throw new NullValueException ( "Token cannot be null" ) ; } $ token -> updateExisting ( [ 'token' => $ this -> generateToken ( $ this -> config -> get ( 'app.key' ) ) , ] ) ; $ this -> fireUpdatedEvent ( $ token -> user , $ token ) ; ret... | Renew a token |
15,103 | protected function insertToken ( ? Authenticatable $ user , string $ token , string $ email ) : Token { if ( $ user === null ) { throw new NullValueException ( "User cannot be null" ) ; } $ row = $ this -> getModel ( ) -> updateOrCreateNew ( [ 'user_id' => $ user -> getAuthIdentifier ( ) , 'email' => $ email , 'token' ... | Insert a token |
15,104 | public function fetchToken ( string $ token ) : ? Token { return $ this -> getModel ( ) -> newQuery ( ) -> where ( 'token' , $ token ) -> first ( ) ; } | Fetch token from the database |
15,105 | public function fetchTokenByEmail ( string $ email ) : ? Token { return $ this -> getModel ( ) -> newQuery ( ) -> where ( 'email' , $ email ) -> first ( ) ; } | Fetch token from the database by email |
15,106 | protected function fireCreatedEvent ( Authenticatable $ user , Token $ token ) { if ( $ this -> createdEvent === null || ! class_exists ( $ this -> createdEvent ) ) { return ; } event ( new $ this -> createdEvent ( $ user , $ token ) ) ; } | Fire created event |
15,107 | protected function fireUpdatedEvent ( Authenticatable $ user , Token $ token ) { if ( $ this -> updatedEvent === null || ! class_exists ( $ this -> updatedEvent ) ) { return ; } event ( new $ this -> updatedEvent ( $ user , $ token ) ) ; } | Fire updated event |
15,108 | protected function fireFailedEvent ( ? Authenticatable $ user , ? Token $ token , ? string $ email ) { if ( $ this -> failedEvent === null || ! class_exists ( $ this -> failedEvent ) ) { return ; } event ( new $ this -> failedEvent ( $ user , $ token , $ email ) ) ; } | Fire failed event |
15,109 | protected function fireCompletedEvent ( Authenticatable $ user ) { if ( $ this -> completedEvent === null || ! class_exists ( $ this -> completedEvent ) ) { return ; } event ( new $ this -> completedEvent ( $ user ) ) ; } | Fire completed event |
15,110 | protected function createMailSettings ( Authenticatable $ user , Token $ token ) : array { Carbon :: setLocale ( $ this -> config -> get ( 'app.locale' , 'en' ) ) ; $ expiry = $ this -> getTokenExpiry ( ) ; $ route = $ this -> generateRoute ( $ token ) ; return [ 'to' => [ [ 'email' => $ token -> email , 'name' => $ us... | Create email options |
15,111 | protected function generateRoute ( Token $ token ) : string { $ route = route ( $ this -> config -> get ( "laranixauth.{$this->configKey}.route" ) , [ ] , false ) ; return urlTo ( $ route , [ 'token' => $ token -> token , 'email' => $ token -> email ] ) ; } | Create route for mail |
15,112 | protected function tokenExpired ( Carbon $ updated ) : bool { return Carbon :: now ( ) -> diffInMinutes ( $ updated ) > $ this -> getTokenLifetime ( ) ; } | Return true if token has expired |
15,113 | public function setFileType ( int $ fileType ) { if ( self :: isFileTypeValid ( $ fileType ) ) $ this -> fileType = self :: $ fileTypes [ $ fileType ] ; } | if valid set the file type property . |
15,114 | public function setAllowedMimeTypes ( ... $ allowedMimeTypes ) { if ( is_array ( $ allowedMimeTypes [ 0 ] ) ) $ this -> allowedMimeTypes = array_merge ( $ this -> allowedMimeTypes , $ allowedMimeTypes [ 0 ] ) ; else $ this -> allowedMimeTypes = array_merge ( $ this -> allowedMimeTypes , $ allowedMimeTypes ) ; } | Set the allowed mime types . |
15,115 | final public function processFile ( ) : bool { if ( $ this -> validateFile ( ) == FALSE ) return FALSE ; $ this -> setAttributes ( ) ; if ( $ this -> validateType ( ) == FALSE ) return FALSE ; return TRUE ; } | Processes the file . |
15,116 | final protected function validateFile ( ) : bool { $ file = $ this -> file ; if ( ! $ file || empty ( $ file ) || ! is_array ( $ file ) ) : $ this -> error = "No file was uploaded." ; return FALSE ; endif ; if ( ! isset ( $ file ) || ! is_uploaded_file ( $ file [ 'tmp_name' ] ) ) : $ this -> error = "Uploaded file is M... | Validates the file |
15,117 | protected function setAttributes ( ) { $ file = $ this -> file ; $ this -> fileName = $ file [ 'name' ] ; $ this -> mimeType = $ file [ 'type' ] ; $ this -> tempPath = $ file [ 'tmp_name' ] ; $ this -> fileError = $ file [ 'error' ] ; $ this -> fileSize = $ file [ 'size' ] ; $ pathParts = pathinfo ( $ this -> fileName ... | Sets file attributes to class properties for evaluation |
15,118 | protected function validateMimeType ( ) : bool { if ( ! is_array ( $ this -> allowedMimeTypes ) || empty ( $ this -> allowedMimeTypes ) ) return TRUE ; if ( ! in_array ( $ this -> mimeType , $ this -> allowedMimeTypes ) ) : $ this -> error = "Unsupported file type." ; return FALSE ; endif ; return TRUE ; } | Validates file mime type . |
15,119 | protected function uploadFile ( ) : bool { $ this -> newFileLocation = $ this -> getUploadDir ( ) . $ this -> uploadFileDir . getConstant ( 'DS' , TRUE ) . $ this -> newFileName ; if ( file_exists ( $ this -> newFileLocation ) ) : $ this -> error = "The file {$this->newFileLocation} already exists." ; return FALSE ; en... | Uploads file to detected destination |
15,120 | protected function validateFileSize ( int $ allowedSize = 0 ) : bool { $ allowedSize = ( ! empty ( $ allowedSize ) AND $ allowedSize >= 1 ) ? $ allowedSize : $ this -> allowedFIleSize ; if ( $ this -> fileSize < $ allowedSize ) return TRUE ; $ this -> error = "File is too large try another one." ; return FALSE ; } | Validates file size . |
15,121 | final static public function sizeBytesToText ( int $ bytes = 0 ) : string { if ( $ bytes >= pow ( 1024 , 8 ) ) return number_format ( $ bytes / pow ( 1024 , 8 ) , 2 ) . ' YB' ; elseif ( $ bytes >= pow ( 1024 , 7 ) ) return number_format ( $ bytes / pow ( 1024 , 7 ) , 2 ) . ' ZB' ; elseif ( $ bytes >= pow ( 1024 , 6 ) )... | Converts size in bytes to a readable text |
15,122 | final static public function sizeTextToBytes ( int $ size = 0 , string $ unit = "" ) : int { $ units = [ 'B' => 0 , 'KB' => 1 , 'MB' => 2 , 'GB' => 3 , 'TB' => 4 , 'PB' => 5 , 'EB' => 6 , 'ZB' => 7 , 'YB' => 8 ] ; return $ size * pow ( 1024 , $ units [ strtoupper ( $ unit ) ] ) ; } | Converts size text to bytes . |
15,123 | public function getPages ( $ identifier = '' ) { if ( ! empty ( $ identifier ) ) { return $ this -> hasPage ( $ identifier ) ? $ this -> pages [ $ identifier ] : null ; } return $ this -> pages ; } | Gets the value of pages . |
15,124 | public static function API ( ) : \ Object \ Form \ API { $ class = '\\' . get_called_class ( ) ; $ model = new $ class ( [ 'skip_processing' => true , 'skip_optimistic_lock' => true , 'skip_acl' => true ] ) ; $ api = new \ Object \ Form \ API ( $ model ) ; return $ api ; } | Create API object |
15,125 | public function addElements ( array $ elements ) { foreach ( $ elements as $ name => $ element ) { if ( is_string ( $ name ) ) { $ this -> addElement ( $ element , $ name ) ; } else { $ this -> addElement ( $ element ) ; } } return $ this ; } | Add the elements |
15,126 | public function addElement ( $ element , $ name = null ) { if ( $ name === null ) { $ this -> _elements [ ] = $ element ; } else { $ this -> _elements [ $ name ] = $ element ; } return $ this ; } | Add the element |
15,127 | public function setElementsAttr ( $ attr , $ value ) { foreach ( $ this -> getElements ( ) as $ element ) { if ( $ element instanceof Tag ) { $ element -> setAttr ( $ attr , $ value ) ; } } return $ this ; } | Set the attribute for each element |
15,128 | public function removeElementsAttr ( $ attr ) { foreach ( $ this -> getElements ( ) as $ element ) { if ( $ element instanceof Tag ) { $ element -> removeAttr ( $ attr ) ; } } return $ this ; } | Remove the attribute from each element |
15,129 | public function addElementsClass ( $ class ) { foreach ( $ this -> getElements ( ) as $ element ) { if ( $ element instanceof Tag ) { $ element -> addClass ( $ class ) ; } } return $ this ; } | Add the class for each element |
15,130 | public function removeElementsClass ( $ class ) { foreach ( $ this -> getElements ( ) as $ element ) { if ( $ element instanceof Tag ) { $ element -> removeClass ( $ class ) ; } } return $ this ; } | Remove the class from each element |
15,131 | public function addElementsStyle ( $ param , $ value ) { foreach ( $ this -> getElements ( ) as $ element ) { if ( $ element instanceof Tag ) { $ element -> addStyle ( $ param , $ value ) ; } } return $ this ; } | Add the style for each element |
15,132 | public function removeElementsStyle ( $ param ) { foreach ( $ this -> getElements ( ) as $ element ) { if ( $ element instanceof Tag ) { $ element -> removeStyle ( $ param ) ; } } return $ this ; } | Remove a style from each element |
15,133 | public function setElementInsteadOf ( $ targetName , $ element , $ name = null ) { if ( ! isset ( $ this -> _elements [ $ targetName ] ) ) { return $ this ; } $ elements = [ ] ; foreach ( $ this -> _elements as $ existsName => $ existsElement ) { if ( $ targetName === $ existsName ) { if ( $ name === null ) { $ element... | Replace the existing element with the new element with the new name preserving the order |
15,134 | public function authenticate ( string $ gApiOAuthSecretFile , ? string $ gApiAccessTokenFile , array $ scopes , callable $ getAuthCode , bool $ forceAuthenticate = false ) { $ this -> client -> setApplicationName ( 'XmlSquad Tools' ) ; $ this -> client -> setScopes ( $ scopes ) ; $ this -> client -> setAccessType ( 'of... | Authenticates the client by asking user to go to the URL and paste the code given by Google |
15,135 | public function authenticateFromCommand ( InputInterface $ input , OutputInterface $ output , string $ gApiOAuthSecretFile , ? string $ gApiAccessTokenFile , array $ scopes , bool $ forceAuthenticate = false ) : bool { try { $ this -> authenticate ( $ gApiOAuthSecretFile , $ gApiAccessTokenFile , $ scopes , function ( ... | A helper for a Symfony Console command . Authenticates the client by asking user to go to the URL and paste the code given by Google . In case of a failed authentication prints a message to the console . |
15,136 | protected function loadClientSecretFromFile ( string $ filePath ) { $ this -> logger -> info ( 'Getting the Google API client secret from the `' . $ filePath . '` file' ) ; try { $ secretData = $ this -> loadCredentialJSON ( $ filePath ) ; } catch ( \ RuntimeException $ exception ) { throw new \ RuntimeException ( 'Cou... | Loads a client secret from file to Google Client |
15,137 | protected function loadAccessTokenFromFile ( string $ filePath ) { $ this -> logger -> info ( 'Getting the last Google API access token from the `' . $ filePath . '` file' ) ; try { $ tokenData = $ this -> loadCredentialJSON ( $ filePath ) ; } catch ( \ RuntimeException $ exception ) { throw new \ RuntimeException ( 'C... | Loads an access token from file to Google Client |
15,138 | protected function loadAccessTokenByAuthenticatingUser ( callable $ getAuthCode ) { try { $ authUrl = $ this -> client -> createAuthUrl ( ) ; } catch ( \ Exception $ exception ) { throw new \ RuntimeException ( 'Couldn\'t create an authentication URL: ' . rtrim ( $ exception -> getMessage ( ) , '.' ) . '. ' . 'Maybe th... | Gets an access token using the interactive authentication process and saves it to the current Google client |
15,139 | protected function saveCurrentAccessTokenToFile ( string $ tokenFilePath ) { $ this -> logger -> info ( 'Saving the access token to the `' . $ tokenFilePath . '` file' ) ; $ token = $ this -> client -> getAccessToken ( ) ; if ( $ token === null ) { throw new \ LogicException ( 'Can\'t save the token because the current... | Saves the current access token to file |
15,140 | protected function loadCredentialJSON ( string $ file ) { if ( ! @ file_exists ( $ file ) ) { throw new \ RuntimeException ( 'The `' . $ file . '` file doesn\'t exist' ) ; } if ( ! is_file ( $ file ) ) { throw new \ RuntimeException ( '`' . $ file . '` file not a file' ) ; } if ( ! is_readable ( $ file ) ) { throw new ... | Reads a JSON data from a file |
15,141 | protected function saveCredentialJson ( string $ file , $ data ) { $ content = json_encode ( $ data , JSON_UNESCAPED_UNICODE | JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_PRETTY_PRINT ) ; $ this -> filesystem -> dumpFile ( $ file , $ content ) ; } | Writes a data to a JSON file |
15,142 | public function dequeue ( array $ options = array ( ) ) { if ( $ attributes = $ this -> backend -> dequeue ( $ options ) ) { return $ this -> deserializeJob ( $ attributes ) ; } } | Get a job from the pipeline . |
15,143 | public function find ( $ id ) { if ( $ attributes = $ this -> backend -> find ( $ id ) ) { return $ this -> deserializeJob ( $ attributes ) ; } } | Find a specific job in the pipeline by its id . |
15,144 | public function boot ( ) { \ spl_autoload_register ( __NAMESPACE__ . '\Loader::class_autoload' , true ) ; \ spl_autoload_register ( __NAMESPACE__ . '\Loader::alias_autoload' , true ) ; static :: $ aliases = Config :: get ( 'services.aliases' ) ; if ( \ is_admin ( ) || Request :: is_wp_login ( ) ) { $ this -> class_list... | Includes all required Snap and theme files and register the Snap autoloader . |
15,145 | public function load_theme ( $ classmap = null ) { if ( $ classmap !== null ) { static :: $ theme_includes = \ unserialize ( $ classmap ) ; } else { $ hookables_dir = \ trim ( Config :: get ( 'theme.hookables_directory' ) , '/' ) ; $ root = \ trailingslashit ( \ get_template_directory ( ) ) ; $ hookable_locations = [ $... | Load all theme files . |
15,146 | private function init_theme_providers ( ) { foreach ( Config :: get ( 'services.theme_providers' ) as $ class_name ) { if ( \ is_subclass_of ( $ class_name , \ Snap \ Services \ Service_Provider :: class ) ) { $ provider = Container :: resolve ( $ class_name ) ; Container :: resolve_method ( $ provider , 'register' ) ;... | Initialize any theme service providers . |
15,147 | private function scan_dir ( $ folder , $ files = [ ] ) { $ folder = \ trailingslashit ( $ folder ) ; if ( isset ( $ this -> visited [ $ folder ] ) ) { return $ files ; } if ( \ is_dir ( $ folder ) ) { $ contents = \ scandir ( $ folder ) ; $ this -> visited [ $ folder ] = null ; } if ( ! empty ( $ contents ) ) { foreach... | Scans a directory for PHP files . |
15,148 | public function optionsNoSequences ( $ options = [ ] ) { $ data = $ this -> options ( $ options ) ; foreach ( $ data as $ k => $ v ) { if ( strpos ( $ k , '_sequence' ) !== false ) { unset ( $ data [ $ k ] ) ; } } return $ data ; } | Options without sequences |
15,149 | public static function getNonSequenceDomain ( string $ domain ) : string { if ( strpos ( $ domain , '_sequence' ) !== false ) { return str_replace ( '_sequence' , '' , $ domain ) ; } return $ domain ; } | Get non sequence domain |
15,150 | public function reset_components ( array $ components ) { foreach ( $ components as $ component ) { $ this -> reset_component ( $ component ) ; } return $ this -> final_instance ; } | Reset the given list of components to their default values . |
15,151 | public function reset_component ( $ component ) { $ component -> value = $ component -> default ; $ this -> final_instance [ $ component -> name ] = $ component -> default ; return $ this -> final_instance ; } | Reset the given component to its default value . |
15,152 | private function is_disabled ( $ component ) { return $ component instanceof DisableableComponentInterface && ( true === $ component -> disabled || true === $ component -> readonly ) ; } | Check if the given component is disabled . |
15,153 | private function get_defaults ( ) { $ defaults = array ( ) ; foreach ( $ this -> component_list -> get_value_components ( ) as $ component ) { $ defaults [ $ component -> name ] = $ component -> default ; } return $ defaults ; } | Get the default values for all form components as an array of name = > default_value |
15,154 | public static function buildOptions ( $ data , $ options_map , $ orderby , $ options ) { $ data = \ Object \ Data \ Common :: options ( $ data , $ options_map , $ options ) ; if ( ! empty ( $ options [ 'i18n' ] ) ) { if ( $ options [ 'i18n' ] !== 'skip_sorting' ) { array_key_sort ( $ data , [ 'name' => SORT_ASC ] , [ '... | Build options based on parameters this must be used to have consistencies in selects |
15,155 | public static function filterActiveOptions ( $ data , $ options_active , $ existing_values = [ ] , $ skip_values = [ ] ) { if ( ! empty ( $ existing_values ) && ! is_array ( $ existing_values ) ) { $ existing_values = [ $ existing_values ] ; } foreach ( $ data as $ k => $ v ) { if ( ! empty ( $ existing_values ) && in_... | Filter active options |
15,156 | public function doUpload ( ) { $ result = false ; if ( is_array ( $ this -> fileArray [ 'tmp_name' ] ) ) { error_log ( 'file array is in multi upload format, use doMultiUpload()' ) ; return false ; } $ errno = $ this -> fileArray [ 'error' ] ; if ( $ errno == UPLOAD_ERR_OK ) { if ( ! File :: createFolder ( $ this -> up... | the uploaded file should have been uploaded to a temp dir move the file to the target directory |
15,157 | private function getErrMsg ( $ errno ) { if ( $ errno == UPLOAD_ERR_INI_SIZE ) { return 'uploaded file larger than max size specified in php.ini' ; } else if ( $ errno == UPLOAD_ERR_FORM_SIZE ) { return 'uploaded file larger than max size specified in form field' ; } else if ( $ errno == UPLOAD_ERR_PARTIAL ) { return '... | get a description for a given error code these are predefined php errors when uploading a file from a post form |
15,158 | private function setMimeType ( $ file , $ index = 0 ) { if ( count ( $ this -> uploaded ) <= $ index ) { error_log ( 'index out of bounds' ) ; return false ; } if ( function_exists ( 'finfo_open' ) ) { $ finfo = finfo_open ( FILEINFO_MIME_TYPE ) ; if ( ! $ finfo ) { error_log ( 'finfo can\'t read mime db' ) ; } else { ... | Determine the mime type of the uploaded file . The browser provides a mime type when the file is uploaded but it is not a reliable source . |
15,159 | public static function systemModuleExists ( string $ module_code ) : bool { $ result = \ Object \ Controller :: getSystemModuleByModuleCode ( $ module_code ) ; return ! empty ( $ result ) ; } | System module exists |
15,160 | public static function systemFeatureExists ( string $ feature_code , $ module_id = null ) : bool { if ( ! isset ( $ module_id ) ) { $ module_id = \ Application :: $ controller -> module_id ; } $ temp = explode ( '::' , $ feature_code ) ; $ result = \ Object \ Controller :: getSystemModuleByModuleCode ( $ temp [ 0 ] ) ;... | System feature exists |
15,161 | public static function systemFeaturesExist ( array $ feature_codes , $ module_id = null ) : bool { $ not_found = false ; foreach ( $ feature_codes as $ v ) { if ( ! self :: systemFeatureExists ( $ v , $ module_id ) ) { $ not_found = true ; break ; } } return ! $ not_found ; } | System features exist |
15,162 | private static function userFeatureExistsOne ( array $ features , string $ feature_code , $ module_id = null ) : int { $ result = $ features [ $ feature_code ] [ $ module_id ] ?? null ; if ( $ result === 0 ) { return 1 ; } else if ( $ result === 1 ) { return 2 ; } return 0 ; } | User feature exists one |
15,163 | private static function userFeatureExistsRole ( string $ role , string $ feature_code , $ module_id = null ) : int { if ( ! empty ( \ Object \ Controller :: $ cached_roles [ $ role ] [ 'features' ] ) ) { $ result = self :: userFeatureExistsOne ( \ Object \ Controller :: $ cached_roles [ $ role ] [ 'features' ] , $ feat... | User feature exists one role |
15,164 | public static function fileExistsInPath ( string $ filename ) { $ paths = explode ( ';' , str_replace ( ':' , ';' , get_include_path ( ) ) ) ; foreach ( $ paths as $ v ) { if ( file_exists ( $ v . DIRECTORY_SEPARATOR . $ filename ) ) { return $ v . DIRECTORY_SEPARATOR . $ filename ; } } return false ; } | File exist in path |
15,165 | private static function userFlagExistsOne ( array $ flags , int $ flag_id , int $ action_id , $ module_id = null ) : int { $ result = $ flags [ $ flag_id ] [ $ action_id ] [ $ module_id ] ?? null ; if ( $ result === 0 ) { return 1 ; } else if ( $ result === 1 ) { return 2 ; } return 0 ; } | User flag exists one |
15,166 | private static function userFlagExistsRole ( string $ role , int $ flag_id , int $ action_id , $ module_id = null ) : int { if ( ! empty ( \ Object \ Controller :: $ cached_roles [ $ role ] [ 'flags' ] ) ) { $ result = self :: userFlagExistsOne ( \ Object \ Controller :: $ cached_roles [ $ role ] [ 'flags' ] , $ flag_i... | User flag exists one role |
15,167 | static public function fromFile ( string $ filename ) { $ yaml = filter_var ( $ filename , FILTER_VALIDATE_URL ) ? yaml_parse_url ( $ filename ) : yaml_parse_file ( $ filename ) ; YamlException :: importFromFile ( $ yaml ) ; return $ yaml ; } | Read YAML from file or by URL |
15,168 | static public function fromData ( string $ data ) { $ yaml = yaml_parse ( $ data ) ; YamlException :: importFromData ( $ yaml ) ; return $ yaml ; } | Parce plain text with YAML inside |
15,169 | public static function validate ( $ argument , $ argumentName = null ) { if ( $ argument === null ) { throw new \ InvalidArgumentException ( "$argumentName cannot be null" ) ; } elseif ( gettype ( $ argument ) == 'string' && trim ( $ argument ) == '' ) { throw new \ InvalidArgumentException ( "$argumentName string cann... | Helper method for validating an argument that will be used by this API in any requests . |
15,170 | public function GetGroupValue ( $ group , $ option ) { if ( isset ( $ this -> preferences [ $ group ] ) ) { if ( isset ( $ this -> preferences [ $ group ] [ $ option ] ) ) { return $ this -> preferences [ $ group ] [ $ option ] ; } } return false ; } | Get the value of an option on a specific configuration group . |
15,171 | public function SetGroupValue ( $ group , $ option , $ value ) { $ this -> preferences [ $ group ] [ $ option ] = $ value ; $ this -> Write ( ) ; } | Edits or creates a new group and option and writes it to the configuration file immediately . |
15,172 | public function compose ( string $ format , array $ compose = [ ] , string $ method = 'compose' ) { if ( ! \ in_array ( $ format , $ this -> formats ) ) { return $ this -> composeError ( null , [ ] , 406 ) ; } elseif ( ! \ method_exists ( $ this , $ method . \ ucwords ( $ format ) ) ) { throw new RuntimeException ( 'Ca... | Compose requested format . |
15,173 | public function composeError ( $ view , array $ data = [ ] , int $ status = 404 ) : Response { $ engine = $ this -> view ; $ file = "errors.{$status}" ; $ view = $ engine -> exists ( $ file ) ? $ engine -> make ( $ file , $ data ) : "{$status} Error" ; return new Response ( $ view , $ status ) ; } | Compose an error template . |
15,174 | protected function prepareDataValue ( array $ config , array $ data ) : array { $ only = $ config [ 'only' ] ?? null ; $ except = $ config [ 'except' ] ?? null ; if ( ! \ is_null ( $ only ) ) { return Arr :: only ( $ data , $ only ) ; } elseif ( ! \ is_null ( $ except ) ) { return Arr :: except ( $ data , $ except ) ; ... | Prepare data to be seen to template . |
15,175 | public function findAll ( $ appUserId ) { $ url = sprintf ( 'users/%s/subaccounts/' , $ appUserId ) ; return $ this -> getAll ( $ url , $ this -> entityClassName ) ; } | Find all user sub accounts |
15,176 | public function create ( $ appUserId , SubAccount $ subAccount ) { $ url = sprintf ( 'users/%s/subaccounts/' , $ appUserId ) ; return $ this -> createObject ( $ url , $ subAccount ) ; } | Create new user sub account |
15,177 | public function update ( $ appUserId , SubAccount $ subAccount ) { $ url = sprintf ( 'users/%s/subaccounts/%s' , $ appUserId , $ subAccount -> getAppAccountId ( ) ) ; return $ this -> updateObject ( $ url , $ subAccount ) ; } | Update existing user sub account |
15,178 | public function delete ( $ appUserId , SubAccount $ subAccount ) { $ url = sprintf ( 'users/%s/subaccounts/%s' , $ appUserId , $ subAccount -> getAppAccountId ( ) ) ; return $ this -> deleteObject ( $ url ) ; } | Delete user sub account |
15,179 | public function doAction ( $ methodName , $ payload , $ httpHeaders ) { $ this -> setHttpHeader ( $ httpHeaders ) ; self :: $ soapClient -> __setSoapHeaders ( $ this -> getAuthHeader ( ) ) ; $ response = self :: $ soapClient -> $ methodName ( $ payload ) ; return json_encode ( $ response ) ; } | Execute SOAP method on the client |
15,180 | private function getAuthHeader ( ) { $ credential = $ this -> apiContext -> getCredential ( ) ; $ header = '<wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">' ; $ header .= '<wsse:UsernameToken wsu:Id="UsernameToken-9" xmlns:wsu="h... | SOAP Authentication header for SOAP client |
15,181 | protected function setup ( ) { $ this -> rs = new \ HaveAPI \ Client \ Resource ( $ this -> client , 'token' , $ this -> description -> resources -> token , array ( ) ) ; $ this -> via = isSet ( $ this -> opts [ 'via' ] ) ? $ this -> opts [ 'via' ] : self :: HTTP_HEADER ; if ( isSet ( $ this -> opts [ 'token' ] ) ) { $... | Request a new token if it isn t in the options . |
15,182 | public function authenticate ( $ request ) { if ( ! $ this -> configured ) return ; $ this -> checkValidity ( ) ; if ( $ this -> via == self :: HTTP_HEADER ) $ request -> addHeader ( $ this -> description -> http_header , $ this -> token ) ; } | Add token header if configured . Checks token validity . |
15,183 | public function queryParameters ( ) { if ( ! $ this -> configured || $ this -> via != self :: QUERY_PARAMETER ) return array ( ) ; return array ( $ this -> description -> query_parameter => $ this -> token ) ; } | Returns token query parameter if configured . |
15,184 | protected function requestToken ( ) { $ ret = $ this -> rs -> request ( array ( 'login' => $ this -> opts [ 'username' ] , 'password' => $ this -> opts [ 'password' ] , 'lifetime' => isSet ( $ this -> opts [ 'lifetime' ] ) ? $ this -> opts [ 'lifetime' ] : 'renewable_auto' , 'interval' => isSet ( $ this -> opts [ 'inte... | Request a new token from the API . |
15,185 | protected function checkValidity ( ) { if ( $ this -> validTo && $ this -> validTo < time ( ) && isSet ( $ this -> opts [ 'username' ] ) && isSet ( $ this -> opts [ 'password' ] ) ) $ this -> requestToken ( ) ; } | Get a new token if the current one expired . |
15,186 | public function errorAction ( ) { $ res = $ this -> getResponse ( ) ; $ res -> setStatusCode ( Response :: HTTP_INTERNAL_SERVER_ERROR ) ; $ res -> setContent ( self :: ERROR_CONTENT ) ; return ( $ res ) ; } | errorAction This action is called if an exception is generated on a production system and no error template was found . |
15,187 | public function notFoundAction ( ) { $ res = $ this -> getResponse ( ) ; $ res -> setStatusCode ( Response :: HTTP_NOT_FOUND ) ; $ res -> setContent ( self :: NOTFOUND_CONTENT ) ; return ( $ res ) ; } | notFoundAction This action is called if the router generated a 404 and couldn t find a template to render for it . |
15,188 | public static function addValue ( array & $ arr , $ key , $ value ) { if ( isset ( $ arr [ $ key ] ) ) { if ( ! is_array ( $ arr [ $ key ] ) ) { $ arr [ $ key ] = [ $ arr [ $ key ] ] ; } $ arr [ $ key ] [ ] = $ value ; } else { $ arr [ $ key ] = $ value ; } } | Add a value to an array |
15,189 | public static function defaults ( array $ arr = null , array $ defaults ) : array { if ( $ arr === null ) { return $ defaults ; } foreach ( $ defaults as $ key => $ value ) { if ( ! isset ( $ arr [ $ key ] ) ) { $ arr [ $ key ] = $ value ; } } return $ arr ; } | Ensure that all keys in one array exist in another |
15,190 | public static function implode ( $ delim , array $ arr , $ beforeLast = null ) : string { if ( count ( $ arr ) > 1 && $ beforeLast !== null ) { $ arr [ ] = $ beforeLast . array_pop ( $ arr ) ; } return implode ( $ delim , $ arr ) ; } | Implode values with a defferent delimeter before the last element |
15,191 | public static function without ( array $ arr , string ... $ keys ) : array { foreach ( $ keys as $ key ) { if ( isset ( $ arr [ $ key ] ) ) { unset ( $ arr [ $ key ] ) ; } } return $ arr ; } | Selectively remove values from an array based on their keys |
15,192 | public static function only ( array $ arr , string ... $ keys ) : array { $ ret = [ ] ; foreach ( $ keys as $ key ) { if ( isset ( $ arr [ $ key ] ) ) { $ ret [ $ key ] = $ arr [ $ key ] ; } } return $ ret ; } | Selectively keep values in an array based on their keys |
15,193 | public static function popValues ( array $ arr , $ match = false , bool $ strict = false ) : array { $ func = Compare :: getMethod ( $ strict ) ; $ len = count ( $ arr ) ; while ( $ len > 0 && call_user_func ( $ func , end ( $ arr ) , $ match ) ) { array_pop ( $ arr ) ; $ len -- ; } return $ arr ; } | Remove values from the end of an array using comparison |
15,194 | public static function shiftValues ( array $ arr , $ match = false , bool $ strict = false ) : array { $ func = Compare :: getMethod ( $ strict ) ; $ len = count ( $ arr ) ; while ( $ len > 0 && call_user_func ( $ func , reset ( $ arr ) , $ match ) ) { array_shift ( $ arr ) ; $ len -- ; } return $ arr ; } | Remove values from the beginning of an array using comparison |
15,195 | public static function toAttributeString ( array $ arr = null ) : string { $ ret = "" ; if ( $ arr !== null ) { foreach ( $ arr as $ k => $ v ) { $ ret .= " $k=\"$v\"" ; } } return $ ret ; } | Create an attribute string from an associative array |
15,196 | public static function export ( array $ arr ) : string { $ str = var_export ( $ arr , true ) ; $ str = str_replace ( "array (" , "array(" , $ str ) ; $ str = preg_replace ( "/=>(\s+)array\(/s" , "=> array(" , $ str ) ; $ str = preg_replace ( "/array\(\s+\)/" , "array()" , $ str ) ; return $ str ; } | Export an array as a string with better than default formatting |
15,197 | public function addConfigPath ( $ path ) { if ( ! is_dir ( $ path ) ) { throw new LoaderException ( sprintf ( "The config path '%s' is not a valid directory" , $ path ) ) ; } if ( $ path [ strlen ( $ path ) - 1 ] != "/" ) { $ path .= "/" ; } $ this -> configPaths [ ] = $ path ; } | Add a directory to search in when loading configuration files |
15,198 | public function removeLoaderByFile ( $ file ) { foreach ( $ this -> loaders as $ i => $ loader ) { if ( $ loader -> supports ( $ file ) ) { unset ( $ this -> loaders [ $ i ] ) ; } } } | Remove the loader that supports the specified file |
15,199 | public function addConfigFile ( $ file , $ alias = null ) { $ filePath = $ this -> findConfigFile ( $ file ) ; if ( ! is_string ( $ alias ) ) { $ this -> configFiles [ ] = $ filePath ; } else { $ this -> configFiles [ $ alias ] = $ filePath ; } } | Queue a config file to be processed |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.