idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
54,100
|
public function insertEscaped ( ... $ field_values ) { if ( $ this -> is_done ) { throw new RuntimeException ( 'This batch insert is already done' ) ; } if ( count ( $ field_values ) == $ this -> fields_num ) { $ this -> rows [ ] = '(' . implode ( ', ' , $ field_values ) . ')' ; $ this -> checkAndInsert ( ) ; } else { throw new BadMethodCallException ( 'Number of arguments does not match number of fields' ) ; } }
|
Insert array of already escaped values .
|
54,101
|
public function flush ( ) { if ( $ this -> is_done ) { throw new RuntimeException ( 'This batch insert is already done' ) ; } $ count_rows = count ( $ this -> rows ) ; if ( $ count_rows > 0 ) { $ this -> connection -> execute ( $ this -> sql_foundation . implode ( ', ' , $ this -> rows ) ) ; $ this -> rows = [ ] ; $ this -> total += $ count_rows ; } }
|
Insert rows that are already loaded .
|
54,102
|
public function done ( ) { if ( $ this -> is_done ) { throw new RuntimeException ( 'This batch insert is already done' ) ; } $ this -> flush ( ) ; $ this -> is_done = true ; return $ this -> total ; }
|
Finish with the batch .
|
54,103
|
public function reset ( string $ path ) { if ( ! empty ( $ this -> cache ) ) { $ this -> cache -> resetPath ( $ path ) ; } $ engine = $ this -> findEngine ( $ path ) ; $ generator = new ContextGenerator ( $ this -> context ) ; foreach ( $ generator -> generate ( ) as $ context ) { $ engine -> reset ( $ path , $ context ) ; } }
|
Reset view cache for a given path . Identical to compile method by effect but faster .
|
54,104
|
public function get ( string $ path ) : ViewInterface { if ( ! empty ( $ this -> cache ) && $ this -> cache -> has ( $ this -> context , $ path ) ) { return $ this -> cache -> get ( $ this -> context , $ path ) ; } $ view = $ this -> findEngine ( $ path ) -> get ( $ path , $ this -> context ) ; if ( ! empty ( $ this -> cache ) ) { $ this -> cache -> set ( $ this -> context , $ path , $ view ) ; } return $ view ; }
|
Get view from one of the associated engines .
|
54,105
|
protected function _createFile ( ) { do { $ this -> _filename = $ this -> getPath ( ) . mt_rand ( ) . '.html' ; } while ( File :: exists ( $ this -> _filename ) ) ; File :: put ( $ this -> _filename , $ this -> getHtml ( ) ) ; chmod ( $ this -> _filename , 0777 ) ; return $ this -> _filename ; }
|
creates file to which will be writen html content
|
54,106
|
public function setPath ( $ path ) { if ( realpath ( $ path ) === false ) { throw new Exception ( "Path must be absolute." ) ; } $ this -> _path = realpath ( $ path ) . DS ; return $ this ; }
|
Absolute path where to store files
|
54,107
|
protected function _getCommand ( ) { $ command = $ this -> _bin ; $ command .= ( $ this -> getCopies ( ) > 1 ) ? " --copies " . $ this -> getCopies ( ) : "" ; $ command .= " --orientation " . $ this -> getOrientation ( ) ; $ command .= " --page-size " . $ this -> getPageSize ( ) ; foreach ( $ this -> getMargins ( ) as $ position => $ margin ) { $ command .= ( false === is_null ( $ margin ) ) ? sprintf ( ' --margin-%s %s' , $ position , $ margin ) : '' ; } $ command .= ( $ this -> getWindowStatus ( ) ) ? " --window-status " . $ this -> getWindowStatus ( ) . "" : "" ; $ command .= ( $ this -> getTOC ( ) ) ? " --toc" : "" ; $ command .= ( $ this -> getGrayscale ( ) ) ? " --grayscale" : "" ; $ command .= ( mb_strlen ( $ this -> getPassword ( ) ) > 0 ) ? " --password " . $ this -> getPassword ( ) . "" : "" ; $ command .= ( mb_strlen ( $ this -> getUsername ( ) ) > 0 ) ? " --username " . $ this -> getUsername ( ) . "" : "" ; $ command .= ( mb_strlen ( $ this -> getFooterHtml ( ) ) > 0 ) ? " --margin-bottom 20 --footer-html \"" . $ this -> getFooterHtml ( ) . "\"" : "" ; $ command .= ( $ this -> getTitle ( ) ) ? ' --title "' . $ this -> getTitle ( ) . '"' : '' ; $ command .= ' "%input%"' ; $ command .= " -" ; if ( $ this -> getRunInVirtualX ( ) ) { $ command = 'xvfb-run ' . $ command ; } return $ command ; }
|
returns command to execute
|
54,108
|
private function initHelper ( ) { if ( ! $ this -> isConfigFileSet ( ) ) { throw new Exception ( "The main config file wasn't defined." ) ; } if ( ! $ this -> isAppRootSet ( ) ) { throw new Exception ( "The application root wasn't defined." ) ; } AppHelper :: getInstance ( ) -> setAppRoot ( $ this -> getAppRoot ( ) ) -> setConfigFile ( $ this -> getConfigFile ( ) ) -> run ( ) ; }
|
It inits the application helper .
|
54,109
|
public function getUsers ( ) { $ tmp = array ( ) ; foreach ( $ this -> htpwd as $ key => $ line ) { if ( empty ( $ line ) || ! strpos ( $ line , ':' ) ) continue ; array_push ( $ tmp , explode ( ":" , $ line ) [ 0 ] ) ; } return $ tmp ; }
|
Gets all users .
|
54,110
|
public function addUser ( $ user , $ pass ) { if ( ! empty ( $ user ) && ! $ this -> userExists ( $ user ) && ! empty ( $ pass ) ) { array_push ( $ this -> htpwd , $ user . ':' . crypt ( $ pass , substr ( str_replace ( '+' , '.' , base64_encode ( pack ( 'N4' , mt_rand ( ) , mt_rand ( ) , mt_rand ( ) , mt_rand ( ) ) ) ) , 0 , 22 ) ) ) ; $ this -> _save ( ) ; return true ; } else { return false ; } }
|
Adds a user .
|
54,111
|
private function _save ( ) { unlink ( $ this -> path ) ; file_put_contents ( $ this -> path , join ( '\n' , $ this -> htpwd ) ) ; }
|
Saves the . htpasswd file contents .
|
54,112
|
protected function _loadLanguageStrings ( $ throw_errors = true , $ force_rebuild = false , $ force_rebuild_on_update = false ) { $ _fn = $ this -> getLoader ( ) -> buildLanguageFileName ( $ this -> lang ) ; $ _f = $ this -> getLoader ( ) -> buildLanguageFilePath ( $ this -> lang ) ; if ( isset ( $ this -> language_strings_cache [ $ _f ] ) && isset ( $ this -> language_strings_cache [ $ this -> lang ] ) ) { $ this -> language_strings = $ this -> language_strings_cache [ $ this -> lang ] ; return $ this ; } $ db_f = $ this -> getLoader ( ) -> buildLanguageDBFilePath ( ) ; if ( @ file_exists ( $ _f ) ) { if ( $ force_rebuild_on_update && filemtime ( $ db_f ) > filemtime ( $ _f ) ) { return $ this -> _rebuildLanguageStringsFiles ( ) -> _loadLanguageStrings ( ) ; } else { $ _v = $ this -> getLoader ( ) -> buildLanguageVarname ( $ this -> lang ) ; include $ _f ; if ( isset ( $ $ _v ) ) { if ( ! isset ( $ this -> language_strings_cache [ $ this -> lang ] ) ) { $ this -> language_strings_cache [ $ this -> lang ] = array ( ) ; } $ this -> language_strings_cache [ $ this -> lang ] = array_merge ( $ this -> language_strings_cache [ $ this -> lang ] , $ $ _v ) ; $ this -> language_strings_cache [ $ _f ] = array ( 'language' => $ this -> lang , 'strings' => $ $ _v ) ; return $ this -> _loadLanguageStrings ( ) ; } else { throw new I18nException ( sprintf ( 'Language strings seems to be malformed in file "%s" (must be a classic array like "string_index"=>"string in the language")!' , $ _fn ) ) ; } } } elseif ( $ force_rebuild ) { return $ this -> _rebuildLanguageStringsFiles ( ) -> _loadLanguageStrings ( ) ; } elseif ( $ throw_errors ) { throw new I18nInvalidArgumentException ( sprintf ( 'Language strings file for language code "%s" not found (searched in "%s")!' , $ this -> lang , $ _f ) ) ; } return $ this ; }
|
Load the current language strings
|
54,113
|
protected function _rebuildLanguageStringsFiles ( ) { $ db_filepath = $ this -> getLoader ( ) -> buildLanguageDBFilePath ( ) ; $ generator = new Generator ( $ db_filepath ) ; $ generator -> generate ( ) ; return $ this ; }
|
Rebuild the language strings databases with I18n \ Generator
|
54,114
|
public function loadFile ( $ file_name , $ dir_name = null ) { try { $ loader = $ this -> getLoader ( ) ; $ file_path = $ loader -> findLanguageDBFile ( ! empty ( $ file_name ) ? basename ( $ file_name ) : $ file_name , ! empty ( $ dir_name ) ? $ dir_name : ( ! empty ( $ file_name ) ? dirname ( $ file_name ) : $ dir_name ) ) ; if ( $ file_path && file_exists ( $ file_path ) ) { $ loader -> setOption ( 'language_strings_db_directory' , dirname ( $ file_path ) ) -> setOption ( 'language_strings_db_filename' , basename ( $ file_path ) ) ; $ this -> _loadLanguageStrings ( true , true , true ) ; } else { throw new I18nInvalidArgumentException ( sprintf ( 'Language file "%s" not found!' , $ file_name ) ) ; } } catch ( I18nException $ e ) { throw $ e ; } }
|
Load a new language file
|
54,115
|
public function setLanguage ( $ lang , $ throw_errors = true , $ force_rebuild = false ) { if ( $ this -> isAvailableLanguage ( $ lang ) ) { $ this -> lang = $ lang ; $ this -> setLocale ( $ this -> getAvailableLocale ( $ lang ) ) ; $ this -> _loadLanguageStrings ( $ throw_errors , $ force_rebuild ) ; } else { throw new I18nInvalidArgumentException ( sprintf ( 'Language "%s" is not available in the application (available languages are %s)!' , $ lang , join ( ', ' , $ this -> getLoader ( ) -> getOption ( 'available_languages' ) ) ) ) ; } return $ this ; }
|
Loads a new language
|
54,116
|
public function setDefaultFromHttp ( ) { $ http_locale = $ this -> getHttpHeaderLocale ( ) ; if ( ! empty ( $ http_locale ) && $ this -> isAvailableLanguage ( $ http_locale ) ) { $ this -> setLanguage ( $ http_locale ) ; } return $ this ; }
|
Try to get the browser default locale and use it
|
54,117
|
public function isAvailableLanguage ( $ lang ) { return array_key_exists ( $ lang , $ this -> getLoader ( ) -> getOption ( 'available_languages' ) ) || in_array ( $ lang , $ this -> getLoader ( ) -> getOption ( 'available_languages' ) ) ; }
|
Check if a language code is available in the Loader
|
54,118
|
public function getAvailableLocale ( $ lang ) { $ langs = $ this -> getLoader ( ) -> getOption ( 'available_languages' ) ; if ( array_key_exists ( $ lang , $ langs ) ) { return $ langs [ $ lang ] ; } elseif ( in_array ( $ lang , $ langs ) ) { return $ langs [ array_search ( $ lang , $ langs ) ] ; } return null ; }
|
Get the full locale info for a language code
|
54,119
|
public function getLocalizedString ( $ index ) { return isset ( $ this -> language_strings [ $ index ] ) ? $ this -> language_strings [ $ index ] : $ index ; }
|
Get the translation of an index
|
54,120
|
public function parseString ( $ str , array $ arguments = null ) { if ( empty ( $ arguments ) ) { return $ str ; } $ arg_mask = $ this -> getLoader ( ) -> getOption ( 'arg_wrapper_mask' ) ; foreach ( $ arguments as $ name => $ value ) { if ( is_string ( $ name ) ) { $ str = strtr ( $ str , array ( sprintf ( $ arg_mask , $ name ) => $ value ) ) ; } else { $ str = sprintf ( $ str , self :: translate ( $ value ) ) ; } } return $ str ; }
|
Parse a translated string making some parameters replacements
|
54,121
|
public function parseStringMetadata ( $ str ) { $ info = array ( ) ; if ( 0 !== preg_match ( '~^\[([^\]]+)\]~i' , $ str , $ matches ) ) { $ str = str_replace ( $ matches [ 0 ] , '' , $ str ) ; $ types = $ matches [ 1 ] ; $ types_items = explode ( ';' , $ types ) ; foreach ( $ types_items as $ item ) { $ parts = explode ( ':' , $ item ) ; if ( count ( $ parts ) > 1 ) { $ info [ $ parts [ 0 ] ] = $ parts [ 1 ] ; } else { $ info [ ] = $ parts [ 0 ] ; } } } return array ( $ str , $ info ) ; }
|
Get the meta - data of a language string
|
54,122
|
protected function _showUntranslated ( $ str = '' , array $ args = null ) { $ arguments = '' ; if ( ! empty ( $ args ) ) { foreach ( $ args as $ var => $ val ) { $ arguments .= '"' . $ var . '" => ' . str_replace ( array ( "\n" , "\t" ) , '' , var_export ( $ val , 1 ) ) . ', ' ; } } return sprintf ( $ this -> getLoader ( ) -> getOption ( 'show_untranslated_wrapper' , '%s' ) , $ str , $ arguments ) ; }
|
Special function to show a string when its translation doesn t exist
|
54,123
|
public function getCurrency ( $ lang = null ) { if ( ! is_null ( $ lang ) ) { $ original_lang = $ this -> getLanguage ( ) ; $ this -> setLanguage ( $ lang ) ; } $ formatter = new NumberFormatter ( $ this -> getLocale ( ) , NumberFormatter :: CURRENCY ) ; $ currency = $ formatter -> getTextAttribute ( NumberFormatter :: CURRENCY_CODE ) ; if ( ! empty ( $ original_lang ) ) { $ this -> setLanguage ( $ original_lang ) ; } return $ currency ; }
|
Get the currency of the current locale
|
54,124
|
public function getLanguageCode ( $ lang = null ) { $ parts = $ this -> _callInternalLocale ( 'parseLocale' , null , $ lang , false ) ; return isset ( $ parts [ 'language' ] ) ? $ parts [ 'language' ] : null ; }
|
Get the language code of the current locale
|
54,125
|
public function getKeyword ( $ keyword , $ lang = null ) { $ parts = $ this -> _callInternalLocale ( 'getKeywords' , null , $ lang , false ) ; return isset ( $ parts [ $ keyword ] ) ? $ parts [ $ keyword ] : null ; }
|
Get one keyword value of the current locale
|
54,126
|
protected function _callInternalLocale ( $ fct_name , $ for_locale = null , $ lang = null , $ do_array = true ) { if ( ! is_null ( $ lang ) ) { $ original_lang = $ this -> getLanguage ( ) ; $ this -> setLanguage ( $ lang ) ; } $ locale = ! is_null ( $ for_locale ) ? $ this -> getAvailableLocale ( $ for_locale ) : $ this -> getLocale ( ) ; $ arguments = $ do_array ? array ( $ locale , $ this -> getLocale ( ) ) : array ( $ locale ) ; $ str = call_user_func_array ( array ( 'Locale' , $ fct_name ) , $ arguments ) ; if ( ! empty ( $ original_lang ) ) { $ this -> setLanguage ( $ original_lang ) ; } return $ str ; }
|
Internally factorize the Locale methods
|
54,127
|
public static function getLocalizedPriceString ( $ number , $ lang = null ) { $ _this = self :: getInstance ( ) ; if ( ! is_null ( $ lang ) ) { $ original_lang = $ _this -> getLanguage ( ) ; $ _this -> setLanguage ( $ lang ) ; } $ formatter = new NumberFormatter ( $ _this -> getLocale ( ) , NumberFormatter :: CURRENCY ) ; $ str = $ formatter -> format ( $ number ) ; if ( ! empty ( $ original_lang ) ) { $ _this -> setLanguage ( $ original_lang ) ; } return $ str ; }
|
Get a localized price value
|
54,128
|
public static function getLocalizedDateString ( DateTime $ date , $ mask = null , $ charset = 'UTF-8' , $ lang = null ) { $ _this = self :: getInstance ( ) ; if ( ! is_null ( $ lang ) ) { $ original_lang = $ _this -> getLanguage ( ) ; $ _this -> setLanguage ( $ lang ) ; } if ( is_null ( $ mask ) ) { $ mask = $ _this -> getLocalizedString ( 'datetime_mask_icu' ) ; } if ( ! empty ( $ mask ) ) { $ fmt = new IntlDateFormatter ( $ _this -> getLocale ( ) , IntlDateFormatter :: FULL , IntlDateFormatter :: FULL , $ _this -> getTimezone ( ) , IntlDateFormatter :: GREGORIAN , $ mask ) ; } else { $ fmt = new IntlDateFormatter ( $ _this -> getLocale ( ) , IntlDateFormatter :: FULL , IntlDateFormatter :: FULL , $ _this -> getTimezone ( ) , IntlDateFormatter :: GREGORIAN ) ; } $ str = $ fmt -> format ( $ date ) ; if ( ! empty ( $ original_lang ) ) { $ _this -> setLanguage ( $ original_lang ) ; } return $ str ; }
|
Get a localized date value
|
54,129
|
public static function translate ( $ index , array $ args = null , $ lang = null ) { $ _this = self :: getInstance ( ) ; if ( ! is_null ( $ lang ) ) { $ original_lang = $ _this -> getLanguage ( ) ; $ _this -> setLanguage ( $ lang ) ; } if ( $ _this -> hasLocalizedString ( $ index ) ) { $ str = $ _this -> getLocalizedString ( $ index ) ; list ( $ str_tmp , $ meta ) = $ _this -> parseStringMetadata ( $ str ) ; if ( ! empty ( $ meta ) ) { $ str = $ str_tmp ; } $ str = $ _this -> parseString ( $ str , $ args ) ; } elseif ( $ _this -> loader -> getOption ( 'show_untranslated' , false ) ) { $ str = $ _this -> _showUntranslated ( $ index , $ args ) ; } else { $ str = $ index ; } if ( ! empty ( $ original_lang ) ) { $ _this -> setLanguage ( $ original_lang ) ; } return $ str ; }
|
Process a translation with arguments
|
54,130
|
public static function pluralize ( array $ indexes = array ( ) , $ number = 0 , array $ args = null , $ lang = null ) { $ _this = self :: getInstance ( ) ; $ args [ 'nb' ] = $ number ; if ( isset ( $ indexes [ $ number ] ) ) { return self :: translate ( $ indexes [ $ number ] , $ args , $ lang ) ; } $ str = ( $ number <= 1 ) ? array_shift ( $ indexes ) : end ( $ indexes ) ; return self :: translate ( $ str , $ args , $ lang ) ; }
|
Process a translation with arguments depending on a counter
|
54,131
|
public function is ( string $ key ) : bool { return isset ( $ this -> meta [ $ key ] ) && ( bool ) $ this -> meta [ $ key ] ; }
|
Check if meta for given key exists and is not false
|
54,132
|
public function check ( $ user , $ permissions , $ resourceName = null , $ resourceId = null ) { return $ this -> manager -> caller ( $ user ) -> can ( $ permissions , $ resourceName , ( int ) $ resourceId ) ; }
|
Check the given user has the given permission .
|
54,133
|
public function can ( $ permissions , $ resourceName = null , $ resourceId = null ) { return $ this -> caller ( ) -> can ( $ permissions , $ resourceName , $ resourceId ) ; }
|
Perform check on the subject .
|
54,134
|
public function all ( ) { if ( $ this -> subject == 'user' ) { return $ this -> getUserPermissions ( $ this -> user ) ; } elseif ( $ this -> subject == 'role' ) { return $ this -> getRolePermissions ( $ this -> role ) ; } }
|
Return all specific permissions for the given subject .
|
54,135
|
public function grant ( $ permissions , $ resourceName = null , $ resourceId = null ) { return $ this -> lock ( ) -> allow ( $ permissions , $ resourceName , $ resourceId ) ; }
|
Grant the given permissions to the given subject .
|
54,136
|
public function revoke ( $ permissions , $ resourceName = null , $ resourceId = null ) { return $ this -> lock ( ) -> deny ( $ permissions , $ resourceName , $ resourceId ) ; }
|
Revoke the given permissions from the given subject .
|
54,137
|
protected function caller ( ) { if ( $ this -> subject == 'user' ) { return $ this -> manager -> caller ( $ this -> user ) ; } elseif ( $ this -> subject == 'role' ) { return $ this -> manager -> role ( $ this -> role ) ; } return null ; }
|
Return the caller to work on .
|
54,138
|
protected function lock ( ) { if ( $ this -> subject == 'user' ) { return $ this -> manager -> caller ( $ this -> user ) ; } elseif ( $ this -> subject == 'role' ) { return $ this -> manager -> role ( $ this -> role ) ; } else { throw new \ Exception ( "Caller not allowed: $this->subject" ) ; } }
|
Return the lock instance to work on .
|
54,139
|
protected function getUserPermissions ( $ user ) { $ permissions = $ this -> manager -> getDriver ( ) -> getCallerPermissions ( $ user ) ; $ collection = new Collection ( ) ; foreach ( $ permissions as $ permission ) { if ( $ permission instanceof Restriction ) { continue ; } $ collection -> allow ( $ permission -> getAction ( ) , $ permission -> getResourceType ( ) , $ permission -> getResourceId ( ) ) ; } return $ collection ; }
|
Return a collection of user based permissions .
|
54,140
|
protected function getRolePermissions ( $ roleName ) { $ role = new SimpleRole ( $ roleName ) ; $ permissions = $ this -> manager -> getDriver ( ) -> getRolePermissions ( $ role ) ; $ collection = new Collection ( ) ; foreach ( $ permissions as $ permission ) { if ( $ permission instanceof Restriction ) { continue ; } $ collection -> allow ( $ permission -> getAction ( ) , $ permission -> getResourceType ( ) , $ permission -> getResourceId ( ) ) ; } return $ collection ; }
|
Return a collection of role based permissions .
|
54,141
|
public function build ( ContainerBuilder $ container ) { parent :: build ( $ container ) ; $ configFile = new SplFileInfo ( ( new FileLocator ( $ this -> getPath ( ) . '/Resources/config' ) ) -> locate ( 'synapse.yml' ) , '' , '' ) ; $ container -> addCompilerPass ( new CompilerPass ( Yaml :: parse ( $ configFile -> getContents ( ) ) ) ) ; $ container -> addResource ( new FileResource ( $ configFile -> getRealPath ( ) ) ) ; }
|
override build to register theme configuration .
|
54,142
|
public static function createFromConfiguration ( $ role , array $ configuration ) { return new Role ( $ role , isset ( $ configuration [ "title" ] ) ? $ configuration [ "title" ] : null , isset ( $ configuration [ "description" ] ) ? $ configuration [ "description" ] : null , isset ( $ configuration [ "hidden" ] ) ? $ configuration [ "hidden" ] : false , isset ( $ configuration [ "tags" ] ) ? $ configuration [ "tags" ] : [ ] , isset ( $ configuration [ "actions" ] ) ? $ configuration [ "actions" ] : [ ] ) ; }
|
Creates the role from the configuration
|
54,143
|
protected function getValidPriority ( $ desiredPriority ) { $ desiredPriority = ( int ) $ desiredPriority * 10000 ; if ( ! in_array ( $ desiredPriority , $ this -> allocatedPriorities ) ) { return $ desiredPriority ; } $ increment = 1 ; while ( in_array ( $ desiredPriority , $ this -> allocatedPriorities ) ) { $ desiredPriority += $ increment ; } return $ desiredPriority ; }
|
Get a valid priority number to attach to a filter
|
54,144
|
public function cropFromEdge ( $ cropWidth , $ cropHeight = null , $ edge = 0 ) { if ( $ cropHeight === null ) { $ cropHeight = $ cropWidth ; } $ cropWidth = ( $ this -> _sourceWidth < $ cropWidth ) ? $ this -> _sourceWidth : $ cropWidth ; $ cropHeight = ( $ this -> _sourceHeight < $ cropHeight ) ? $ this -> _sourceHeight : $ cropHeight ; $ cropX = intval ( ( $ this -> _sourceWidth - $ cropWidth ) / 2 ) ; $ cropY = intval ( ( $ this -> _sourceHeight - $ cropHeight ) / 2 ) ; $ top = ( int ) $ edge | 12 ; if ( 14 == $ top ) { $ cropY = 0 ; } elseif ( 13 == $ top ) { $ cropY = $ this -> _sourceHeight - $ cropHeight ; } $ left = ( $ edge >> 2 ) ; if ( 2 == $ left ) { $ cropX = 0 ; } elseif ( 1 == $ left ) { $ cropX = $ this -> _sourceWidth - $ cropWidth ; } return $ this -> crop ( $ cropX , $ cropY , $ cropWidth , $ cropHeight ) ; }
|
Crop a picture from a given edge
|
54,145
|
public static function getResourceGroup ( $ name ) { $ group = FALSE ; if ( is_array ( $ name ) ) { $ count = count ( $ name ) ; if ( $ count < 1 || $ count > 2 ) { throw new Exception ( 'You must only pass the resource group and name for a resource.' ) ; } else if ( $ count == 1 ) { $ name = $ name [ 0 ] ; } else { $ group = $ name [ 0 ] ; $ name = $ name [ 1 ] ; } } if ( ! $ group ) { $ group = $ name ; } return array ( $ group , $ name ) ; }
|
Return a resource group and name given a name variable
|
54,146
|
public static function newResource ( $ name , $ resource , $ select = FALSE , $ overrride = FALSE , $ default = TRUE ) { list ( $ group , $ name ) = self :: getResourceGroup ( $ name ) ; if ( isset ( self :: $ resources [ $ group ] [ $ name ] ) && ! $ overrride ) { throw new Exception ( 'The ' . ( $ group ? $ group . '\\' : '' ) . $ name . ' resource already exists.' ) ; } if ( $ select || ( $ default && ! self :: getGroupSetting ( $ group , 'default' ) ) ) { self :: setGroupSetting ( $ group , 'default' , $ name ) ; } self :: $ resources [ $ group ] [ $ name ] = $ resource ; }
|
Set a new framework resource
|
54,147
|
public static function newResources ( $ group , $ resources , $ setDefault = TRUE , $ defaultOverride = FALSE ) { foreach ( $ resources as $ resource ) { $ select = FALSE ; $ name = FALSE ; $ override = $ defaultOverride ; if ( is_object ( $ resource ) ) { $ obj = $ resource ; } elseif ( ! is_array ( $ resource ) || ! $ resource || ! is_object ( $ resource [ 0 ] ) ) { throw new Exception ( 'Invalid resource to add to group ' . $ group ) ; } else { foreach ( $ resource as $ arg => $ val ) { switch ( $ arg ) { case 0 : $ obj = $ val ; break ; case 1 : $ name = $ val ; break ; case 2 : $ select = $ val ; break ; case 3 : $ override = $ val ; break ; } } } if ( ! $ name ) { $ name = $ group . '-' . ( self :: countResourceGroup ( $ group ) + 1 ) ; } self :: newResource ( array ( $ group , $ name ) , $ obj , $ select , $ override , $ setDefault ) ; } }
|
Set a group of framework resources
|
54,148
|
public static function removeResource ( $ group , $ name = FALSE ) { if ( $ name ) { unset ( self :: $ resources [ $ group ] [ $ name ] ) ; if ( self :: getGroupSetting ( $ group , 'default' ) == $ name ) { self :: removeDefault ( $ group ) ; } } else { unset ( self :: $ resources [ $ group ] ) ; } if ( self :: countResourceGroup ( $ group ) < 1 ) { unset ( self :: $ resourceSettings [ $ group ] ) ; } }
|
Delete resource or resource group
|
54,149
|
public static function & getResource ( $ name ) { list ( $ group , $ name ) = self :: getResourceGroup ( $ name ) ; if ( ! isset ( self :: $ resources [ $ group ] [ $ name ] ) ) { $ bln = FALSE ; return $ bln ; } return self :: $ resources [ $ group ] [ $ name ] ; }
|
Return a framework resource reference
|
54,150
|
public static function getSelectedResources ( ) { $ resources = array ( ) ; foreach ( array_keys ( self :: $ resourceSettings ) as $ group ) { $ resources [ $ group ] = & self :: getResource ( array ( $ group , self :: getGroupSetting ( $ group , 'default' ) ) ) ; } return $ resources ; }
|
Return an array of reference resource objects which are currently selected
|
54,151
|
public static function & getSelectedResource ( $ group ) { if ( ! isset ( self :: $ resources [ $ group ] ) || ! self :: getGroupSetting ( $ group , 'default' ) ) { $ bln = FALSE ; return $ bln ; } return self :: getResource ( array ( $ group , self :: getGroupSetting ( $ group , 'default' ) ) ) ; }
|
Return the currently selected resource for a resource group
|
54,152
|
public static function setSelectedResource ( $ group , $ name ) { if ( ! isset ( self :: $ resources [ $ group ] [ $ name ] ) ) { return FALSE ; } self :: setGroupSetting ( $ group , 'default' , $ name ) ; return TRUE ; }
|
Set the selected resource for a resource group
|
54,153
|
public static function selectRandomResource ( $ group ) { if ( ! isset ( self :: $ resources [ $ group ] ) ) { $ bln = FALSE ; return $ bln ; } return array_rand ( self :: $ resources [ $ group ] ) ; }
|
Return a random group resource name
|
54,154
|
public static function countResourceGroup ( $ group ) { return isset ( self :: $ resources [ $ group ] ) ? count ( self :: $ resources [ $ group ] ) : 0 ; }
|
Return number of resource in a group
|
54,155
|
public static function getGroupSetting ( $ group , $ setting ) { return isset ( self :: $ resourceSettings [ $ group ] [ $ setting ] ) ? self :: $ resourceSettings [ $ group ] [ $ setting ] : FALSE ; }
|
Return group setting or FALSE if not set
|
54,156
|
public function startWithNode ( $ name , $ nodes ) { if ( ! is_array ( $ nodes ) ) { $ nodes = array ( $ nodes ) ; } $ parts = array ( ) ; foreach ( $ nodes as $ key => $ node ) { $ fullKey = $ name . '_' . $ key ; $ parts [ ] = ":$fullKey" ; $ this -> set ( $ fullKey , $ node ) ; } $ parts = implode ( ', ' , $ parts ) ; $ this -> start ( "$name = node($parts)" ) ; return $ this ; }
|
Adds nodes to the queries start clause .
|
54,157
|
public function startWithLookup ( $ name , $ index , $ key , $ value ) { $ this -> start ( "$name = node:`$index`($key = :{$name}_{$key})" ) ; $ this -> set ( "{$name}_{$key}" , $ value ) ; return $ this ; }
|
Adds a node lookup to the queries start clause .
|
54,158
|
public function set ( $ name , $ value ) { if ( is_object ( $ value ) && method_exists ( $ value , 'getId' ) ) { $ this -> parameters [ $ name ] = $ value -> getId ( ) ; } else { $ this -> parameters [ $ name ] = $ value ; } return $ this ; }
|
Sets named query parameters .
|
54,159
|
public function getOne ( ) { $ result = $ this -> execute ( ) ; if ( isset ( $ result [ 0 ] ) ) { return $ this -> convertValue ( $ result [ 0 ] [ 0 ] ) ; } return null ; }
|
Executes the query and returns one result .
|
54,160
|
public function getList ( ) { $ result = $ this -> execute ( ) ; $ list = new ArrayCollection ; foreach ( $ result as $ row ) { $ list -> add ( $ this -> convertValue ( $ row [ 0 ] ) ) ; } return $ list ; }
|
Executes the query and returns a list of results as entities .
|
54,161
|
public function getResult ( ) { $ result = $ this -> execute ( ) ; $ list = new ArrayCollection ; foreach ( $ result as $ row ) { $ entry = array ( ) ; foreach ( $ row as $ key => $ value ) { $ entry [ $ key ] = $ this -> convertValue ( $ value ) ; } $ list -> add ( $ entry ) ; } return $ list ; }
|
Executes the query and returns a array collection of assoc . arrays without converting them to entities .
|
54,162
|
private function processParameters ( ) { $ parameters = $ this -> parameters ; $ string = $ this -> query ; $ string = str_replace ( '[:' , '[;;' , $ string ) ; $ parameters = array_filter ( $ parameters , function ( $ value ) use ( & $ parameters , & $ string ) { $ key = key ( $ parameters ) ; next ( $ parameters ) ; if ( is_numeric ( $ value ) ) { $ string = str_replace ( ":$key" , $ value , $ string ) ; return false ; } else { $ string = str_replace ( ":$key" , '{' . $ key . '}' , $ string ) ; return true ; } } ) ; $ string = str_replace ( '[;;' , '[:' , $ string ) ; $ this -> query = $ string ; return $ parameters ; }
|
Processes parameters and returns an array of them afterwards .
|
54,163
|
protected function compare ( $ schedule1 , $ schedule2 ) { $ run1 = $ schedule1 -> getNextRunDate ( ) ; $ run2 = $ schedule2 -> getNextRunDate ( ) ; if ( $ run1 < $ run2 ) { return 1 ; } elseif ( $ run1 > $ run2 ) { return - 1 ; } return 0 ; }
|
Compare the schedules the one with the first nextRunDate will be added at the beginning of the list .
|
54,164
|
protected function delete_assignment ( ) { $ uri = str_replace ( '{assignment}' , $ this -> assignment , config ( 'forge-publish.update_assignment_uri' ) ) ; $ url = config ( 'forge-publish.url' ) . $ uri ; try { $ response = $ this -> http -> delete ( $ url , [ 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest' , 'Authorization' => 'Bearer ' . fp_env ( 'ACACHA_FORGE_ACCESS_TOKEN' ) ] ] ) ; } catch ( \ Exception $ e ) { $ this -> error ( 'And error occurs connecting to the api url: ' . $ url ) ; $ this -> error ( 'Status code: ' . $ e -> getResponse ( ) -> getStatusCode ( ) . ' | Reason : ' . $ e -> getResponse ( ) -> getReasonPhrase ( ) ) ; return [ ] ; } }
|
Delete assignment .
|
54,165
|
public static function fromMessage ( Message $ msg ) { $ workerHandlerId = $ msg -> shift ( ) ; $ requestId = $ msg -> shift ( ) ; if ( ! $ requestId ) { $ requestId = null ; } return new self ( $ workerHandlerId , $ requestId ) ; }
|
Creates an instance based on the Message .
|
54,166
|
public function run ( ) { $ this -> tryAssignController ( ) ; if ( ! $ this -> isControllerAssigned ( ) ) { throw new Exception ( "It's unable to assign controller to this route path." ) ; } $ oCtrl = $ this -> createCtrl ( ) ; $ oCtrl -> { $ this -> actionName } ( $ this -> actionArgs ) ; }
|
It executes the action of controller .
|
54,167
|
private function writeArray ( array $ array , $ depth , $ comments = false ) { $ isIndexed = array_values ( $ array ) === $ array ; $ method = $ comments ? 'writeComment' : 'writeLine' ; foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { $ val = '' ; } else { $ val = $ value ; } $ key = $ this -> serializeValue ( $ key ) ; $ val = $ this -> serializeValue ( $ val ) ; if ( $ isIndexed ) { $ this -> $ method ( $ val . ',' , $ depth ) ; } else { $ this -> $ method ( sprintf ( '%s => %s,' , $ key , $ val ) , $ depth ) ; } if ( is_array ( $ value ) ) { $ this -> writeArray ( $ value , $ depth + 1 ) ; } } }
|
Output an array .
|
54,168
|
private function outputExamples ( $ depth ) { if ( is_array ( $ this -> example ) ) { $ message = count ( $ this -> example ) > 1 ? 'Examples' : 'Example' ; $ this -> writeComment ( $ message . ':' , $ depth * 4 + 4 ) ; $ this -> writeArray ( $ this -> example , $ depth * 4 + 4 , true ) ; } }
|
Output the node s examples .
|
54,169
|
private function outputDefaults ( $ depth ) { if ( $ this -> defaultArray ) { $ message = count ( $ this -> defaultArray ) > 1 ? 'Defaults' : 'Default' ; $ childDepth = $ depth * 4 + 4 ; $ this -> writeComment ( $ message . ':' , $ childDepth ) ; $ this -> writeArray ( $ this -> defaultArray , $ childDepth ) ; } }
|
Output the node s default value .
|
54,170
|
private function outputChildren ( $ children , $ depth ) { if ( $ children ) { foreach ( $ children as $ childNode ) { if ( $ childNode -> getInfo ( ) === 'Prototype' ) { $ childNode -> setInfo ( '' ) ; $ hasChildren = ! $ childNode instanceof ArrayNode || ! $ childNode -> getChildren ( ) ; $ this -> writeNode ( $ childNode , $ depth + 1 , $ hasChildren ) ; } else { $ this -> writeNode ( $ childNode , $ depth + 1 ) ; } } } if ( $ children || $ this -> example || $ this -> defaultArray ) { $ this -> writeLine ( '],' , $ depth * 4 ) ; } }
|
Output the children of the node .
|
54,171
|
private function _newRound ( ) { $ environment_factory = EnvironmentFactory :: Get ( ) ; if ( ! in_array ( RoundBasedEnvironmentFactory :: class , class_parents ( $ environment_factory ) ) ) { throw RuntimeException :: EnvironmentFactoryIsNotRoundBased ( ) ; } return $ environment_factory -> newRound ( $ this -> _currentRoundNo ) ; }
|
Returns a new round generated by the EnvironmentFactory object .
|
54,172
|
public function addRound ( ) { ++ $ this -> _currentRoundNo ; $ new_round = $ this -> _newRound ( ) ; $ this -> _rounds -> offsetSet ( $ this -> _currentRoundNo , $ new_round ) ; return $ new_round ; }
|
Creates the next round and returns the new current round .
|
54,173
|
public function parse ( ) { $ time = time ( ) ; $ gmdate = gmdate ( 'D, d M Y H:i:s' , $ time ) ; Container :: get ( 'response' ) -> setHeader ( 'MDE-Version' , \ MarkdownExtended \ MarkdownExtended :: MDE_VERSION ) -> setHeader ( 'Last-Modified' , $ gmdate . ' GMT' ) ; $ etag = '' ; $ sources = $ this -> getSources ( ) ; $ options = Container :: get ( 'request' ) -> getData ( 'options' , array ( ) ) ; $ format = Container :: get ( 'request' ) -> getData ( 'format' ) ; $ extract = Container :: get ( 'request' ) -> getData ( 'extract' , 'full' ) ; if ( ! empty ( $ format ) ) { $ options [ 'output_format' ] = $ format ; } if ( ! empty ( $ sources ) ) { try { foreach ( $ sources as $ index => $ source ) { $ mde_content = Helper :: parseMdeSource ( $ source , $ options ) ; switch ( $ extract ) { case 'metadata' : $ parsed_content = $ mde_content -> getMetadataToString ( ) ; break ; case 'body' : $ parsed_content = $ mde_content -> getBody ( ) ; break ; case 'notes' : $ parsed_content = $ mde_content -> getNotesToString ( ) ; break ; case 'full' : default : $ parsed_content = $ mde_content -> getMetadataToString ( ) . PHP_EOL . $ mde_content -> getBody ( ) . PHP_EOL . $ mde_content -> getNotesToString ( ) ; break ; } $ etag .= $ source . '=' . $ parsed_content . ';' ; $ content_index = $ this -> addContent ( $ parsed_content ) ; if ( $ this -> getSourceType ( ) == 'file' && is_string ( $ index ) ) { $ source = $ index ; } if ( $ content_index !== $ index ) { $ this -> unsetSource ( $ index ) -> setSource ( $ content_index , $ source ) ; } } } catch ( \ Exception $ e ) { throw $ e ; } $ etag = md5 ( $ etag ) ; Container :: get ( 'response' ) -> setHeader ( 'ETag' , $ etag ) ; } $ if_modified_since = Container :: get ( 'request' ) -> getHeader ( 'If-Modified-Since' ) ; $ if_none_match = Container :: get ( 'request' ) -> getHeader ( 'If-None-Match' ) ; if ( ( ! empty ( $ if_modified_since ) && @ strtotime ( $ if_modified_since ) >= $ time ) || ( ! empty ( $ if_none_match ) && ! empty ( $ etag ) && trim ( $ if_none_match ) == $ etag ) ) { Container :: get ( 'response' ) -> setStatus ( Response :: STATUS_NOT_MODIFIED ) -> fetchHeaders ( ) ; exit ( PHP_EOL ) ; } return $ this ; }
|
Parse the sources contents
|
54,174
|
public function serve ( ) { $ type = $ this -> getSourceType ( ) ; $ sources = $ this -> getSources ( ) ; $ contents = $ this -> getContents ( ) ; if ( $ type != 'file' && count ( $ sources ) == 1 ) { $ response_data = array ( 'source' => $ sources [ 0 ] , 'content' => $ contents [ 0 ] , ) ; } else { $ response_data = array ( 'sources' => $ sources , 'contents' => $ contents , ) ; } $ errors_collection = $ this -> getErrors ( ) ; $ errors = array ( ) ; foreach ( $ errors_collection as $ _error ) { $ errors [ ] = $ _error -> getFullMessage ( ) ; } $ response_data [ 'errors' ] = $ errors ; if ( $ this -> isDebug ( ) ) { $ response_data [ 'dump' ] = serialize ( $ this ) ; } if ( Container :: get ( 'request' ) -> isMethod ( 'head' ) ) { Container :: get ( 'response' ) -> fetchHeaders ( ) ; exit ( PHP_EOL ) ; } else { try { Container :: get ( 'response' ) -> send ( $ response_data ) ; } catch ( \ Exception $ e ) { $ this -> warning ( $ e -> getMessage ( ) ) ; Container :: get ( 'response' ) -> setContent ( array ( 'errors' => $ this -> getErrors ( ) ) ) -> fetch ( ) ; } } }
|
Serve the JSON response and exit
|
54,175
|
public function warning ( $ str , $ status = Response :: STATUS_OK ) { $ this -> addError ( new Error ( $ str , $ status ) ) ; return $ this ; }
|
Add a simple not - fatal error message
|
54,176
|
public function error ( $ str , $ code = Response :: STATUS_ERROR ) { $ this -> addError ( new Error ( $ str , $ code ) ) ; Container :: get ( 'response' ) -> setStatus ( $ code ) ; if ( ! Container :: get ( 'response' ) -> isStatus ( Response :: STATUS_OK ) ) { $ this -> serve ( ) ; } }
|
Handle errors adding the error message to the response and serving it if needed
|
54,177
|
public static function bySerializedContentType ( $ contentType ) { switch ( $ contentType ) { case PhpSerializer :: SERIALIZED_CONTENT_TYPE : $ serializer = new PhpSerializer ( ) ; break ; case JsonSerializer :: SERIALIZED_CONTENT_TYPE : $ serializer = new JsonSerializer ( ) ; break ; case NullSerializer :: SERIALIZED_CONTENT_TYPE : $ serializer = new NullSerializer ( ) ; break ; default : throw new Exception ( 'Not supported content type!' ) ; } return $ serializer ; }
|
Creates a Serializer for the given content type .
|
54,178
|
protected function getPublicPropertiesName ( ) : array { $ reflectionClass = new \ ReflectionClass ( $ this ) ; $ publicProperties = $ reflectionClass -> getProperties ( \ ReflectionProperty :: IS_PUBLIC ) ; return array_map ( function ( \ ReflectionProperty $ property ) { return $ property -> name ; } , $ publicProperties ) ; }
|
Get all the public properties name .
|
54,179
|
public static function __instance ( ) { if ( empty ( self :: $ __instance ) ) { self :: $ __instance = with ( new \ ReflectionClass ( self :: $ __class ) ) -> newInstanceArgs ( self :: $ __args ) ; } return self :: $ __instance ; }
|
Get the underlying instance .
|
54,180
|
public function filterByDataType ( $ data_type ) { $ callback = function ( BindingInterface $ binding , $ key ) use ( $ data_type ) { switch ( $ data_type ) { case PDO :: PARAM_BOOL : return $ binding -> isBoolean ( ) ; case PDO :: PARAM_NULL : return $ binding -> isNull ( ) ; case PDO :: PARAM_INT : return $ binding -> isInteger ( ) ; case PDO :: PARAM_STR : return $ binding -> isString ( ) ; case PDO :: PARAM_LOB : return $ binding -> isLargeObject ( ) ; case PDO :: PARAM_STMT : return $ binding -> isStatement ( ) ; case PDO :: PARAM_INPUT_OUTPUT : return $ binding -> isInputOutput ( ) ; } } ; return $ this -> filter ( $ callback ) ; }
|
Create a new collection with only bindings with a given data type .
|
54,181
|
public function filterByParameter ( $ parameter ) { $ callback = function ( BindingInterface $ binding , $ key ) use ( $ parameter ) { return $ binding -> getParameter ( ) == $ parameter ; } ; return $ this -> filter ( $ callback ) ; }
|
Create a new collection with only bindings with a parameter that matches the provided parameter value .
|
54,182
|
public function filterByValue ( $ value ) { $ callback = function ( BindingInterface $ binding , $ key ) use ( $ value ) { return $ binding -> getValue ( ) == $ value ; } ; return $ this -> filter ( $ callback ) ; }
|
Create a new collection with only bindings with a value that matches the provided value .
|
54,183
|
public function filterByValueLike ( $ value ) { $ callback = function ( BindingInterface $ binding , $ key ) use ( $ value ) { return strpos ( $ binding -> getValue ( ) , $ value ) !== false ; } ; return $ this -> filter ( $ callback ) ; }
|
Create a new collection with only bindings with a value that contain the provided value .
|
54,184
|
public function hydrateFromArray ( array $ array ) { $ this -> clear ( ) ; if ( current ( array_keys ( $ array ) ) === 0 ) { $ array = array_combine ( range ( 1 , count ( $ array ) ) , array_values ( $ array ) ) ; } foreach ( $ array as $ key => $ value ) { $ this -> push ( $ this -> wye -> makeBinding ( $ key , $ value ) ) ; } return $ this ; }
|
Rebuilds the contents of the collection based on the provided array . Keys become binding parameters and values are used for binding values . 0 - indexed numerical - keyed arrays are shifted once to begin with 1 .
|
54,185
|
public static function formatPermissions ( array $ userPermissions ) : array { $ userPermissions = self :: format ( $ userPermissions ) ; foreach ( $ userPermissions as $ key => $ permission ) { $ userPermissions [ $ key ] = self :: $ permissions [ $ key ] ; } return $ userPermissions ; }
|
Replace user permission with PermissionRegistrar
|
54,186
|
public function index ( $ id , $ code = null ) { $ locale = is_null ( $ code ) ? app ( ) -> getLocale ( ) : $ code ; $ locale = $ locale == null ? 'en' : $ locale ; $ current = Languages :: where ( 'code' , $ locale ) -> first ( ) ; $ languages = Languages :: query ( ) -> get ( ) ; if ( ! $ this -> translationRepository -> count ( $ id , $ locale ) ) { return redirect ( handles ( 'antares::translations/sync/' . $ id . '/' . $ locale ) ) ; } return $ this -> presenter -> table ( $ id , $ current , $ languages , $ this -> translationRepository -> getCategories ( $ id , $ locale ) ) ; }
|
default translation action
|
54,187
|
public function translation ( $ type ) { $ keys = Input :: get ( 'keys' ) ; $ code = Input :: get ( 'code' ) ; $ collection = Translation :: where ( 'area' , $ type ) -> whereIn ( 'key' , $ keys ) -> where ( 'locale' , $ code ) -> get ( ) ; $ map = array_map ( function ( $ item ) { return array_only ( $ item , [ 'id' , 'key' , 'value' ] ) ; } , $ collection -> toArray ( ) ) ; return new JsonResponse ( $ map , 200 ) ; }
|
single term translation
|
54,188
|
public function update ( TranslationListener $ listener , $ type ) { $ params = Input :: all ( ) ; $ first = head ( array_keys ( array_get ( $ params , 'name' ) ) ) ; $ translation = Translation :: whereId ( $ first ) -> with ( 'language' ) -> first ( ) ; $ code = $ translation -> language -> code ; if ( $ this -> translationRepository -> updateTranslations ( $ params , $ type ) ) { return $ listener -> updateSuccessfull ( $ type , $ code ) ; } return $ listener -> updateFailed ( $ type , $ code ) ; }
|
updates term translation
|
54,189
|
public function group ( TranslationListener $ listener , $ typeId , $ group , $ code = null ) { try { Session :: put ( 'group' , $ group ) ; return redirect ( handles ( "antares::translations/index/{$typeId}/{$code}" ) ) ; } catch ( Exception $ e ) { Log :: warning ( $ e ) ; return $ listener -> groupFailedFailed ( $ e -> getMessage ( ) ) ; } }
|
process changing translation group
|
54,190
|
public function rawDispatch ( $ command = null , array $ source = null ) { if ( $ command !== null ) ; elseif ( isset ( $ _REQUEST [ $ this -> cmdVar ] ) ) $ command = $ _REQUEST [ $ this -> cmdVar ] ; else throw new Exception ( 'No command specified!' ) ; if ( ! isset ( $ this -> actions [ $ command ] ) ) throw new Exception ( 'Unknown command: ' . $ command ) ; $ functionSpec = $ this -> actions [ $ command ] ; $ method = strtoupper ( array_shift ( $ functionSpec ) ) ; $ function = array_shift ( $ functionSpec ) ; if ( $ source === null ) { switch ( $ method ) { case 'GET' : $ source = $ _GET ; break ; case 'POST' : $ source = $ _POST ; break ; case 'PUT' : case 'DELETE' : parse_str ( file_get_contents ( 'php://input' ) , $ source ) ; break ; default : $ source = $ _REQUEST ; break ; } } $ parameters = array ( ) ; if ( sizeof ( $ functionSpec ) > 0 ) { foreach ( $ functionSpec [ 0 ] as $ param ) { if ( ! is_array ( $ param ) ) { $ parameters [ ] = $ this -> initParam ( $ source , $ param ) ; } else { $ type = ( ( isset ( $ param [ 1 ] ) and array_key_exists ( 1 , $ param ) ) ? $ param [ 1 ] : 'string' ) ; $ default = ( ( isset ( $ param [ 2 ] ) and array_key_exists ( 2 , $ param ) ) ? $ param [ 2 ] : null ) ; $ required = ( isset ( $ param [ 3 ] ) ? ( bool ) $ param [ 3 ] : true ) ; $ parameters [ ] = $ this -> initParam ( $ source , $ param [ 0 ] , $ type , $ default , $ required ) ; } } } $ res = call_user_func_array ( array ( $ this , $ this -> prefix . $ function ) , $ parameters ) ; if ( $ res instanceof VoidResult ) return null ; return ( is_array ( $ res ) && ( isset ( $ res [ 'result' ] ) || isset ( $ res [ 'error' ] ) ) ) ? $ res : array ( 'result' => $ res ) ; }
|
Executes an API function possibly throwing an exception on errors .
|
54,191
|
protected function exceptionToResult ( \ Exception $ e ) { if ( ! $ this -> showerror ) return null ; elseif ( $ this -> showtrace ) return array ( 'error' => $ e -> getMessage ( ) , 'trace' => errorTrace ( $ e ) ) ; else return array ( 'error' => $ e -> getMessage ( ) ) ; }
|
Converts an exception to result data suitable for output as JSON .
|
54,192
|
public function run ( ) { if ( ! isset ( $ _REQUEST [ $ this -> cmdVar ] ) ) throw new Exception ( 'No task specified.' ) ; elseif ( ! in_array ( $ _REQUEST [ $ this -> cmdVar ] , $ this -> auth_exceptions ) && ! $ this -> auth ( ) ) throw new Exception ( 'Authentication required.' ) ; $ this -> runJSON ( ) ; }
|
Only runs a function if a valid authentication token has been sent .
|
54,193
|
public function authCookieToken ( $ strCookieToken ) { if ( $ username = self :: validateCookieToken ( $ strCookieToken ) ) { self :: setUserSession ( array ( 'username' => $ user ) ) ; return true ; } return false ; }
|
Authenticates a user by using the session cookie
|
54,194
|
static public function openResult ( $ res ) { if ( ! is_array ( $ res ) ) throw new Exception ( 'Invalid datatype. Array expected!' ) ; if ( isset ( $ res [ 'error' ] ) ) throw new Exception ( 'Server error: ' . $ res [ 'error' ] ) ; if ( ! isset ( $ res [ 'result' ] ) ) throw new Exception ( 'Server returned no result.' ) ; return $ res [ 'result' ] ; }
|
Opens the response envelope
|
54,195
|
public function setUserSession ( $ user ) { if ( ! isset ( $ user [ $ this -> usernameKey ] ) || $ user [ $ this -> usernameKey ] == '' ) throw new Exception ( 'Invalid username' ) ; foreach ( $ user as $ strKey => $ strValue ) $ _SESSION [ 'user_' . $ strKey ] = $ strValue ; }
|
Sets the user session information
|
54,196
|
public function getUserSession ( ) { if ( isset ( $ _SESSION [ 'user_' . $ this -> usernameKey ] ) ) { $ arrUser = array ( ) ; foreach ( $ _SESSION as $ strKey => $ strValue ) if ( substr ( $ strKey , 0 , 4 ) == 'user_' ) $ arrUser [ substr ( $ strKey , 4 ) ] = $ strValue ; return $ arrUser ; } return false ; }
|
Returns the current user session
|
54,197
|
public function rollback ( ) { if ( $ this -> readOnly ) { return false ; } $ this -> readOnly = true ; fclose ( $ this -> fp ) ; unlink ( $ this -> tmp ) ; }
|
Closes the temporary file delete it and flags the object as read only .
|
54,198
|
public function commit ( ) { if ( $ this -> readOnly ) { return false ; } $ this -> readOnly = true ; fflush ( $ this -> fp ) ; fclose ( $ this -> fp ) ; if ( ! @ rename ( $ this -> tmp , $ this -> file ) ) { throw new RuntimeException ( "Cannot move the temporary file" ) ; } return $ this -> file ; }
|
Finishes the writing of the file and saves it . After this function the object is pretty much read only .
|
54,199
|
public function write_log ( $ msg = '' , $ log_level = 0 ) { if ( $ this -> log_level > ( int ) $ log_level ) return true ; try { if ( ! $ this -> file -> open ( ( string ) "$this->_log_path/$this->_file_name" ) && ! $ this -> file -> create_file ( "$this->_log_path/$this->_file_name" ) ) { throw new LogException ( ( string ) "file: $this->_log_path/$this->_file_name couldn't be created." ) ; } $ this -> file -> open ( "$this->_log_path/$this->_file_name" ) ; if ( strpos ( $ msg , "\n" ) === false ) { $ msg = "[" . ( string ) date ( self :: LOG_DATE_FORMAT ) . ( string ) "] $msg " . "\n" ; } else { $ msg = "[" . ( string ) date ( self :: LOG_DATE_FORMAT ) . ( string ) "] $msg" ; } if ( $ this -> file -> append ( $ msg ) === false ) { } } catch ( LogException $ e ) { error_log ( $ e -> getMessage ( ) ) ; } return true ; }
|
write to the log file
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.