idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
2,000
public function render ( Response $ response ) : void { $ i = 0 ; foreach ( $ response -> getViewHelpers ( ) as $ name => $ view_helper ) { if ( is_a ( $ view_helper , ViewHelperInterface :: class ) ) { if ( null !== $ view_helper -> getParent ( ) && ! is_null ( $ response -> getViewHelper ( $ view_helper -> getParent ( ) ) ) ) { $ parent = $ response -> getViewHelper ( $ view_helper -> getParent ( ) ) ; if ( is_a ( $ parent , ViewHelperCollection :: class ) ) { $ parent -> append ( $ name , $ view_helper ) ; } } } } }
Loads the view helpers and outputs the response in an appropriate format .
2,001
public function createURL ( $ route_name , $ variables = [ ] ) { if ( ! isset ( $ this -> routes ) ) { $ this -> routes = Core :: i ( ) -> config -> getConfiguration ( 'routes' ) ; } if ( ! isset ( $ this -> routes [ $ route_name ] ) ) { throw new \ Exception ( 'The specified route, ' . $ route_name . ', was not defined.' ) ; } $ variables = array_merge ( $ this -> routes [ $ route_name ] [ 'defaults' ] , $ variables ) ; $ query_string = [ ] ; $ url = str_replace ( '[' , '' , $ this -> routes [ $ route_name ] [ 'route' ] ) ; $ url = str_replace ( ']' , '' , $ url ) ; foreach ( $ variables as $ key => $ value ) { if ( false !== strpos ( $ url , ':' . $ key . ':' ) ) { $ url = str_replace ( ':' . $ key . ':' , $ value , $ url ) ; } elseif ( $ key != 'controller' && $ key != 'action' && $ key != 'module' ) { $ query_string [ ] = urlencode ( $ key ) . '=' . urlencode ( $ value ) ; } } $ url = rtrim ( $ url , '/index' ) ; $ url = rtrim ( $ url , '/index' ) ; $ url = rtrim ( $ url , '/index' ) ; if ( count ( $ query_string ) > 0 ) { $ url .= '?' . implode ( '&' , $ query_string ) ; } $ url = ltrim ( $ url , '/' ) ; if ( \ Framework :: i ( ) -> locale_set ) { $ url = $ this -> getLinkLocale ( \ Framework :: i ( ) -> locale ) . '/' . $ url ; } return $ url ; }
Create a url based on a route . Passed variables will replace placeholders in the route . If the variable is not part of the route the variable will be appended as a query string .
2,002
public function createLink ( $ path , $ include_locale = false ) { $ protocol = ( \ Framework :: i ( ) -> isSecure ( ) ) ? 'https:' : 'http:' ; $ base = $ this -> getBaseURL ( $ include_locale ) ; return $ protocol . $ base . $ path ; }
Create an absolute path for use in links to use in place of relative links that can be affected by locale information .
2,003
public function getBaseURL ( $ include_locale = true ) { $ base = '//' . $ _SERVER [ 'HTTP_HOST' ] . str_replace ( 'index.php' , '' , $ _SERVER [ 'URL' ] ) ; if ( $ include_locale && \ Framework :: i ( ) -> locale_set ) { $ base .= $ this -> getLinkLocale ( \ Framework :: i ( ) -> locale ) . '/' ; } return $ base ; }
Calculates and returns the base URL for the site . This is used in the base HREF tag and can also be used for generating internal links to resources that don t correspond to Framework 2 paths .
2,004
public static function Ee00b ( $ date1 , $ date2 ) { $ dpsipr ; $ depspr ; $ epsa ; $ dpsi ; $ deps ; $ ee ; IAU :: Pr00 ( $ date1 , $ date2 , $ dpsipr , $ depspr ) ; $ epsa = IAU :: Obl80 ( $ date1 , $ date2 ) + $ depspr ; IAU :: Nut00b ( $ date1 , $ date2 , $ dpsi , $ deps ) ; $ ee = IAU :: Ee00 ( $ date1 , $ date2 , $ epsa , $ dpsi ) ; return $ ee ; }
- - - - - - - - - i a u E e 0 0 b - - - - - - - - -
2,005
protected static function checkVersion ( ) { if ( self :: $ checked === true ) { return true ; } $ process = new \ SystemProcess \ SystemProcess ( 'bzr' ) ; $ process -> nonZeroExitCodeException = true ; $ process -> argument ( '--version' ) -> execute ( ) ; if ( ! preg_match ( '/\Bazaar \(bzr\) ([0-9.]*)/' , $ process -> stdoutOutput , $ match ) ) { throw new \ RuntimeException ( 'Could not determine Bazaar version.' ) ; } if ( version_compare ( $ match [ 1 ] , '1.1' , '<' ) ) { throw new \ RuntimeException ( 'Bazaar is required in a minimum version of 1.1.' ) ; } $ process = new \ SystemProcess \ SystemProcess ( 'bzr' ) ; $ process -> nonZeroExitCodeException = true ; $ process -> argument ( 'plugins' ) -> execute ( ) ; if ( strpos ( $ process -> stdoutOutput , 'xmloutput' ) === false ) { throw new \ RuntimeException ( 'Missing required bazaar pluging "xmloutput".' ) ; } return self :: $ checked = true ; }
Verify bzr version
2,006
public function countMethodAnnotations ( ) { $ counter = 0 ; foreach ( $ this -> methodAnnotations as $ method ) { if ( count ( $ method ) == 0 ) { return 0 ; } foreach ( $ method as $ annotationToken ) { $ counter = $ counter + count ( $ annotationToken ) ; } } return $ counter ; }
Count the filtered annotation lines in all method the class have .
2,007
public function cssAction ( ) { $ pygmentize = $ this -> get ( 'cypress.pygments_elephant.pygmentize' ) ; $ response = new Response ( ) ; $ response -> headers -> set ( 'content-type' , 'text/css' ) ; $ response -> setContent ( $ pygmentize -> generateCss ( ) ) ; return $ response ; }
css for pygments
2,008
public function findFile ( $ class ) { if ( ! function_exists ( 'drupal_get_path' ) ) { return ; } $ class = ltrim ( $ class , '\\' ) ; $ expl = explode ( '\\' , $ class ) ; $ module = strtolower ( preg_replace ( '/(?<=\\w)(?=[A-Z])/' , '_$1' , reset ( $ expl ) ) ) ; if ( 2 === count ( $ expl ) ) { foreach ( array ( $ module , strtolower ( reset ( $ expl ) ) ) as $ mod ) { $ className = strtolower ( end ( $ expl ) ) ; $ file = DRUPAL_ROOT . DIRECTORY_SEPARATOR . drupal_get_path ( 'module' , $ mod ) . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . "{$className}.class.inc" ; if ( file_exists ( $ file ) ) { return $ file ; } } } if ( 1 !== count ( $ expl ) ) { $ classPath = str_replace ( '_' , DIRECTORY_SEPARATOR , array_pop ( $ expl ) ) ; $ file = DRUPAL_ROOT . DIRECTORY_SEPARATOR . drupal_get_path ( 'module' , $ module ) . DIRECTORY_SEPARATOR . implode ( DIRECTORY_SEPARATOR , $ expl ) . DIRECTORY_SEPARATOR . "{$classPath}.php" ; if ( file_exists ( $ file ) ) { return $ file ; } } }
Tries to locate the file where the class is defined .
2,009
public static function create ( $ className ) { $ bestLoggerConfiguration = LoggerManager :: findBestLoggerConfigurationForClass ( $ className ) ; if ( ! isset ( $ bestLoggerConfiguration ) ) { return new Logger ( $ className ) ; } $ logger = new Logger ( $ className ) ; $ logger -> _targetClassName = $ bestLoggerConfiguration [ 'class' ] ; $ logger -> _level = LogLevel :: createFromCode ( $ bestLoggerConfiguration [ 'level' ] ) ; $ logger -> _setupWriters ( $ bestLoggerConfiguration [ 'writers' ] ) ; return $ logger ; }
Create and return a Logger
2,010
public function emergency ( $ messageOrException , $ contextOrException = null , array $ context = array ( ) ) { $ this -> log ( LogLevel :: EMERGENCY , $ messageOrException , $ contextOrException , $ context ) ; }
System is unusable
2,011
public function alert ( $ messageOrException , $ contextOrException = null , array $ context = array ( ) ) { $ this -> log ( LogLevel :: ALERT , $ messageOrException , $ contextOrException , $ context ) ; }
Action must be taken immediately
2,012
public function error ( $ messageOrException , $ contextOrException = null , array $ context = array ( ) ) { $ this -> log ( LogLevel :: ERROR , $ messageOrException , $ contextOrException , $ context ) ; }
Runtime errors that do not require immediate action but should typically be logged and monitored
2,013
public function warning ( $ messageOrException , $ contextOrException = null , array $ context = array ( ) ) { $ this -> log ( LogLevel :: WARNING , $ messageOrException , $ contextOrException , $ context ) ; }
Exceptional occurrences that are not errors
2,014
public function notice ( $ messageOrException , $ contextOrException = null , array $ context = array ( ) ) { $ this -> log ( LogLevel :: NOTICE , $ messageOrException , $ contextOrException , $ context ) ; }
Normal but significant events
2,015
public function debug ( $ messageOrException , $ contextOrException = null , array $ context = array ( ) ) { $ this -> log ( LogLevel :: DEBUG , $ messageOrException , $ contextOrException , $ context ) ; }
Detailed debug information
2,016
public static function split ( $ delimiter , $ value , $ limit = null ) { if ( $ delimiter == '' ) { return $ value ; } if ( $ limit == null ) { return explode ( $ delimiter , $ value ) ; } else { return explode ( $ delimiter , $ value , $ limit ) ; } }
Returns an array of strings each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter .
2,017
public static function regexResult ( $ reg , $ str , $ match = 1 ) { preg_match_all ( $ reg , $ str , $ matches ) ; return $ matches [ $ match ] ; }
Obtain matches from a Regex expression .
2,018
public function searchTweets ( $ query , $ count = 10 ) { if ( $ this -> bearer_token == null ) { throw new \ Exception ( 'Incorrect token. You need to obtain correct Bearer token in order to make calls to the API. Check if your API keys are correct.' ) ; } $ this -> makeRequest ( $ query , $ count ) ; }
Pull tweets from API
2,019
public function makeRequest ( $ query , $ count ) { try { $ response = $ this -> client -> request ( 'GET' , self :: $ api_base . '1.1/search/tweets.json' , [ 'query' => [ 'q' => $ query , 'count' => $ count ] , 'headers' => [ 'Authorization' => 'Bearer ' . $ this -> bearer_token ] ] ) ; $ this -> setStatusCode ( $ response -> getStatusCode ( ) ) ; $ response_body = json_decode ( $ response -> getBody ( ) ) ; $ this -> response = $ response_body -> statuses ; } catch ( \ Exception $ e ) { $ this -> setStatusCode ( $ e -> getCode ( ) ) ; $ this -> setResponse ( $ e -> getMessage ( ) ) ; } }
Get raw Twitter response
2,020
public function isBearer ( $ response ) { if ( ! isset ( $ response -> token_type ) ) { return false ; } if ( $ response -> token_type == 'bearer' ) { return $ response -> access_token ; } }
Validate the initial response to check if the response has a bearer token
2,021
public static function cache ( $ key , $ value ) { $ key = static :: createCacheKey ( $ key ) ; if ( $ cache = static :: getCache ( $ key ) ) { return $ cache ; } if ( $ value instanceof Closure ) { $ value = call_user_func ( $ value ) ; } return static :: setCache ( $ key , $ value ) ; }
Dynamically read and write from the cache at once . If the cache exists with the key return it else execute and save the result . If the value happens to be a closure evaluate the closure and save the result .
2,022
private function hasPermission ( AuthenticatedUserInterface $ user , string $ uri ) { $ permissions = $ this -> getParameterByKey ( "permissions" ) ; foreach ( $ permissions as $ permissionPath => $ acceptableRoles ) { if ( $ permissionPath [ 0 ] !== "/" ) { $ permissionPath = "/" . $ permissionPath ; } if ( substr ( $ permissionPath , - 1 ) !== "/" ) { $ permissionPath = $ permissionPath . "/" ; } $ match = preg_match ( $ permissionPath , $ uri ) ; if ( $ match == 1 ) { if ( in_array ( Role :: ANON_USER , $ acceptableRoles ) ) return true ; foreach ( $ acceptableRoles as $ permissionRole ) { if ( in_array ( $ permissionRole , $ user -> getRoles ( ) ) ) return true ; } return false ; } } return false ; }
Checks that the user has permission to get response for the request .
2,023
public function isEmpty ( ) { if ( parent :: isEmpty ( ) ) { return true ; } if ( null === $ this -> read ( ) ) { $ this -> clear ( ) ; return true ; } return false ; }
Returns true if and only if storage is empty .
2,024
public function read ( ) { $ identity = $ this -> identity ; if ( null === $ identity ) { $ identity = parent :: read ( ) ; $ this -> identity = $ identity ; } return $ identity ; }
Returns the contents of storage . Behavior is undefined when storage is empty .
2,025
protected function scanAddonDefinition ( $ definitionFile ) { if ( ! file_exists ( $ definitionFile ) ) { throw new \ Exception ( "missing definition file" ) ; } $ definition = [ 'path' => dirname ( $ definitionFile ) , 'requires' => [ ] ] ; $ definitionData = json_decode ( file_get_contents ( $ definitionFile ) , true ) ; if ( ! $ definitionData ) { throw new \ Exception ( "failed to parse definition file" ) ; } $ definition = array_merge_recursive ( $ definition , $ definitionData ) ; $ requiredKeys = [ 'name' , 'description' , 'author' , 'version' ] ; $ requiredMatch = array_fill_keys ( $ requiredKeys , null ) ; $ requirementCheck = array_intersect_key ( $ definition , $ requiredMatch ) ; if ( count ( $ requirementCheck ) < count ( $ requiredKeys ) ) { $ missing = array_diff_key ( $ requiredMatch , $ definition ) ; throw new \ Exception ( "missing definition fields (" . implode ( ',' , array_keys ( $ missing ) ) . ")" ) ; } return $ definition ; }
Scan an addon definition file
2,026
protected function scanClasses ( $ dir , $ depth = 2 ) { if ( $ depth < 0 ) { return [ ] ; } $ paths = scandir ( $ dir ) ; $ classes = [ ] ; foreach ( $ paths as $ path ) { if ( in_array ( $ path , [ '.' , '..' ] ) ) { continue ; } $ full = paths ( $ dir , $ path ) ; if ( is_dir ( $ full ) ) { if ( $ depth > 0 ) { $ classes = array_merge ( $ classes , $ this -> scanClasses ( $ full , $ depth - 1 ) ) ; } } else { if ( fnmatch ( '*.php' , $ path ) ) { $ declarations = $ this -> scanFile ( $ full ) ; foreach ( $ declarations as $ namespaceRow ) { if ( isset ( $ namespaceRow [ 'namespace' ] ) && $ namespaceRow ) { $ namespace = rtrim ( $ namespaceRow [ 'namespace' ] , '\\' ) . '\\' ; $ namespaceClasses = $ namespaceRow [ 'classes' ] ; } else { $ namespace = '' ; $ namespaceClasses = $ namespaceRow ; } foreach ( $ namespaceClasses as $ classRow ) { $ className = $ namespace . $ classRow [ 'name' ] ; $ classes [ strtolower ( $ className ) ] = [ $ className , $ full ] ; if ( $ classRow [ 'type' ] == 'CLASS' ) { if ( preg_match ( '`^[\w\d]+Addon$`' , $ classRow [ 'name' ] ) ) { $ this -> special [ 'addon' ] = $ className ; } } } } } } } return $ classes ; }
Scan a directory for addon classes
2,027
public function autoload ( $ class ) { $ classKey = strtolower ( $ class ) ; if ( isset ( $ this -> classes [ $ classKey ] ) ) { list ( $ _ , $ path ) = $ this -> classes [ $ classKey ] ; include_once $ path ; } }
Autoload this addon s classes
2,028
public function getRequestHeaders ( ) { $ headers = parent :: getRequestHeaders ( ) ; if ( ! is_null ( $ this -> modifiedSince ) ) { $ headers [ 'If-Modified-Since' ] = $ this -> modifiedSince -> format ( 'r' ) ; } return $ headers ; }
Returns array of request headers .
2,029
public function setData ( $ data ) { $ this -> data = [ ] ; $ data = self :: normalizeArray ( $ data ) ; foreach ( $ data as $ offset => $ value ) $ this -> offsetSet ( $ offset , $ value ) ; return $ this ; }
Overwrite internal data array
2,030
public static function findPostsByFlag ( $ flag , $ post_type = PostTypes :: ANY ) { return Post :: findByExactMeta ( $ flag , Checkbox :: ON , $ post_type ) ; }
Finds one or more posts that have the given flag enabled
2,031
public function connect ( Array $ config ) { $ dsn = $ this -> getDSN ( $ config ) ; $ options = $ this -> getOptions ( $ config ) ; $ connection = $ this -> createConnection ( $ dsn , $ config , $ options ) ; if ( isset ( $ config [ 'charset' ] ) ) { $ connection -> prepare ( "set names '" . $ config [ 'charset' ] . "'" ) -> execute ( ) ; } if ( isset ( $ config [ 'timezone' ] ) ) { $ connection -> prepare ( "set time zone '" . $ config [ 'timezone' ] . "'" ) -> execute ( ) ; } return $ connection ; }
Create the actual connection .
2,032
protected function getDSN ( Array $ config ) { $ dsn = "pgsql:host={$config['host']};dbname={$config['dbname']}" ; if ( isset ( $ config [ 'port' ] ) ) { $ dsn .= ";port={$config['port']}" ; } if ( isset ( $ config [ 'sslmode' ] ) ) { $ dsn .= ";sslmode={$config['sslmode']}" ; } return $ dsn ; }
Return the base DSN for the connection .
2,033
public function attachmentUrlFilter ( $ key , $ filter = null ) { if ( empty ( $ key ) ) { return '' ; } try { $ url = $ this -> attachmentHandler -> getFileUrl ( $ key ) ; } catch ( AttachmentException $ e ) { return '' ; } if ( null === $ filter ) { return $ url ; } return $ this -> cacheManager -> getBrowserPath ( $ url , $ filter ) ; }
Fetch attachment url and pass through liip_imagine filter if the url is not null and filter name is given .
2,034
public function attachmentImageFilter ( $ key , $ filter , $ title = '' , $ altImageUrl = null ) { $ url = $ this -> attachmentUrlFilter ( $ key , $ filter ) ; if ( '' == $ url && null === $ altImageUrl ) { return '' ; } return '<img src="' . ( '' != $ url ? $ url : $ altImageUrl ) . '" title="' . htmlspecialchars ( $ title ) . '" />' ; }
Filters attachment url passes it through liip_imagine and provides a ready to use img tag that is marked as safe . If the url is empty no image tag will be generated . Use this if you want to quickly output attachment images and not care if the attachment was set or not .
2,035
public function CheckForSpam ( $ Type ) { $ Session = Gdn :: Session ( ) ; $ SpamCheckEnabled = GetValue ( 'SpamCheck' , $ this , TRUE ) ; if ( $ SpamCheckEnabled === FALSE || $ Session -> User -> Admin || $ Session -> CheckPermission ( 'Garden.Moderation.Manage' ) ) return FALSE ; $ Spam = FALSE ; if ( ! in_array ( $ Type , array ( 'Comment' , 'Discussion' ) ) ) trigger_error ( ErrorMessage ( sprintf ( 'Spam check type unknown: %s' , $ Type ) , 'VanillaModel' , 'CheckForSpam' ) , E_USER_ERROR ) ; $ CountSpamCheck = $ Session -> GetAttribute ( 'Count' . $ Type . 'SpamCheck' , 0 ) ; $ DateSpamCheck = $ Session -> GetAttribute ( 'Date' . $ Type . 'SpamCheck' , 0 ) ; $ SecondsSinceSpamCheck = time ( ) - Gdn_Format :: ToTimestamp ( $ DateSpamCheck ) ; $ SpamCount = Gdn :: Config ( 'Vanilla.' . $ Type . '.SpamCount' ) ; if ( ! is_numeric ( $ SpamCount ) || $ SpamCount < 2 ) $ SpamCount = 2 ; $ SpamTime = Gdn :: Config ( 'Vanilla.' . $ Type . '.SpamTime' ) ; if ( ! is_numeric ( $ SpamTime ) || $ SpamTime < 0 ) $ SpamTime = 30 ; $ SpamLock = Gdn :: Config ( 'Vanilla.' . $ Type . '.SpamLock' ) ; if ( ! is_numeric ( $ SpamLock ) || $ SpamLock < 30 ) $ SpamLock = 30 ; $ Attributes = array ( ) ; if ( $ SecondsSinceSpamCheck < $ SpamLock && $ CountSpamCheck >= $ SpamCount && $ DateSpamCheck !== FALSE ) { $ Spam = TRUE ; $ this -> Validation -> AddValidationResult ( 'Body' , sprintf ( T ( 'You have posted %1$s times within %2$s seconds. A spam block is now in effect on your account. You must wait at least %3$s seconds before attempting to post again.' ) , $ SpamCount , $ SpamTime , $ SpamLock ) ) ; $ Attributes [ 'Date' . $ Type . 'SpamCheck' ] = Gdn_Format :: ToDateTime ( ) ; } else { if ( $ SecondsSinceSpamCheck > $ SpamTime ) { $ Attributes [ 'Count' . $ Type . 'SpamCheck' ] = 1 ; $ Attributes [ 'Date' . $ Type . 'SpamCheck' ] = Gdn_Format :: ToDateTime ( ) ; } else { $ Attributes [ 'Count' . $ Type . 'SpamCheck' ] = $ CountSpamCheck + 1 ; } } $ UserModel = Gdn :: UserModel ( ) ; if ( $ Session -> UserID ) $ UserModel -> SaveAttribute ( $ Session -> UserID , $ Attributes ) ; return $ Spam ; }
Checks to see if the user is spamming . Returns TRUE if the user is spamming .
2,036
public function redirect ( $ path , $ query = [ ] , $ http_response_code = 302 ) { $ url = $ this -> create ( $ path , $ query , true , '&' ) ; header ( 'Location: ' . $ url , true , $ http_response_code ) ; die ( '' ) ; }
Does a clean redirect .
2,037
public function create ( $ path = '' , $ query = [ ] , $ absolute = false , $ separator = '&amp;' ) { if ( empty ( $ path ) ) $ path = $ this -> _fullpath ; $ parts = $ this -> parse ( $ path ) ; parse_str ( $ parts [ 'query' ] , $ parts [ 'query' ] ) ; $ parts [ 'query' ] = array_merge ( $ parts [ 'query' ] , $ query ) ; if ( empty ( $ parts [ 'scheme_divider' ] ) ) { $ nodes = explode ( '/' , trim ( $ parts [ 'path' ] , '/' ) ) ; $ lang = $ this -> _language_actual ; if ( in_array ( $ nodes [ 0 ] , $ this -> _language_possible ) ) { $ lang = array_shift ( $ nodes ) ; } if ( isset ( $ query [ 'language' ] ) && in_array ( $ query [ 'language' ] , $ this -> _language_possible ) ) { $ lang = $ query [ 'language' ] ; unset ( $ parts [ 'query' ] [ 'language' ] ) ; } if ( $ lang !== $ this -> _language_actual || $ this -> _language_possible [ 0 ] !== $ this -> _language_actual ) { array_unshift ( $ nodes , $ lang ) ; } $ parts [ 'path' ] = implode ( '/' , $ nodes ) ; if ( $ absolute ) { $ base = $ this -> parse ( $ this -> getBaseHref ( ) ) ; $ base [ 'path' ] = $ base [ 'path' ] . $ parts [ 'path' ] ; $ base [ 'query' ] = $ parts [ 'query' ] ; $ parts = $ base ; } } if ( count ( $ parts [ 'query' ] ) > 0 ) { $ parts [ 'query_divider' ] = '?' ; } $ parts [ 'query' ] = http_build_query ( $ parts [ 'query' ] , '' , $ separator ) ; return implode ( '' , $ parts ) ; }
Creates a URL for use with Morrow . It handles automatically languages in the URL .
2,038
public function getBasehref ( ) { $ script_name = dirname ( $ _SERVER [ 'SCRIPT_NAME' ] ) ; $ script_name = str_replace ( '\\' , '/' , $ script_name ) ; $ path = '/' . trim ( $ script_name , '/' ) . '/' ; if ( $ path == '//' ) $ path = '/' ; $ scheme = isset ( $ _SERVER [ 'HTTPS' ] ) || isset ( $ _SERVER [ 'HTTP_X_SSL_ACTIVE' ] ) || ( isset ( $ _SERVER [ 'SSL_PROTOCOL' ] ) && ! empty ( $ _SERVER [ 'SSL_PROTOCOL' ] ) ) ? 'https://' : 'http://' ; $ host = php_sapi_name ( ) === 'cli' ? gethostname ( ) : $ _SERVER [ 'HTTP_HOST' ] ; $ base_href = $ scheme . $ host . $ path ; return $ base_href ; }
To get the base href for the actual Morrow installation .
2,039
public function patch ( $ userId , $ dataSourceId , Fitness_DataSource $ postBody , $ optParams = array ( ) ) { $ params = array ( 'userId' => $ userId , 'dataSourceId' => $ dataSourceId , 'postBody' => $ postBody ) ; $ params = array_merge ( $ params , $ optParams ) ; return $ this -> call ( 'patch' , array ( $ params ) , "Fitness_DataSource" ) ; }
Updates a given data source . It is an error to modify the data source s data stream ID data type type stream name or device information apart from the device version . Changing these fields would require a new unique data stream ID and separate data source .
2,040
protected function addSelectsToQuery ( Builder $ query , array $ selects ) { if ( ! empty ( $ selects ) ) { $ query -> selectRaw ( 'max(' . implode ( ' + ' , $ selects ) . ') as relevance' , $ this -> searchBindings ) ; } }
Puts all the select clauses to the main query .
2,041
protected function filterQueryWithRelevance ( Builder $ query , array $ selects , $ relevance_count ) { $ comparator = $ this -> getDatabaseDriver ( ) != 'mysql' ? implode ( ' + ' , $ selects ) : 'relevance' ; $ relevance_count = number_format ( $ relevance_count , 2 , '.' , '' ) ; if ( $ this -> getDatabaseDriver ( ) == 'mysql' ) { $ bindings = [ ] ; } else { $ bindings = $ this -> searchBindings ; } $ query -> havingRaw ( "$comparator >= $relevance_count" , $ bindings ) ; $ query -> orderBy ( 'relevance' , 'desc' ) ; }
Adds the relevance filter to the query .
2,042
public function & __get ( $ property ) { $ value = null ; if ( ! empty ( $ property ) ) { $ call = "getter_" . $ property ; if ( method_exists ( $ this , $ call ) ) $ value = $ this -> { $ call } ( ) ; } return $ value ; }
Handler method for accessing virtual properties .
2,043
public function definition ( $ concrete = null , array $ args = [ ] ) { $ definition = new Definition ( $ this , $ concrete , $ args ) ; return $ definition ; }
Instantiate a new Definition
2,044
public function get ( $ abstract ) { if ( ! isset ( $ this -> definitions [ $ abstract ] ) ) { $ this -> definitions [ $ abstract ] = new Definition ( $ this ) ; } return $ this -> definitions [ $ abstract ] ; }
Return a bound definition if set or bind a new definition and return it .
2,045
public function bind ( $ abstract , $ concrete = null , array $ args = [ ] ) { if ( is_null ( $ concrete ) ) { $ concrete = $ abstract ; } if ( isset ( $ this -> definitions [ $ abstract ] ) ) { $ definition = $ this -> definitions [ $ abstract ] ; $ definition -> setClass ( $ concrete ) ; $ definition -> withArgs ( $ args ) ; } else { $ definition = new Definition ( $ this , $ concrete , $ args ) ; $ this -> definitions [ $ abstract ] = $ definition ; } return $ definition ; }
Bind a new definition or if it s already set set the concrete class of the bound definition .
2,046
public function readDirRecursive ( $ dir , $ pattern ) { $ sub_dirs = glob ( $ dir . '/*' , \ GLOB_ONLYDIR ) ; $ files = array ( ) ; if ( ! empty ( $ sub_dirs ) ) { foreach ( $ sub_dirs as $ sub_dir ) { $ files = array_merge ( $ files , $ this -> readDirRecursive ( $ sub_dir , $ pattern ) ) ; } } $ files = array_merge ( $ files , glob ( $ dir . '/' . $ pattern , \ GLOB_NOCHECK ) ) ; return $ files ; }
read the subdirectory recursive and catch all files with the given pattern
2,047
protected function getSession ( ServerRequestInterface $ request ) : SessionInterface { if ( $ this -> session === null ) { $ this -> session = $ request -> getAttribute ( SessionMiddleware :: SESSION_ATTRIBUTE ) ; if ( ! $ this -> session instanceof SessionInterface ) { throw MissingSessionContainerException :: create ( ) ; } } return $ this -> session ; }
Fetch session from request attributes
2,048
protected function parsevalue ( $ value ) { if ( ! is_array ( $ value ) && ! $ value instanceof \ ArrayAccess && ! is_object ( $ value ) ) { return false ; } return $ this -> rParseValue ( $ value ) ; }
Parse the value into a type map
2,049
protected function rParseValue ( $ parsableValue ) { $ ret = array ( ) ; foreach ( $ parsableValue as $ key => $ value ) { if ( is_array ( $ value ) || $ value instanceof \ ArrayAccess || is_object ( $ value ) ) { $ ret [ $ key ] = $ this -> rParseValue ( $ value ) ; continue ; } $ ret [ $ key ] = $ this -> normalizeType ( $ value ) ; } if ( empty ( $ ret ) ) { $ ret = $ this -> normalizeType ( $ parsableValue ) ; } return $ ret ; }
Recursive value type parser
2,050
protected function issetInObjectOrArray ( $ actValue , $ key ) { if ( is_object ( $ actValue ) && property_exists ( $ actValue , $ key ) ) { return $ actValue -> $ key ; } if ( isset ( $ actValue [ $ key ] ) ) { return $ actValue [ $ key ] ; } return false ; }
Test if key isset in either Object or Array
2,051
public static function generateUrl ( $ name , array $ tokens = [ ] ) { if ( $ name === null ) { return ; } if ( isset ( static :: $ routes [ $ name ] ) ) { $ route = static :: $ routes [ $ name ] ; } else { foreach ( static :: $ routes as $ r ) { if ( $ r -> name === $ name ) { $ route = $ r ; } } } if ( isset ( $ route ) ) { return $ route -> generateUrl ( $ tokens ) ; } else { throw new Exception ( "No route with name [{$name}]" ) ; } }
Returns compiled path for the route .
2,052
public static function root ( $ to = null ) { static :: $ routes [ 'root' ] = new Route ( 'root' , 'root' ) ; if ( $ to ) { static :: $ routes [ 'root' ] -> to ( $ to ) ; } return static :: $ routes [ 'root' ] ; }
Sets the root route .
2,053
public static function resources ( $ resource , $ controller ) { $ uri = strtolower ( Inflector :: controllerise ( $ resource ) ) ; static :: get ( "/{$uri}" ) -> to ( "{$controller}::index" ) ; static :: get ( "/{$uri}/:id" ) -> to ( "{$controller}::show" ) ; static :: get ( "/{$uri}/new" ) -> to ( "{$controller}::new" ) ; static :: post ( "/{$uri}/new" ) -> to ( "{$controller}::create" ) ; static :: get ( "/{$uri}/:id/edit" ) -> to ( "{$controller}::edit" ) ; static :: post ( "/{$uri}/:id/edit" ) -> to ( "{$controller}::save" ) ; static :: get ( "/{$uri}/:id/delete" ) -> to ( "{$controller}::delete" ) ; static :: post ( "/{$uri}/:id/delete" ) -> to ( "{$controller}::destroy" ) ; }
Shortcut for setting up the routes for a resource .
2,054
public static function route ( $ route , $ name = null ) { if ( $ route == '404' ) { return static :: $ routes [ '404' ] = new Route ( '404' , '404' ) ; } if ( $ name ) { return static :: $ routes [ $ name ] = new Route ( $ route , $ name ) ; } else { return static :: $ routes [ ] = new Route ( $ route ) ; } }
Adds a new route .
2,055
public static function process ( Request $ request ) { $ uri = "/" . trim ( $ request -> pathInfo ( ) , '/' ) ; if ( isset ( static :: $ routes [ 'root' ] ) and $ request -> pathInfo ( ) == '/' ) { return static :: setRoute ( static :: $ routes [ 'root' ] ) ; } foreach ( static :: $ routes as $ route ) { $ route -> route = str_replace ( array_keys ( static :: $ tokens ) , array_values ( static :: $ tokens ) , $ route -> route ) ; $ pattern = "#^{$route->route}" . '(?<extension>' . implode ( '|' , static :: $ extensions ) . ")?$#" ; if ( preg_match ( $ pattern , $ uri , $ params ) ) { unset ( $ params [ 0 ] ) ; $ route -> params = array_merge ( $ route -> params , $ params ) ; $ route -> destination = preg_replace ( $ pattern , $ route -> destination , $ uri ) ; $ route -> params = array_merge ( $ route -> defaults , $ route -> params ) ; if ( in_array ( strtolower ( $ request -> method ( ) ) , $ route -> method ) ) { return static :: setRoute ( $ route ) ; } } } if ( isset ( static :: $ routes [ '404' ] ) ) { return static :: set404 ( ) ; } else { throw new Exception ( "No routes found for '{$uri}'" ) ; } }
Routes the request to the controller .
2,056
public static function set404 ( ) { if ( ! isset ( static :: $ routes [ '404' ] ) ) { throw new Exception ( "There is no 404 route set." ) ; } $ match = preg_match ( "#(?<extension>" . implode ( '|' , static :: $ extensions ) . ")?$#" , Request :: $ requestUri , $ params ) ; if ( isset ( $ params [ 'extension' ] ) ) { static :: $ routes [ '404' ] -> params [ 'extension' ] = $ params [ 'extension' ] ; } return static :: setRoute ( static :: $ routes [ '404' ] ) ; }
Sets the route info to that of the 404 route .
2,057
public function format ( ) { switch ( $ this -> displayFormat ) { case self :: FORMAT_CANADA : if ( preg_match ( $ this -> displayFormat , $ this -> postalCode , $ matches ) && count ( $ matches ) === 3 ) { return strtoupper ( sprintf ( '%s %s' , $ matches [ 1 ] , $ matches [ 2 ] ) ) ; } return $ this -> postalCode ; break ; case self :: FORMAT_USA : return $ this -> postalCode ; break ; default : return $ this -> postalCode ; break ; } }
Get formatted phone number for display This assumes a flattened format like 12345 or S4P0H0
2,058
public function InsertRelation ( \ rstoetter \ libsqlphp \ cKEY_COLUMN_USAGE_Entry $ obj ) { if ( is_null ( $ obj -> m_TABLE_NAME ) ) { die ( "\n cKEY_COLUMN_USAGE_Entry mit is_null( m_TABLE_NAME ) " ) ; } $ obj_found = $ this -> SearchByKey ( $ obj -> m_TABLE_NAME ) ; if ( $ obj_found === false ) { $ obj_new = new cKeyColumnUsageTreeNode ( $ obj -> m_TABLE_NAME ) ; if ( ! is_null ( $ obj -> m_REFERENCED_TABLE_NAME ) ) { $ obj_new -> GetData ( ) -> AddReferredTableName ( $ obj -> m_REFERENCED_TABLE_NAME ) ; } $ this -> InsertNode ( $ obj_new ) ; } else { if ( ! is_null ( $ obj -> m_REFERENCED_TABLE_NAME ) ) { $ obj_found -> GetData ( ) -> AddReferredTableName ( $ obj -> m_REFERENCED_TABLE_NAME ) ; } } if ( ! is_null ( $ obj -> m_REFERENCED_TABLE_NAME ) ) { $ obj_ref = $ this -> SearchByKey ( $ obj -> m_REFERENCED_TABLE_NAME ) ; if ( $ obj_ref === false ) { $ obj_new = new cKeyColumnUsageTreeNode ( $ obj -> m_REFERENCED_TABLE_NAME ) ; $ this -> InsertNode ( $ obj_new ) ; } } }
Insert a new item into the tree
2,059
public static function getTypeError ( $ type ) { $ data = [ Type :: TEXT => static :: TEXT , Type :: INTEGER => static :: INTEGER , Type :: FLOAT => static :: FLOAT , Type :: BOOLEAN => static :: BOOLEAN , Type :: TIMESTAMP => static :: TIMESTAMP , Type :: DATETIME => static :: DATETIME , Type :: DATE => static :: DATE , Type :: TIME => static :: TIME , Type :: YEAR => static :: YEAR , Type :: IP => static :: IP , Type :: EMAIL => static :: EMAIL , Type :: URL => static :: URL , Type :: JSON => static :: JSON , Type :: OBJECT => static :: VALUE , Type :: ENTITY => static :: VALUE , ] ; return isset ( $ data [ $ type ] ) ? $ data [ $ type ] : static :: VALUE ; }
Return the correct error constant for a specified type .
2,060
protected function _errorhandler_file ( $ errstr , $ backtrace , $ errortype ) { $ body = '############################## ' . $ errortype . "\n" ; $ body .= 'Datum: ' . date ( "d.m.Y - H:i:s" ) . "\n" ; if ( isset ( $ _SERVER [ 'REQUEST_URI' ] ) ) { $ body .= 'URL: ' . $ _SERVER [ 'REQUEST_URI' ] . "\n" ; $ body .= 'IP: ' . $ _SERVER [ 'REMOTE_ADDR' ] . "\n" ; $ body .= 'User-Agent: ' . ( isset ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ? $ _SERVER [ 'HTTP_USER_AGENT' ] : '-' ) . "\n" ; } else { $ body .= 'CLI: ' . ( implode ( ' ' , $ _SERVER [ 'argv' ] ) ) . "\n" ; } $ body .= 'Meldung: ' . $ errstr . "\n" ; $ body .= 'Backtrace: ' . "\n\n" ; foreach ( $ backtrace as $ value ) { $ body .= ' File: ' . $ value [ 'file' ] . " (Line " . $ value [ 'line' ] . ")\n" ; $ body .= ' Function: ' . $ value [ 'class' ] . $ value [ 'type' ] . $ value [ 'function' ] . '()' . "\n\n" ; } $ body .= "\n" ; file_put_contents ( $ this -> _logfile , $ body , FILE_APPEND ) ; }
Writes an error to a logfile .
2,061
protected function _errorhandler_output ( $ errstr , $ backtrace , $ errortype ) { $ error = '<div class="dp_container">' ; $ error .= '<div class="skyline">' . $ errortype . '</div>' ; $ error .= '<h1 class="exception">' . htmlspecialchars ( $ errstr , ENT_QUOTES , 'UTF-8' ) . '</h1>' ; $ count = 0 ; foreach ( $ backtrace as $ key => $ value ) { if ( ! empty ( $ value [ 'file' ] ) && is_file ( $ value [ 'file' ] ) ) { $ id_file = '_errorhandler_file_' . $ this -> errorcounter . '_' . $ count ; $ id_args = 'errorhandler_args_' . $ this -> errorcounter . '_' . $ count ; $ show = ( $ count === 0 ) ? 'style="display: block;"' : '' ; if ( $ count > 0 ) { $ call = $ value [ 'class' ] . $ value [ 'type' ] . $ value [ 'function' ] . '()' ; $ error .= '<h2>' . $ call . '</h2>' ; } $ file = preg_replace ( '=[^/]+$=' , '<strong>$0</strong>' , $ value [ 'file' ] ) ; $ error .= '<h3>' . $ file . ' (Line ' . $ value [ 'line' ] . ')</h3>' ; $ error .= '<div class="file" id="' . $ id_file . '" ' . $ show . '>' . $ this -> _getContent ( $ value [ 'file' ] , $ value [ 'line' ] ) . '<div style="clear: both;"></div></div>' ; if ( count ( $ value [ 'args' ] ) > 0 and $ count > 0 ) { $ dump = htmlspecialchars ( print_r ( $ value [ 'args' ] , true ) ) ; $ error .= '<h3>Arguments (' . count ( $ value [ 'args' ] ) . ')</h3>' ; $ error .= '<div class="args" id="' . $ id_args . '">' . $ dump . '</div>' ; } $ count ++ ; } } $ error .= '</div>' ; if ( $ this -> errorcounter === 1 ) $ error .= $ this -> _debug_styles ( ) ; return $ error ; }
Outputs an error to the screen .
2,062
public function errorhandler ( $ exception ) { $ errstr = $ exception -> getMessage ( ) ; $ errcode = $ exception -> getCode ( ) ; $ backtrace = $ exception -> getTrace ( ) ; if ( $ errstr == $ this -> lasterror ) return ; $ this -> lasterror = $ errstr ; $ this -> errorcounter ++ ; if ( $ exception instanceof ErrorException ) array_shift ( $ backtrace ) ; $ bt [ 'file' ] = $ exception -> getFile ( ) ; $ bt [ 'line' ] = $ exception -> getLine ( ) ; array_unshift ( $ backtrace , $ bt ) ; $ backtrace_keys = [ 'file' => '' , 'line' => '' , 'class' => '' , 'object' => '' , 'type' => '' , 'function' => '' , 'args' => [ ] ] ; foreach ( $ backtrace as $ key => $ value ) { $ backtrace [ $ key ] = array_merge ( $ backtrace_keys , $ value ) ; } if ( $ exception instanceof ErrorException ) $ errordescription = $ this -> errortypes [ $ exception -> getSeverity ( ) ] ; elseif ( $ errcode == 0 ) $ errordescription = 'EXCEPTION' ; else $ errordescription = 'EXCEPTION (Code ' . $ errcode . ')' ; if ( ! is_int ( $ this -> config [ 'output' ] [ 'screen' ] ) ) { die ( __CLASS__ . ': debug.output.screen has to a valid PHP timestamp.' ) ; } if ( time ( ) < $ this -> config [ 'output' ] [ 'screen' ] ) { $ error = $ this -> _errorhandler_output ( $ errstr , $ backtrace , $ errordescription ) ; echo $ error ; } if ( ! is_int ( $ this -> config [ 'output' ] [ 'file' ] ) ) { die ( __CLASS__ . ': debug.output.file has to a valid PHP timestamp.' ) ; } if ( time ( ) < $ this -> config [ 'output' ] [ 'file' ] ) { $ this -> _errorhandler_file ( $ errstr , $ backtrace , $ errordescription ) ; } if ( $ this -> _event_object !== null ) { $ this -> _event_object -> trigger ( 'core.after_exception' , $ exception ) ; } }
This method is called when an exception occurs
2,063
protected function _getContent ( $ errfile_or_string , $ errline , $ file_or_string = 'file' ) { $ show_lines = 10 ; if ( $ file_or_string === 'file' ) $ file = highlight_file ( $ errfile_or_string , true ) ; else $ file = highlight_string ( $ errfile_or_string , true ) ; $ file = explode ( "<br />" , $ file ) ; foreach ( $ file as $ key => $ value ) { $ temp = strip_tags ( $ value ) ; if ( empty ( $ temp ) ) $ value = '&nbsp;' ; $ value = '<span>' . $ value . '</span>' ; if ( $ key == $ errline - 1 ) $ value = '<div class="lineerror">' . $ value . '</div>' ; $ value = '<li><code>' . $ value . '</code></li>' ; $ file [ $ key ] = $ value ; } if ( $ errline - $ show_lines < 0 ) $ linestart = 0 ; else $ linestart = $ errline - $ show_lines ; $ file = array_slice ( $ file , $ linestart , $ show_lines * 2 , true ) ; $ file = implode ( '' , $ file ) ; return '<ol start="' . ( $ linestart + 1 ) . '">' . $ file . '</ol>' ; }
Retrieves a code excerpt from a file .
2,064
protected function _dump ( $ args ) { $ backtrace = debug_backtrace ( ) ; $ backtrace = $ backtrace [ 1 ] ; if ( isset ( $ backtrace [ 'file' ] ) ) { $ file = file ( $ backtrace [ 'file' ] ) ; $ function = trim ( $ file [ $ backtrace [ 'line' ] - 1 ] ) ; } $ output = '' ; foreach ( $ args as $ arg ) { $ this -> errorcounter ++ ; $ output .= '<div class="dp_container">' ; $ output .= '<h1 class="dump">' . htmlspecialchars ( $ function ) . '</h1>' ; $ file = preg_replace ( '=[^/]+$=' , '<strong>$0</strong>' , $ backtrace [ 'file' ] ) ; $ output .= '<h3>' . $ file . ' (Line ' . $ backtrace [ 'line' ] . ')</h3>' ; $ output .= $ this -> _dump_php ( $ arg ) ; $ output .= '</div>' ; $ output .= $ this -> _debug_styles ( ) ; } if ( $ this -> config [ 'output' ] [ 'screen' ] == false ) return '' ; echo $ output ; }
Returns the HTML for dumped variables .
2,065
protected function _dump_php ( & $ var ) { $ scope = false ; $ prefix = 'unique' ; $ suffix = 'value' ; if ( $ scope ) $ vals = $ scope ; else $ vals = $ GLOBALS ; $ old = $ var ; $ var = $ new = $ prefix . rand ( ) . $ suffix ; $ vname = false ; foreach ( $ vals as $ key => $ val ) { if ( $ val === $ new ) $ vname = $ key ; } $ var = $ old ; $ output = '<div class="args">' ; $ output .= $ this -> _dump_php_recursive ( $ var , '$' . $ vname ) ; $ output .= "</div>" ; return $ output ; }
Returns the HTML for the args of dumped variables .
2,066
public function init ( array $ initVars ) { if ( filter_var ( $ initVars [ 'url' ] , FILTER_VALIDATE_URL ) ) { $ this -> handle = curl_init ( $ initVars [ 'url' ] ) ; if ( isset ( $ initVars [ 'headers' ] ) ) { $ this -> setOpt ( CURLOPT_HTTPHEADER , $ initVars [ 'headers' ] ) ; } switch ( $ initVars [ 'method' ] ) { case 'GET' : break ; case 'PUT' : $ this -> setOpt ( CURLOPT_CUSTOMREQUEST , 'PUT' ) ; $ this -> setOpt ( CURLOPT_POSTFIELDS , $ initVars [ 'data' ] ) ; break ; case 'POST' : $ this -> setOpt ( CURLOPT_CUSTOMREQUEST , 'POST' ) ; $ this -> setOpt ( CURLOPT_POSTFIELDS , $ initVars [ 'data' ] ) ; break ; default : break ; } return true ; } else { return false ; } }
Initalises the cURL handle and sets some defaults
2,067
public function __async_add ( ) { $ parent = dbQuery ( '\samson\cms\CMSMaterial' ) -> id ( $ _POST [ 'parent_id' ] ) -> first ( ) ; $ fields_array_temp = array ( ) ; $ fields_array = array ( ) ; foreach ( $ parent -> cmsnavs ( ) as $ structure ) { if ( $ structure -> type == 1 ) { $ fields_array_temp = array_merge ( $ fields_array_temp , $ structure -> fields ( ) ) ; } } foreach ( $ fields_array_temp as $ field ) { $ fields_array [ $ field -> id ] = $ field ; } unset ( $ fields_array_temp ) ; $ field_keys = array_keys ( $ fields_array ) ; $ child = null ; $ parent -> copy ( $ child , $ field_keys ) ; $ child -> Name = 'related material' ; $ child -> Url = $ _POST [ 'Url' ] ; $ child -> parent_id = $ parent -> id ; $ child -> type = 2 ; $ child -> remains = 0 ; $ child -> save ( ) ; return array ( 'status' => 1 ) ; }
Creating new related material
2,068
public function __async_table ( $ parentID ) { $ form = new Form ( $ parentID ) ; $ tab = new RelatedTabLocalized ( $ form ) ; $ content = $ tab -> getContent ( ) ; return array ( 'status' => 1 , 'table' => $ content ) ; }
Async updating related table
2,069
public function saveFieldHandler ( $ dbObject , $ param , $ value ) { if ( $ dbObject instanceof \ samson \ activerecord \ materialfield ) { $ material = dbQuery ( 'material' ) -> id ( $ dbObject -> MaterialID ) -> first ( ) ; if ( $ material -> type == 1 && $ material -> parent_id == 0 ) { $ children = dbQuery ( 'material' ) -> cond ( 'parent_id' , $ material -> id ) -> fields ( 'MaterialID' ) ; foreach ( $ children as $ child ) { if ( ! dbQuery ( 'materialfield' ) -> cond ( 'FieldID' , $ dbObject -> FieldID ) -> cond ( 'locale' , $ dbObject -> locale ) -> cond ( 'MaterialID' , $ child ) -> first ( $ childMaterialField ) ) { $ childMaterialField = new \ samson \ activerecord \ materialfield ( false ) ; $ childMaterialField -> MaterialID = $ child ; $ childMaterialField -> FieldID = $ dbObject -> FieldID ; $ childMaterialField -> locale = $ dbObject -> locale ; $ childMaterialField -> Active = 1 ; } $ childMaterialField -> Value = $ dbObject -> Value ; if ( isset ( $ dbObject -> numeric_value ) ) { $ childMaterialField -> numeric_value = $ dbObject -> numeric_value ; } $ childMaterialField -> save ( ) ; } } } if ( $ dbObject instanceof \ samson \ activerecord \ material && $ param == 'remains' ) { $ parent = null ; if ( dbQuery ( 'material' ) -> cond ( 'MaterialID' , $ dbObject -> parent_id ) -> first ( $ parent ) ) { $ parent -> remains = ( int ) $ parent -> remains - ( int ) $ value + ( int ) $ dbObject -> remains ; $ parent -> save ( ) ; } } }
External handler called on samson . cms . input . change event
2,070
public function write ( $ path , Iterator $ data , $ threshold = null , $ flags = 0 ) { $ asObject = $ this -> isAsObject ( $ data , $ flags ) ; $ pretty = $ flags & self :: FLAG_PRETTY_PRINT ; $ jsonFlags = $ pretty ? JSON_PRETTY_PRINT : 0 ; $ ord = isset ( $ threshold ) ? 1 : null ; $ file = $ this -> open ( $ path , $ asObject , $ pretty , $ ord ) ; while ( $ data -> valid ( ) ) { if ( $ pretty ) { $ file -> fwrite ( "\t" ) ; } if ( $ asObject ) { $ file -> fwrite ( '"' . $ data -> key ( ) . '": ' ) ; } $ file -> fwrite ( Json :: encode ( $ data -> current ( ) , $ jsonFlags ) ) ; $ data -> next ( ) ; $ hasNext = $ data -> valid ( ) ; $ shouldRollover = $ this -> shouldRollover ( $ file , $ threshold ) ; if ( ! $ shouldRollover && $ hasNext ) { $ file -> fwrite ( "," ) ; } if ( $ pretty ) { $ file -> fwrite ( "\n" ) ; } if ( $ shouldRollover && $ hasNext ) { $ ord += 1 ; $ file = $ this -> rollover ( $ file , $ asObject , $ path , $ pretty , $ ord ) ; } } $ this -> close ( $ file , $ asObject , $ pretty ) ; }
Writes data to a JSON file .
2,071
public function setAttributeNS ( $ namespaceURI , $ qualifiedName , $ value ) : void { if ( $ this -> ownerDocument && $ namespaceURI === XliffFile :: XLIFF_NS && $ this -> ownerDocument -> isDefaultNamespace ( XliffFile :: XLIFF_NS ) ) { \ call_user_func_array ( [ 'parent' , 'setAttribute' ] , \ array_slice ( \ func_get_args ( ) , 1 ) ) ; return ; } \ call_user_func_array ( [ 'parent' , 'setAttributeNS' ] , \ func_get_args ( ) ) ; }
Adds new attribute .
2,072
public function getAttributeNS ( $ namespaceURI , $ localName ) : ? string { if ( $ this -> ownerDocument && $ namespaceURI === XliffFile :: XLIFF_NS && $ this -> ownerDocument -> isDefaultNamespace ( XliffFile :: XLIFF_NS ) ) { return \ call_user_func_array ( [ 'parent' , 'getAttribute' ] , \ array_slice ( \ func_get_args ( ) , 1 ) ) ; } return \ call_user_func_array ( [ 'parent' , 'getAttributeNS' ] , \ func_get_args ( ) ) ; }
Returns value of attribute
2,073
public function format ( $ level , $ message , array $ context = array ( ) ) { if ( ! is_object ( $ message ) ) { return $ this -> formatter -> format ( '' , $ message , $ context ) ; } $ this -> _processed [ ] = $ message ; $ object_as_array = array ( ) ; $ object_as_array [ ' class_name' ] = get_class ( $ message ) ; $ object_vars = get_object_vars ( $ message ) ; foreach ( $ object_vars as $ key => $ value ) { if ( $ value === $ message || in_array ( $ value , $ this -> _processed , true ) ) { $ value = 'recursion - parent object [' . get_class ( $ value ) . ']' ; } $ object_as_array [ $ key ] = $ this -> format ( '' , $ value , $ context ) ; } $ reflection = new ReflectionClass ( $ message ) ; foreach ( $ reflection -> getProperties ( ) as $ property ) { if ( array_key_exists ( $ property -> getName ( ) , $ object_vars ) ) { continue ; } $ type = $ this -> getPropertyKey ( $ property ) ; if ( version_compare ( PHP_VERSION , '5.3.0' , '>=' ) ) { $ property -> setAccessible ( true ) ; } try { $ value = $ property -> getValue ( $ message ) ; } catch ( ReflectionException $ e ) { $ value = 'only PHP 5.3 can access private/protected properties' ; } if ( $ value === $ message || in_array ( $ value , $ this -> _processed , true ) ) { $ value = 'recursion - parent object [' . get_class ( $ value ) . ']' ; } $ object_as_array [ $ type ] = $ this -> formatObjectHandleArray ( $ value , $ context ) ; } return array ( $ object_as_array ) ; }
Format objects into JSON objects
2,074
protected function formatObjectHandleArray ( $ value , array $ context ) { if ( is_array ( $ value ) ) { $ objs = array ( ) ; foreach ( $ value as $ key => $ value2 ) { $ objs [ $ key ] = $ this -> format ( '' , $ value2 , $ context ) ; } return $ objs ; } else { return $ this -> format ( '' , $ value , $ context ) ; } }
Prosesses array values
2,075
protected function getPropertyKey ( ReflectionProperty $ property ) { $ static = $ property -> isStatic ( ) ? ' static' : '' ; if ( $ property -> isPublic ( ) ) { return 'public' . $ static . ' ' . $ property -> getName ( ) ; } if ( $ property -> isProtected ( ) ) { return 'protected' . $ static . ' ' . $ property -> getName ( ) ; } if ( $ property -> isPrivate ( ) ) { return 'private' . $ static . ' ' . $ property -> getName ( ) ; } }
Return description string of object property
2,076
public static function isOn ( $ exception = false ) { if ( isset ( $ _SESSION ) ) { return true ; } exception_if ( $ exception , SessionSurfaceIsOffException :: class ) ; return false ; }
Check if session is started .
2,077
protected static function load ( ) { if ( ! static :: isOn ( ) ) { return false ; } elseif ( ! array_has ( $ _SESSION , static :: $ register_name ) ) { $ _SESSION [ static :: $ register_name ] = [ ] ; } static :: $ register = $ _SESSION [ static :: $ register_name ] ; return true ; }
Load the session register .
2,078
public static function put ( $ name , $ object , $ lifetime = null ) { static :: isOn ( true ) ; if ( is_null ( $ lifetime ) ) { $ lifetime = config ( 'storage.session_lifetime' ) ; } if ( $ lifetime > 0 ) { $ lifetime = time ( ) + $ lifetime ; } $ item = [ 'name' => $ name , 'object' => $ object , 'lifetime' => $ lifetime ] ; static :: $ register [ $ name ] = $ item ; static :: save ( ) ; return true ; }
Set new session variable .
2,079
public static function prolong ( $ name , $ lifetime ) { $ item = static :: reach ( $ name ) ; if ( $ item [ 'lifetime' ] > 0 ) { $ item [ 'lifetime' ] += $ lifetime ; } elseif ( $ item [ 'lifetime' ] == 0 ) { $ item [ 'lifetime' ] = time ( ) + $ lifetime ; } static :: $ register [ $ name ] = $ item ; static :: save ( ) ; return true ; }
Prolong a session variable lang time .
2,080
public static function get ( $ name ) { static :: isOn ( true ) ; $ item = static :: reach ( $ name ) ; if ( ( $ item [ 'lifetime' ] < time ( ) && $ item [ 'lifetime' ] > 0 ) ) { static :: remove ( $ name ) ; exception ( SessionKeyNotFoundException :: class , $ name ) ; } else { return $ item [ 'object' ] ; } }
Get a seesion variable .
2,081
public static function exists ( $ name ) { static :: isOn ( true ) ; if ( ! isset ( static :: $ register [ $ name ] ) ) { return false ; } else { $ item = static :: $ register [ $ name ] ; return $ item [ 'lifetime' ] > time ( ) || $ item [ 'lifetime' ] == 0 ; } }
Check if a session variable is existe .
2,082
public static function remove ( $ name ) { exception_if ( ! static :: exists ( $ name ) , SessionKeyNotFoundException :: class , $ name ) ; static :: $ register [ $ name ] = null ; static :: save ( ) ; return true ; }
Forget and remove a session variable .
2,083
public static function token ( ) { $ name = config ( 'security.key1' ) ; $ token = '' ; if ( static :: exists ( $ name ) ) { $ token = static :: get ( $ name ) ; } else { $ token = Hash :: token ( ) ; static :: put ( $ name , $ token ) ; } return $ token ; }
Set and get the session token variable .
2,084
static function supprimer_argument_balise ( $ pos , $ p ) { if ( ! isset ( $ p -> param [ 0 ] ) ) { return null ; } if ( ! isset ( $ p -> param [ 0 ] [ $ pos ] ) ) { return null ; } if ( $ pos == 0 ) { array_shift ( $ p -> param [ 0 ] ) ; } else { $ debut = array_slice ( $ p -> param [ 0 ] , 0 , $ pos ) ; $ fin = array_slice ( $ p -> param [ 0 ] , $ pos + 1 ) ; $ p -> param [ 0 ] = array_merge ( $ debut , $ fin ) ; } return $ p ; }
Supprime un argument de balise
2,085
static function recuperer_et_supprimer_argument_balise ( $ pos , & $ p ) { $ arg = Pile :: recuperer_argument_balise ( $ pos , $ p ) ; $ p = Pile :: supprimer_argument_balise ( $ pos , $ p ) ; return $ arg ; }
Retourne un argument de balise et le supprime de la liste des arguments
2,086
static function ajouter_argument_balise ( $ element , $ p ) { if ( ! isset ( $ p -> param [ 0 ] [ 0 ] ) ) { if ( ! isset ( $ p -> param [ 0 ] ) ) { $ p -> param [ 0 ] = array ( ) ; } $ p -> param [ 0 ] [ 0 ] = '' ; } $ zero = array_shift ( $ p -> param [ 0 ] ) ; array_unshift ( $ p -> param [ 0 ] , $ element ) ; array_unshift ( $ p -> param [ 0 ] , $ zero ) ; return $ p ; }
Ajoute un argument de balise
2,087
public static function fromResponse ( Response $ httpResponse ) { $ content = json_decode ( $ httpResponse -> getBody ( ) -> getContents ( ) , true ) ; $ status = isset ( $ content [ 'status' ] ) ? $ content [ 'status' ] : '' ; if ( $ status == Status :: OK ) { $ htmlAttributes = isset ( $ content [ 'html_attributes' ] ) ? $ content [ 'html_attributes' ] : [ ] ; $ result = isset ( $ content [ 'result' ] ) ? $ content [ 'result' ] : [ ] ; $ result = PlaceDetailsResult :: fromArray ( $ result ) ; $ errorMessage = null ; } else { $ errorMessage = isset ( $ content [ 'error_message' ] ) ? $ content [ 'error_message' ] : null ; $ htmlAttributes = [ ] ; $ result = null ; } return new static ( $ httpResponse , $ status , $ result , $ htmlAttributes , $ errorMessage ) ; }
Create response from http response .
2,088
public function toAssocArray ( $ ident ) { $ nodes = ( func_num_args ( ) > 1 ) ? $ this -> toArray ( 1 ) : $ this -> toArray ( ) ; $ array = array ( ) ; foreach ( $ nodes as $ node ) { if ( array_key_exists ( $ ident , $ node ) ) { $ array [ ( is_object ( $ node [ $ ident ] ) ) ? $ node [ $ ident ] -> toString ( ) : $ node [ $ ident ] ] = $ node ; } else { throw new TeamSpeak3_Adapter_ServerQuery_Exception ( "invalid parameter" , 0x602 ) ; } } return $ array ; }
Returns a multi - dimensional assoc array containing the reply splitted in multiple rows and columns . The identifier specified by key will be used while indexing the array .
2,089
public function setData ( $ key , $ value ) { $ data = $ this -> findData ( $ key ) ; if ( ! isset ( $ data ) ) { $ data = $ this -> createData ( $ key ) ; } $ data -> setValue ( $ value ) ; }
Sets the value of an already existing data or creates a new one
2,090
public function removeData ( $ key ) { $ data = $ this -> findData ( $ key ) ; if ( isset ( $ data ) ) { $ this -> data -> removeElement ( $ data ) ; return true ; } return false ; }
Removes data if set previously
2,091
protected function findData ( $ key ) { $ criteria = Criteria :: create ( ) -> where ( Criteria :: expr ( ) -> eq ( 'key' , $ key ) ) ; $ result = $ this -> data -> matching ( $ criteria ) ; if ( is_array ( $ result ) ) { $ result = reset ( $ result ) ; return $ result ; } }
Finds a data entity
2,092
public function onDeleteNode ( NodeInterface $ node ) { $ textNode = $ this -> textNodeManager -> findTextNodeByNode ( $ node ) ; if ( null !== $ textNode ) { $ this -> textNodeManager -> remove ( $ textNode ) ; $ this -> textManager -> remove ( $ textNode -> getText ( ) ) ; } }
On delete node .
2,093
public function newCommit ( NewCommitEvent $ event ) { $ commit = $ event -> getCommit ( ) ; $ related = $ this -> matcher -> getRelatedIssues ( $ commit ) ; $ commit -> setIssuesRelated ( $ related ) ; $ this -> repository -> persist ( $ commit ) ; }
Fills the commit with related issues matched by CommitMatcher .
2,094
private function _setDefaultHeadersCompression ( ehough_shortstop_api_HttpRequest $ request ) { if ( $ this -> _isDebugEnabled ) { $ this -> _logger -> debug ( 'Determining if HTTP compression is available...' ) ; } $ header = $ this -> _httpContentDecoder -> getAcceptEncodingHeaderValue ( ) ; if ( $ header !== null ) { if ( $ this -> _isDebugEnabled ) { $ this -> _logger -> debug ( 'HTTP decompression is available.' ) ; } $ request -> setHeader ( ehough_shortstop_api_HttpRequest :: HTTP_HEADER_ACCEPT_ENCODING , $ header ) ; } else { if ( $ this -> _isDebugEnabled ) { $ this -> _logger -> debug ( 'HTTP decompression is NOT available.' ) ; } } }
Sets compression headers .
2,095
private function _setDefaultHeadersBasic ( ehough_shortstop_api_HttpRequest $ request ) { $ map = array ( ehough_shortstop_api_HttpRequest :: HTTP_HEADER_USER_AGENT => 'shortstop; https://github.com/ehough/shortstop' , ehough_shortstop_api_HttpRequest :: HTTP_HEADER_HTTP_VERSION => 'HTTP/1.0' , ) ; foreach ( $ map as $ headerName => $ headerValue ) { if ( ! $ request -> containsHeader ( $ headerName ) ) { $ request -> setHeader ( $ headerName , $ headerValue ) ; } } }
Sets things like user agent and HTTP version .
2,096
public function find ( $ key ) { return array_key_exists ( ( $ key = strtolower ( trim ( $ key ) ) ) , $ this -> Hashes ) ? $ this -> Hashes [ $ key ] : false ; }
Try to find value for a key .
2,097
public function index ( $ builder = null ) { $ models = $ this -> repository -> all ( [ ] , true ) ; return response ( ) -> json ( $ models , 200 ) ; }
List resources .
2,098
public function addOption ( $ value , $ display = null ) { if ( null === $ display ) $ display = $ value ; $ this -> _options [ ] = array ( $ value , $ display ) ; return $ this ; }
Adds an option to the field . Once added you cannot edit or delete the options .
2,099
public function loadFile ( $ path , $ fieldsTerminator = ',' , $ fieldsEncloser = '"' , $ linesTerminator = "\n" ) { debug_enforce_string ( $ path ) ; debug_enforce_string ( $ fieldsTerminator ) ; debug_enforce_string ( $ fieldsEncloser ) ; debug_enforce_string ( $ linesTerminator ) ; $ sql = $ this -> getSql ( ) ; $ db = $ this -> getDb ( ) ; $ path = $ db -> quote ( $ path , 'string' ) ; $ linesTerminator = $ db -> quote ( $ linesTerminator , 'string' ) ; $ fieldsEncloser = $ db -> quote ( $ fieldsEncloser , 'string' ) ; $ fieldsTerminator = $ db -> quote ( $ fieldsTerminator , 'string' ) ; $ db -> exec ( $ sql . "\n" . "INTO OUTFILE $path" . " FIELDS TERMINATED BY $fieldsTerminator" . " ENCLOSED BY $fieldsEncloser" . " LINES TERMINATED BY $linesTerminator" ) ; }
Load results as CSV - like file on database server .