idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
58,500
|
public static function validate ( $ argument , $ types = [ ] , $ throwException = true ) { $ valid = false ; foreach ( $ types as $ type ) { if ( strcasecmp ( gettype ( $ argument ) , $ type ) == 0 ) { $ valid = true ; break ; } } if ( ! $ valid && $ throwException ) { throw new \ InvalidArgumentException ( implode ( " or " , $ types ) . " required. " . gettype ( $ argument ) . " given." ) ; } return $ valid ; }
|
Validates argument .
|
58,501
|
public static function prioritize ( $ args = [ ] ) { $ value = null ; foreach ( $ args as $ arg ) { if ( ! empty ( $ arg ) ) { $ value = $ arg ; break ; } } return $ value ; }
|
Prioritize the first non empty element from array
|
58,502
|
public static function notNull ( $ argValue , $ argName = '' ) { $ valid = ( $ argValue !== null ) ; if ( ! $ valid ) { $ message = implode ( ' ' , array_filter ( [ 'Argument' , $ argName , 'must not be null' ] ) ) ; throw new \ InvalidArgumentException ( $ message ) ; } return $ valid ; }
|
Throws exception if argument is null
|
58,503
|
public function createService ( ServiceLocatorInterface $ serviceLocator ) { $ instanceManager = new InstanceManager ( $ serviceLocator ) ; $ di = new DIContainer ( null , $ instanceManager ) ; $ config = $ serviceLocator -> get ( 'Config' ) ; if ( isset ( $ config [ 'di' ] ) ) { $ di -> configure ( new DiConfig ( $ config [ 'di' ] ) ) ; } return $ di ; }
|
Create and return abstract factory seeded by dependency injector
|
58,504
|
public static function isUniqueIdValid ( $ uniqueId , $ class ) { if ( ! $ uniqueId ) { throw new InvalidArgumentException ( sprintf ( __ ( 'For the service provider [%s], the container unique ID cannot be empty.' , 'fulcrum' ) , $ class ) ) ; } if ( ! is_string ( $ uniqueId ) ) { throw new InvalidArgumentException ( sprintf ( __ ( 'For the service provider [%s], the container unique ID must be a string. %s given.' , 'fulcrum' ) , $ class , gettype ( $ uniqueId ) ) ) ; } return true ; }
|
Checks if the unique id is valid . Else it throws an error .
|
58,505
|
public static function isConcreteConfigValid ( $ uniqueId , array $ concreteConfig , array $ defaultStructure , $ class ) { foreach ( array_keys ( $ defaultStructure ) as $ key ) { if ( ! array_key_exists ( $ key , $ concreteConfig ) ) { throw new MissingRequiredParameterException ( sprintf ( __ ( "The required %s parameter is missing in the service provider's configuration for unique ID [%s]. [Class %s]" , 'fulcrum' ) , $ uniqueId , $ key , $ class ) ) ; } } ConfigValidator :: mustNotBeEmpty ( $ concreteConfig [ 'config' ] , sprintf ( __ ( 'The configuration source for unique ID [%s] cannot be empty. [Service Provider: %s]' , 'fulcrum' ) , $ uniqueId , $ class ) ) ; if ( is_string ( $ concreteConfig [ 'config' ] ) ) { return ConfigValidator :: mustBeLoadable ( $ concreteConfig [ 'config' ] ) ; } return ConfigValidator :: mustBeAnArray ( $ concreteConfig [ 'config' ] ) ; }
|
Checks if the parameters are valid .
|
58,506
|
public function getUploadPath ( $ name = null ) { if ( is_null ( $ name ) ) { return '' ; } else { if ( ! isset ( $ this -> cache [ $ name ] ) ) { $ this -> cache [ $ name ] = Yii :: $ app -> pathManager -> getPath ( $ this -> namespace ) ; } } return $ this -> cache [ $ name ] -> getFullPath ( $ name ) ; }
|
Get absolute final destination path
|
58,507
|
protected function _createRow ( $ input ) { foreach ( $ input as $ key => $ value ) { $ temp = str_replace ( '"' , '""' , $ value ) ; $ temp = preg_replace ( "=(\r\n|\r|\n)=" , "\n" , $ temp ) ; $ input [ $ key ] = $ this -> delimiter . $ temp . $ this -> delimiter ; } $ output = implode ( $ this -> separator , $ input ) . $ this -> linebreaks ; return $ output ; }
|
Create one row in the CSV file .
|
58,508
|
public function rules ( $ key = null , $ operation = null ) { $ ruleName = $ operation ? "{$operation}Rules" : 'defaultRules' ; $ ruleName = method_exists ( $ this , $ ruleName ) ? $ ruleName : 'defaultRules' ; $ rules = $ this -> { $ ruleName } ( ) ; if ( is_null ( $ key ) ) { return $ this -> rules ; } return is_array ( $ key ) ? array_only ( $ this -> rules , $ key ) : $ this -> rules [ $ key ] ; }
|
Return the rules for validation .
|
58,509
|
public function setRules ( $ rules = [ ] , $ operation = null ) { $ rulesProperty = $ operation ? $ operation . 'Rules' : 'rules' ; $ this -> { $ rulesProperty } = $ rules ; return $ this ; }
|
Set the rules .
|
58,510
|
public function render ( $ group = null ) { $ this -> config ( 'content.url' , Router :: url ( $ this -> config ( 'content.url' ) ) ) ; $ content = $ this -> formatTemplate ( 'content' , $ this -> config ( 'content' ) ) ; if ( $ group ) { $ this -> config ( array_shift ( $ this -> _config [ 'childConfig' ] ) ) ; $ menu = new MenuGroup ( [ $ this -> config ( ) ] , $ this -> _here ) ; $ content .= $ menu -> render ( $ group ) ; $ this -> _active = $ this -> _active || $ menu -> active ( ) ; } return $ content ; }
|
If the current menu item holds a submenu we recursively build again a new menu group .
|
58,511
|
public static function generate ( $ hashLength = self :: MAX_HASH_LENGTH , $ hashSeed = self :: All ) { if ( ! isset ( static :: $ _hashSeeds , static :: $ _hashSeeds [ $ hashSeed ] ) || ! is_array ( static :: $ _hashSeeds [ $ hashSeed ] ) ) { return md5 ( time ( ) . mt_rand ( ) . time ( ) ) ; } for ( $ _i = 0 , $ _hash = null , $ _size = count ( static :: $ _hashSeeds [ $ hashSeed ] ) - 1 ; $ _i < $ hashLength ; $ _i ++ ) { $ _hash .= static :: $ _hashSeeds [ $ hashSeed ] [ mt_rand ( 0 , $ _size ) ] ; } return $ _hash ; }
|
Generates a unique hash code
|
58,512
|
public static function hash ( $ hashTarget = null , $ hashType = self :: SHA1 , $ hashLength = self :: MAX_HASH_LENGTH , $ rawOutput = false ) { $ _value = ( null === $ hashTarget ) ? static :: generate ( $ hashLength ) : $ hashTarget ; switch ( $ hashType ) { case static :: MD5 : $ _hash = md5 ( $ _value , $ rawOutput ) ; break ; case static :: SHA1 : $ _hash = sha1 ( $ _value , $ rawOutput ) ; break ; case static :: CRC32 : $ _hash = crc32 ( $ _value ) ; break ; default : $ _hash = hash ( $ hashType , $ _value , $ rawOutput ) ; break ; } return $ _hash ; }
|
Generic hashing method . Will hash any string or generate a random hash and hash that!
|
58,513
|
public function compile ( GetResponseEvent $ event ) { if ( ! $ this -> debug ) { return ; } if ( HttpKernelInterface :: MASTER_REQUEST !== $ event -> getRequestType ( ) ) { return ; } $ this -> assetWatcher -> compile ( ) ; }
|
Run asset watcher
|
58,514
|
public static function create ( $ name , $ alias , $ url ) : self { $ self = new static ( ) ; $ self -> name = $ name ; $ self -> alias = $ alias ; $ self -> url = $ url ; $ self -> created_by = Yii :: $ app -> user -> identity -> id ; $ self -> updated_by = Yii :: $ app -> user -> identity -> id ; return $ self ; }
|
Create domain .
|
58,515
|
public function edit ( $ name , $ alias , $ url ) : void { $ this -> name = $ name ; $ this -> alias = $ alias ; $ this -> url = $ url ; $ this -> updated_by = Yii :: $ app -> user -> identity -> id ; }
|
Update domain .
|
58,516
|
protected function convertPositiveTo ( $ input ) { $ extraLen = strlen ( $ input ) - 5 ; if ( $ extraLen < 0 ) { return str_pad ( $ input , 4 , '0' , STR_PAD_LEFT ) ; } if ( $ extraLen < 26 ) { return chr ( static :: ORD_START + $ extraLen ) . $ input ; } $ extraLen -= 25 ; $ prefix = '' ; $ carets = '' ; do { $ carets .= '^' ; $ extraLen -- ; $ prefix = chr ( static :: ORD_START + $ extraLen % 26 ) . $ prefix ; $ extraLen = intval ( $ extraLen / 26 ) ; } while ( $ extraLen ) ; return "${carets}${prefix}${input}" ; }
|
Convert a positive value into its RFC2550 representation .
|
58,517
|
protected function convertNegativeTo ( $ input ) { $ res = $ this -> convertPositiveTo ( substr ( $ input , 1 ) ) ; $ res = strtr ( $ res , static :: POSITIVE_CHARS , static :: NEGATIVE_CHARS ) ; if ( strlen ( $ res ) < 5 ) { $ res = '/' . $ res ; } elseif ( $ res [ 0 ] !== '!' ) { $ res = '*' . $ res ; } return $ res ; }
|
Converts a negative value into its RFC2550 representation .
|
58,518
|
public function convertFromPositive ( $ input ) { $ matches = [ ] ; if ( ! preg_match ( ' /^0*(?<carets>\\^*)(?<alpha>[A-Z]*)(?<year>\d+)$/' , $ input , $ matches ) ) { return null ; } if ( $ matches [ 'alpha' ] === '' ) { return $ matches [ 'year' ] ; } if ( $ matches [ 'carets' ] === '' ) { $ expectedLength = ord ( $ matches [ 'alpha' ] ) - static :: ORD_START + 5 ; } else { $ len = strlen ( $ matches [ 'carets' ] ) ; $ expectedLength = 0 ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ expectedLength = $ expectedLength * 26 ; $ expectedLength += ord ( $ matches [ 'alpha' ] [ $ i ] ) - static :: ORD_START ; $ expectedLength ++ ; } $ expectedLength += 30 ; } return str_pad ( $ matches [ 'year' ] , $ expectedLength , '0' , STR_PAD_RIGHT ) ; }
|
Convert a positive representation .
|
58,519
|
public function convertFromNegative ( $ input ) { if ( strpos ( '/*' , $ input [ 0 ] ) !== false ) { $ input = substr ( $ input , 1 ) ; } $ input = strtr ( $ input , static :: NEGATIVE_CHARS , static :: POSITIVE_CHARS ) ; $ res = $ this -> convertFromPositive ( $ input ) ; if ( preg_match ( '/^0+$/' , $ res ) ) { return $ res ; } return '-' . $ res ; }
|
Convert a negative representation .
|
58,520
|
public static function setClassAttributes ( $ className , AttributeSet $ attributes ) { if ( self :: attributesSetFor ( $ className ) ) { throw new Exception \ RuntimeException ( srptinf ( "Attributes already set for class %s" , $ className ) ) ; } self :: $ classAttributes [ $ className ] = $ attributes ; }
|
Register attributes for a class . This must be done before creating an instance of Attributes for that class . Registration can be done only once .
|
58,521
|
public static function isClassAttribute ( $ className , $ attrName ) { if ( ! self :: attributesSetFor ( $ className ) ) { throw new Exception \ RuntimeException ( sprintf ( "Attributes not set for class %s" , $ className ) ) ; } return self :: $ classAttributes [ $ className ] -> exists ( $ attrName ) ; }
|
Check if an attribute is valid for a class .
|
58,522
|
public static function getAttributesFor ( $ className ) { if ( ! self :: attributesSetFor ( $ className ) ) { $ className :: getAttributeSet ( ) ; } return self :: $ classAttributes [ $ className ] ; }
|
Get the registered attributes for a class .
|
58,523
|
public function init ( $ parameters ) { if ( empty ( $ parameters [ "log_path" ] ) ) { throw new \ Exception ( "Log path is not specified!" ) ; } $ this -> log_path = $ parameters [ "log_path" ] ; if ( ! file_exists ( $ this -> log_path ) || ! is_writable ( $ this -> log_path ) ) { throw new \ Exception ( sprintf ( "The log path '%s' is not writable!" , $ this -> log_path ) ) ; } return true ; }
|
Initializes the debug profiler with parameters .
|
58,524
|
public function logMessageToFile ( $ message , $ file_name ) { $ file = $ this -> log_path . $ file_name ; if ( ( ! file_exists ( $ file ) && is_writable ( $ this -> log_path ) ) || is_writable ( $ file ) ) { return error_log ( $ message . "\r\n" , 3 , $ file ) ; } else { throw new \ Exception ( sprintf ( "The log file '%s' is not writable!" , $ file ) ) ; } }
|
Logs a message to a specified log file .
|
58,525
|
public function clearLogFile ( $ file_name ) { $ file = $ this -> log_path . $ file_name ; if ( ( ! file_exists ( $ file ) && is_writable ( $ this -> log_path ) ) || is_writable ( $ file ) ) { return @ unlink ( $ file ) ; } return false ; }
|
Clears the specified log file .
|
58,526
|
public function clearLogFiles ( ) { $ dir = $ this -> log_path ; $ files = scandir ( $ dir ) ; foreach ( $ files as $ file ) { if ( $ file == "." || $ file == ".." || is_dir ( $ dir . $ file ) ) { continue ; } $ pi = pathinfo ( $ dir . $ file ) ; if ( empty ( $ pi [ "extension" ] ) || strtolower ( $ pi [ "extension" ] ) != "log" ) { continue ; } if ( ! $ this -> clearLogFile ( $ file ) ) { return false ; } } return true ; }
|
Clears all log files .
|
58,527
|
private function mustHaveTheKeyInThe ( array $ data ) : void { $ mapping = $ this ; assert ( $ mapping instanceof ExposesDataKey ) ; if ( ! isset ( $ data [ $ mapping -> key ( ) ] ) ) { throw MissingTheKey :: inTheInput ( $ data , $ mapping , $ mapping -> key ( ) ) ; } }
|
Asserts that our key is present in the input array .
|
58,528
|
protected function getOptions ( Style $ style ) : array { $ options = [ ] ; $ options [ ] = $ style -> isBold ( ) ? 'bold' : null ; $ options [ ] = $ style -> isUnderscore ( ) ? 'underscore' : null ; return array_filter ( $ options ) ; }
|
Devuelve un array con opciones a partir de un estilo
|
58,529
|
public static function ruleRegex ( $ regex ) { $ args = func_get_args ( ) ; $ regex = join ( ':' , $ args ) ; if ( ! preg_match ( '/^([\/#~]).+\1[msugex]*$/' , $ regex ) ) { $ regex = '/' . stripslashes ( $ regex ) . '/' ; } return function ( $ input ) use ( $ regex ) { return preg_match ( $ regex , $ input ) ; } ; }
|
Check regex against input
|
58,530
|
public static function ruleRegexInverse ( $ regex ) { $ args = func_get_args ( ) ; $ regex = join ( ':' , $ args ) ; if ( ! preg_match ( '/^([\/#~]).+\1[msugex]*$/' , $ regex ) ) { $ regex = '/' . stripslashes ( $ regex ) . '/' ; } return function ( $ input ) use ( $ regex ) { return ! preg_match ( $ regex , $ input ) ; } ; }
|
Check regex against input and returns reveresed result
|
58,531
|
public static function ruleDate ( ) { return function ( $ input ) { $ date = null ; try { $ date = date_parse ( $ input ) ; if ( $ date [ 'warning_count' ] === 0 && $ date [ 'error_count' ] === 0 ) { return strlen ( $ date [ 'hour' ] ) === 0 ; } else { return false ; } } catch ( \ Exception $ e ) { return false ; } } ; }
|
Check whether input is a date string
|
58,532
|
public static function ruleDateTime ( ) { return function ( $ input ) { $ date = null ; try { $ date = date_parse ( $ input ) ; return $ date [ 'warning_count' ] === 0 && $ date [ 'error_count' ] === 0 ; } catch ( \ Exception $ e ) { return false ; } } ; }
|
Check whether input is a datetime
|
58,533
|
public function after ( ) { if ( $ this -> _handle_ajax == true ) { if ( $ this -> request -> is_ajax ( ) ) { $ return = array ( ) ; if ( RD :: has_messages ( ) == false ) { $ return [ 'status' ] = 'success' ; $ return [ 'response' ] = [ '' ] ; } else if ( RD :: get_current ( RD :: ERROR ) != null ) { $ return [ 'status' ] = 'error' ; $ return [ 'errors' ] = RD :: get_current ( RD :: ERROR ) ; } else if ( RD :: get_current ( array ( RD :: SUCCESS , RD :: INFO ) ) != null ) { $ return [ 'status' ] = 'success' ; $ return [ 'response' ] = RD :: get_current ( array ( RD :: SUCCESS , RD :: INFO , RD :: WARNING ) ) ; } else { $ return [ 'status' ] = 'success' ; $ return [ 'response' ] = RD :: get_current ( ) ; } $ this -> response -> headers ( 'Content-Type' , 'application/json' ) ; $ this -> response -> body ( json_encode ( $ return ) ) ; } else { if ( RD :: has_messages ( ) ) RD :: persist ( ) ; parent :: after ( ) ; } } else parent :: after ( ) ; }
|
Handle Request Data persistence or output based on the request type .
|
58,534
|
public function load ( $ source , Configuration $ config = null ) : Configuration { if ( null === $ config ) { $ config = new Configuration ( ) ; } $ loader = $ this -> getLoader ( $ source , $ config ) ; if ( ! $ loader -> supports ( $ source ) ) { throw new \ InvalidArgumentException ( 'Unsupported configuration.' ) ; } $ loader -> load ( $ source ) ; return $ config ; }
|
Load a configuration .
|
58,535
|
public function getConfigParam ( $ name ) { $ result = null ; $ config = $ this -> getConfiguration ( ) ; $ parts = explode ( '.' , $ name ) ; foreach ( $ parts as $ key ) { if ( isset ( $ config [ $ key ] ) ) { $ result = $ config = $ config [ $ key ] ; } else { $ result = null ; break ; } } return $ result ; }
|
Get configuration parameter
|
58,536
|
public function getComponentConfig ( $ componentName ) { $ result = null ; $ config = $ this -> getConfiguration ( ) ; if ( isset ( $ config [ self :: COMPONENT_CONFIG_BLOCK ] [ $ componentName ] ) ) { $ result = $ config [ self :: COMPONENT_CONFIG_BLOCK ] [ $ componentName ] ; } return $ result ; }
|
Get configuration for component by name
|
58,537
|
public function runController ( $ handler , array $ params = [ ] ) { return SystemHelpers :: call ( $ this -> prepareCallback ( $ handler ) , function ( $ paramName ) use ( $ params ) { if ( ( $ component = $ this -> getComponent ( $ paramName ) ) !== null ) { return $ component ; } if ( isset ( $ _GET [ $ paramName ] ) ) { return $ _GET [ $ paramName ] ; } if ( isset ( $ _POST [ $ paramName ] ) ) { return $ _POST [ $ paramName ] ; } if ( isset ( $ params [ $ paramName ] ) ) { return $ params [ $ paramName ] ; } } ) ; }
|
Run by handler name
|
58,538
|
protected function forceComponentLoading ( ) { $ config = $ this -> getConfiguration ( ) ; foreach ( $ config [ self :: COMPONENT_CONFIG_BLOCK ] as $ key => $ params ) { if ( isset ( $ params [ 'class' ] ) && isset ( $ params [ 'force' ] ) ) { $ component = $ this -> getComponent ( $ key ) ; if ( $ component instanceof Plugin ) { $ this -> attachPlugin ( $ key , $ component ) ; } } } return $ this ; }
|
Force component loading
|
58,539
|
public function getComponent ( $ name ) { if ( ! isset ( $ this -> componentCache [ $ name ] ) && ( $ this -> componentCache [ $ name ] = $ this -> createComponent ( $ name ) ) !== null ) { $ this -> componentCache [ $ name ] -> init ( ) ; } return $ this -> componentCache [ $ name ] ; }
|
Get component by name
|
58,540
|
public function attachPlugin ( $ name , Plugin $ plugin ) { $ plugin -> register ( $ this ) ; $ this -> plugins [ $ name ] = $ plugin ; return $ this ; }
|
Attach plugin to application
|
58,541
|
abstract function __construct ( $ result , $ buffered = true ) ;
|
Construct a new result - set .
|
58,542
|
private function convertArrayKeys ( array $ data , $ case ) { foreach ( $ data as $ property => $ value ) { $ originalProperty = $ property ; switch ( $ case ) { case StringCases :: STUDLY_CAPS : $ property = $ this -> toStudlyCaps ( $ property ) ; break ; case StringCases :: CAMEL_CASE : $ property = $ this -> toCamelCase ( $ property ) ; break ; case StringCases :: SNAKE_CASE : $ property = $ this -> toSplitCase ( $ property ) ; break ; case StringCases :: DASH_CASE : $ property = $ this -> toSplitCase ( $ property , "-" ) ; break ; default : if ( strlen ( $ case ) == 1 ) { $ property = $ this -> toSplitCase ( $ property , $ case ) ; } break ; } if ( $ property != $ originalProperty ) { unset ( $ data [ $ originalProperty ] ) ; $ data [ $ property ] = $ value ; } } return $ data ; }
|
convert the keys of an array
|
58,543
|
public function pageGeneratedIn ( $ langStringPageGeneratedIn = '%s' ) { $ str = str_replace ( '%s' , round ( $ this -> getmicrotime ( ) - $ this -> PageTimestamp , 4 ) , $ langStringPageGeneratedIn ) ; return $ str ; }
|
If called with Page Generated in %s seconds it returns Page Generated in x . xxxx seconds
|
58,544
|
public function handleRequest ( $ requestedUrl ) { $ controllersToScan = self :: $ config [ "scanneableControllers" ] ; $ request = HttpRequestBuilder :: buildFromRequestUrl ( $ requestedUrl ) ; if ( $ this -> getMode ( ) != self :: $ MODE_TESTING ) { Session :: start ( ) ; if ( ! is_null ( $ request -> getLang ( ) ) ) { Session :: set ( "lang" , $ request -> getLang ( ) ) ; } else { if ( is_null ( Session :: get ( "lang" ) ) && ! is_null ( self :: get ( "lang" , "default" ) ) ) { Session :: set ( "lang" , self :: get ( "lang" , "default" ) ) ; } } } $ enabledController = FALSE ; foreach ( $ controllersToScan as $ appName => $ controllerNamespace ) { $ class = $ controllerNamespace . $ request -> getControllerClass ( ) ; if ( $ this -> validClass ( $ class ) ) { $ enabledController = TRUE ; break ; } } if ( $ enabledController ) { $ controller = new $ class ( ) ; $ controller -> setName ( $ request -> getControllerName ( ) ) ; } else { $ class = self :: get ( "defaultController" ) ; $ request -> setAction ( self :: get ( "defaultMethod" ) ) ; $ controller = new $ class ( ) ; } if ( $ controller -> isSecure ( ) ) { if ( is_null ( Session :: get ( "user" ) ) ) { $ request = new HttpRequest ( "" ) ; $ request -> setAction ( self :: get ( "loginMethod" ) ) ; $ class = self :: get ( "loginController" ) ; $ controller = new $ class ( ) ; } else { if ( ! $ controller -> canAccess ( Session :: get ( "user" ) ) ) { $ request = new HttpRequest ( "" ) ; $ request -> setAction ( self :: get ( "restrictedMethod" ) ) ; $ request -> setControllerName ( "user" ) ; $ class = self :: get ( "defaultController" ) ; $ controller = new $ class ( ) ; } } } $ method = $ request -> getAction ( ) ; $ this -> dispatch ( $ controller , $ method , $ request ) ; }
|
Handle the requested url dispatching to routed controllers .
|
58,545
|
public function shutdown ( ) { if ( ( $ error = error_get_last ( ) ) ) { ob_clean ( ) ; $ msg = $ error [ "message" ] . " in file: " . $ error [ "file" ] . " on line: " . $ error [ "line" ] ; $ log = new Logger ( 'kernel' ) ; $ file = self :: get ( "dir" , "log" ) . "/log-" . date ( "Ymd" ) . ".log" ; $ log -> pushHandler ( new StreamHandler ( $ file , Logger :: ERROR ) ) ; switch ( $ this -> mode ) { case self :: $ MODE_PRODUCTION : $ log -> addError ( $ msg ) ; $ request = new HttpRequest ( ) ; $ class = self :: get ( "defaultController" ) ; $ method = self :: get ( "errorMethod" ) ; $ controller = new $ class ( ) ; $ this -> dispatch ( $ controller , $ method , $ request ) ; break ; case self :: $ MODE_DEVELOPMENT : die ( $ msg ) ; break ; default : echo $ msg ; break ; } } }
|
Function for show errors based on kernel mode .
|
58,546
|
public static function getRoute ( $ pattern ) { $ route = null ; if ( isset ( self :: $ routes [ $ pattern ] ) ) { $ route = self :: $ routes [ $ pattern ] ; } return $ route ; }
|
Get a route .
|
58,547
|
protected function createMemcachedDriver ( string $ name , Prop $ config ) { $ memcached = new \ Memcached ( $ config -> getOr ( "persistent_id" , null ) ) ; if ( $ config -> isArray ( "options" ) ) { $ memcached -> setOptions ( $ config -> get ( "options" ) ) ; } if ( $ config -> getIs ( "username" ) && method_exists ( $ memcached , "setSaslAuthData" ) ) { $ memcached -> setSaslAuthData ( $ config -> get ( "username" ) , $ config -> getOr ( "password" , "" ) ) ; } if ( $ config -> isArray ( "servers" ) ) { $ memcached -> addServers ( $ config -> get ( "servers" ) ) ; } else { $ memcached -> addServer ( $ config -> getOr ( "host" , "127.0.0.1" ) , $ config -> getOr ( "port" , 11211 ) , $ config -> getOr ( "weight" , 0 ) ) ; } return new MemcachedStore ( $ memcached , $ name , $ config -> getOr ( "prefix" , "" ) , $ config -> getOr ( "life" , 0 ) ) ; }
|
Create an instance of the Memcached cache driver
|
58,548
|
protected function createRedisDriver ( string $ name , Prop $ config ) { if ( ! class_exists ( "Predis\\Client" ) ) { throw new \ RuntimeException ( "Redis client library is not loaded" ) ; } $ parameters = $ config -> toArray ( ) ; $ options = $ config -> isArray ( "options" ) ? $ config -> get ( "options" ) : [ ] ; unset ( $ parameters [ "options" ] ) ; if ( ! isset ( $ options [ "timeout" ] ) ) { $ options [ "timeout" ] = 10 ; } if ( isset ( $ options [ "prefix" ] ) && strlen ( $ options [ "prefix" ] ) ) { $ options [ "prefix" ] = $ options [ "prefix" ] . ":" ; } $ options [ "exceptions" ] = true ; return new RedisStore ( new Client ( $ config -> toArray ( ) , $ options ) , $ name , $ config -> getOr ( "life" , 0 ) ) ; }
|
Create an instance of the Redis cache driver
|
58,549
|
protected function createDatabaseDriver ( string $ name , Prop $ config ) { return new DatabaseStore ( App :: Database ( ) -> getConnection ( $ config -> getOr ( "connection" , null ) ) , $ name , $ config -> getOr ( "table" , "cache" ) , $ config -> getOr ( "life" , 0 ) ) ; }
|
Create an instance of the database cache driver
|
58,550
|
protected function createApcDriver ( string $ name , Prop $ config ) { if ( ! function_exists ( "apcu_store" ) ) { throw new \ RuntimeException ( "APCu client library is not loaded" ) ; } $ cli = function_exists ( "php_sapi_name" ) && strpos ( php_sapi_name ( ) , "cli" ) !== false ; $ enable = in_array ( strtolower ( ini_get ( "apc.enable" . ( $ cli ? "_cli" : "d" ) ) ) , [ "on" , "1" ] ) ; if ( ! $ enable ) { throw new \ RuntimeException ( "APCu is not enabled, change php/apc ini configuration file" ) ; } return new ApcStore ( $ name , $ config -> getOr ( "prefix" , "" ) , $ config -> getOr ( "life" , 0 ) ) ; }
|
Create an instance of the APC cache driver
|
58,551
|
protected function createFileDriver ( string $ name , Prop $ config ) { return new FileStore ( Filesystem :: getInstance ( ) , $ name , $ config -> getOr ( "directory" , "cache" ) , $ config -> getOr ( "life" , 0 ) ) ; }
|
Create an instance of the file cache driver
|
58,552
|
public static function ListAll ( ) { $ data = [ ] ; $ folders = glob ( Application :: $ root . 'resources/translator/*' ) ; foreach ( $ folders as $ key => $ value ) { $ folder = \ Strings :: splite ( $ value , 'resources/translator/' ) ; $ folder = $ folder [ 1 ] ; $ data [ ] = '>' . $ folder ; foreach ( glob ( Application :: $ root . 'resources/translator/' . $ folder . '/*.php' ) as $ key2 => $ value2 ) { $ file = \ Strings :: splite ( $ value2 , "app/lang/$folder/" ) ; $ file = $ file [ 1 ] ; $ data [ ] = ' ' . $ file ; } } return $ data ; }
|
Listing all schemas .
|
58,553
|
public static function generator ( $ algo = 'crc32b' , $ length = 32 ) { $ host = Route :: HTTP_HOST ( ) ; $ timestamp = Date :: getTimestamp ( ) ; $ uniqid = uniqid ( bin2hex ( random_bytes ( $ length ) ) , true ) ; $ out = self :: get ( $ algo , $ host . $ timestamp . $ uniqid ) ; return $ out ; }
|
Random hash generator .
|
58,554
|
public function fromSub ( $ query , $ as ) { $ bindings = [ ] ; if ( $ query instanceof Closure ) { $ callback = $ query ; $ callback ( $ query = $ this -> newQuery ( ) ) ; } if ( $ query instanceof self ) { $ bindings = $ query -> getBindings ( ) ; $ query = $ query -> toSql ( ) ; } else if ( ! is_string ( $ query ) ) { throw new InvalidArgumentException ; } $ this -> from = new Expression ( '(' . $ query . ') as ' . $ this -> grammar -> wrap ( $ as ) ) ; $ this -> setBindings ( $ bindings , 'from' ) ; return $ this ; }
|
Add a select query for from expression to the query .
|
58,555
|
public function forPage ( $ page , $ perPage = 15 ) { if ( $ page < 1 ) { $ page = 1 ; } return $ this -> limit ( $ perPage , ( $ page - 1 ) * $ perPage ) ; }
|
Set the limit and offset for a given page .
|
58,556
|
public function updateOrInsert ( array $ attributes , array $ values = [ ] ) { if ( ! $ this -> where ( $ attributes ) -> exists ( ) ) { return $ this -> insert ( array_merge ( $ attributes , $ values ) ) ; } return ( bool ) $ this -> limit ( 1 ) -> update ( $ values ) ; }
|
Insert or update a record matching the attributes and fill it with values .
|
58,557
|
public static function set_cookie ( $ name , $ value , $ expiry = 90 , $ path = null , $ domain = null , $ secure = false , $ httpOnly = false ) { Deprecation :: notice ( '0.2' , 'This method is no longer required. Please use Cookie::set' ) ; Cookie :: set ( $ name , $ value , $ expiry , $ path , $ domain , $ secure , $ httpOnly ) ; }
|
Set cookie to use the same cookie domain as Session
|
58,558
|
public static function parse_record_fields ( $ content , $ data = [ ] , $ record = null , $ ignore = [ ] , $ html = true ) { $ content = new SSViewer_FromString ( $ content ) ; if ( ! $ record ) { $ record = ArrayData :: create ( $ data ) ; } else { $ record = clone $ record ; $ record = $ record -> customise ( $ data ) ; } if ( ! empty ( $ ignore ) ) { foreach ( $ ignore as $ i ) { $ record -> $ i = null ; } } if ( $ html ) { return DBField :: create_field ( 'HTMLText' , $ content -> process ( $ record ) ) -> forTemplate ( ) ; } else { return DBField :: create_field ( 'Text' , $ content -> process ( $ record ) ) -> forTemplate ( ) ; } }
|
Replace fields in content with record fields
|
58,559
|
public static function save_from_map ( DataObject $ record , $ relation , $ regField = '' , $ write = true ) { $ map = $ record -> toMap ( ) ; $ rel = $ record -> getComponent ( $ relation ) ; $ changed = false ; if ( ! $ regField ) { $ regField = $ relation ; } foreach ( $ map as $ field => $ val ) { if ( preg_match ( '/^' . preg_quote ( $ regField ) . '\[(\w+)\]$/' , $ field , $ match ) !== false ) { if ( count ( $ match ) == 2 && isset ( $ match [ 1 ] ) ) { $ rel -> setCastedField ( $ match [ 1 ] , $ val ) ; $ changed = true ; } } } if ( $ changed ) { if ( $ write ) { $ rel -> write ( ) ; } return true ; } return false ; }
|
than it should be )
|
58,560
|
public function getTransactor ( $ name ) { if ( ! array_key_exists ( $ name , $ this -> transactors ) ) { throw TransactorException :: transactorNotRegistered ( $ name ) ; } return $ this -> transactors [ $ name ] ; }
|
Gets a single transactor by name
|
58,561
|
protected function callSelector ( $ key ) { foreach ( $ this -> selectors as $ selector => $ callback ) { $ regex = '/' . $ selector . '/i' ; if ( preg_match ( $ regex , $ key , $ matches ) ) { return call_user_func_array ( $ callback , array ( $ this , $ key , $ matches ) ) ; } } throw new Exception \ Index ( 'Unknown index: ' . $ key ) ; }
|
Calls a selector or throws an exception if it doesn t know what it is .
|
58,562
|
public function spliceCallback ( Collection $ collection , $ key , array $ matches ) { $ start = $ matches [ 'start' ] ; $ end = $ matches [ 'end' ] ; if ( $ end == 'END' ) { $ end = count ( $ this -> contents ) - 1 ; } if ( $ start < 0 ) { $ start = ( count ( $ this -> contents ) ) - abs ( $ start ) ; } if ( $ start >= count ( $ this -> contents ) ) { throw new Exception \ Bounds ( 'Start index (' . $ start . ') is beyond the end of the file' , Exception \ Bounds :: ERROR_START_OUT_OF_RANGE ) ; } elseif ( $ start > $ end ) { throw new Exception \ Bounds ( 'Start index is greater than end index: ' . $ start . ' > ' . $ end , Exception \ Bounds :: ERROR_START_GT_END ) ; } if ( $ end >= count ( $ this -> contents ) ) { $ end = count ( $ this -> contents ) - 1 ; } $ offset = $ start ; $ length = ( $ end - $ start ) + 1 ; return array_slice ( $ this -> contents , $ offset , $ length ) ; }
|
Splices a collection given by a range . You can also use START and END as keywords .
|
58,563
|
public function pluckCallback ( Collection $ collection , $ key , array $ matches ) { $ indexes = explode ( ',' , $ key ) ; $ result = array ( ) ; foreach ( $ indexes as $ idx ) { $ idx = trim ( $ idx ) ; if ( $ idx != '' ) { if ( array_key_exists ( $ idx , $ this -> contents ) ) { $ result [ $ idx ] = $ this -> contents [ $ idx ] ; } } } return $ result ; }
|
Implements the plucking behaviour .
|
58,564
|
public function offsetGet ( $ offset ) { if ( is_int ( $ offset ) ) { return $ this -> contents [ $ offset ] ; } elseif ( $ offset == ':last' ) { return $ this -> contents [ count ( $ this -> contents ) - 1 ] ; } else { return $ this -> callSelector ( $ offset ) ; } }
|
This function is the gateway to the short syntax magic .
|
58,565
|
public function sortByMember ( $ member , $ direction = Collection :: SORT_ASC , $ flags = SORT_REGULAR ) { $ arr_to_sort = array ( ) ; foreach ( $ this -> contents as $ key => $ item ) { if ( is_array ( $ item ) ) { if ( ! array_key_exists ( $ member , $ item ) ) { throw new Exception \ Index ( 'Unknown Array Index "' . $ member . '" in item with key: "' . $ key . '"' ) ; } $ arr_to_sort [ $ key ] = $ item [ $ member ] ; } elseif ( is_object ( $ item ) ) { if ( isset ( $ item -> $ member ) && ! ( $ item -> $ member instanceof \ Closure ) ) { $ arr_to_sort [ $ key ] = $ item -> $ member ; } elseif ( method_exists ( $ item , $ member ) ) { $ arr_to_sort [ $ key ] = $ item -> $ member ( ) ; } elseif ( property_exists ( $ item , $ member ) && $ item -> $ member instanceof \ Closure ) { $ func = $ item -> $ member ; $ arr_to_sort [ $ key ] = $ func ( ) ; } else { throw new Exception \ Index ( 'Unknown Object Member/Method "' . $ member . '" in item with key: "' . $ key . '"' ) ; } } } switch ( $ direction ) { case self :: SORT_ASC : case self :: SORT_ASC_PRESERVE_KEYS : asort ( $ arr_to_sort , $ flags ) ; break ; case self :: SORT_DESC : case self :: SORT_DESC_PRESERVE_KEYS : arsort ( $ arr_to_sort , $ flags ) ; break ; default : throw new Exception \ Exception ( 'Unknown sort direction: ' . $ direction ) ; break ; } $ new_contents = array ( ) ; foreach ( $ arr_to_sort as $ key => $ not_used_sorted_value ) { switch ( $ direction ) { case self :: SORT_ASC_PRESERVE_KEYS : case self :: SORT_DESC_PRESERVE_KEYS : $ new_contents [ $ key ] = $ this -> contents [ $ key ] ; break ; default : $ new_contents [ ] = $ this -> contents [ $ key ] ; break ; } } $ this -> contents = $ new_contents ; return $ this ; }
|
Sorting by a member of the collection contents . Works on keyed arrays object members and the result of functions on an object .
|
58,566
|
public function cycleForward ( $ advance = 1 ) { for ( $ i = 0 ; $ i < $ advance ; $ i ++ ) { if ( $ this -> cyclePosition == $ this -> count ( ) - 1 ) { $ this -> cyclePosition = 0 ; } else { $ this -> cyclePosition ++ ; } } return $ this -> cycleValue ( ) ; }
|
Cycles the collection forward . What this means is that the Collection will move forward a given number of positions . If it reaches the end of the collection it will wrap back to the beginning .
|
58,567
|
public function hasManyThroughMany ( $ related , $ through , $ firstKey = null , $ secondKey = null , $ localKey = null , $ throughKey = null ) { $ through = new $ through ; $ firstKey = $ firstKey ? : $ this -> getForeignKey ( ) ; $ secondKey = $ secondKey ? : $ through -> getForeignKey ( ) ; $ localKey = $ localKey ? : $ this -> getKeyName ( ) ; return new HasManyThroughMany ( ( new $ related ) -> newQuery ( ) , $ this , $ through , $ firstKey , $ secondKey , $ localKey , $ throughKey ) ; }
|
get relationships through another table
|
58,568
|
public function computeDelta ( ) { if ( ! $ this -> hasDelta ( ) ) { return false ; } $ thisPeriod = $ this -> nthPreviousPeriod ( ) ; $ mostRecentPeriod = $ this -> nthPreviousPeriod ( 1 ) ; $ current = $ this -> computeValue ( $ thisPeriod ) ; $ previous = $ this -> computeValue ( $ mostRecentPeriod ) ; return $ current - $ previous ; }
|
Calculates the delta between the current value and the previous value .
|
58,569
|
public function values ( $ start = - 6 , $ end = 0 ) { $ start = ( int ) $ start ; $ end = ( int ) $ end ; if ( $ start < 0 ) { $ granularity = $ this -> granularity ( ) ; if ( $ granularity == STATISTIC_GRANULARITY_DAY ) { $ nPrevious = strtotime ( $ start . ' days' ) ; $ start = mktime ( 0 , 0 , 0 , date ( 'm' , $ nPrevious ) , date ( 'd' , $ nPrevious ) , date ( 'Y' , $ nPrevious ) ) ; } elseif ( $ granularity == STATISTIC_GRANULARITY_WEEK ) { $ nPrevious = strtotime ( $ start . ' weeks' ) ; $ start = mktime ( 0 , 0 , 0 , date ( 'm' , $ nPrevious ) , date ( 'd' , $ nPrevious ) , date ( 'Y' , $ nPrevious ) ) ; } elseif ( $ granularity == STATISTIC_GRANULARITY_MONTH ) { $ nPrevious = strtotime ( $ start . ' months' ) ; $ start = mktime ( 0 , 0 , 0 , date ( 'm' , $ nPrevious ) , 1 , date ( 'Y' , $ nPrevious ) ) ; } elseif ( $ granularity == STATISTIC_GRANULARITY_YEAR ) { $ nPrevious = strtotime ( $ start . ' years' ) ; $ start = mktime ( 0 , 0 , 0 , 1 , 1 , date ( 'Y' , $ nPrevious ) ) ; } } $ includePresent = $ end == 0 || $ end - time ( ) >= 0 ; if ( $ includePresent ) { $ end = time ( ) ; } $ values = $ this -> app [ 'db' ] -> select ( 'day,val' ) -> from ( 'Statistics' ) -> where ( [ 'metric' => $ this -> key ( ) , [ 'ts' , $ start , '>=' ] , [ 'ts' , $ end , '<=' ] , ] ) -> all ( ) ; if ( $ includePresent ) { $ values [ ] = [ 'day' => date ( 'Y-m-d' ) , 'val' => $ this -> computeValue ( ) , ] ; } return $ values ; }
|
Looks up all stored values between two timestamps . If more points are available than requested then the points will be summed up according to equally spaced intervals .
|
58,570
|
public function needsToBeCaptured ( ) { if ( ! $ this -> shouldBeCaptured ( ) ) { return false ; } $ mostRecentPeriod = $ this -> nthPreviousPeriod ( 1 ) ; $ latestStartDate = date ( 'Y-m-d' , $ mostRecentPeriod [ 'start' ] ) ; return Statistic :: totalRecords ( [ 'metric' => $ this -> key ( ) , 'day' => $ latestStartDate , ] ) == 0 ; }
|
Checks if the metric needs a value captured for the newest completed period .
|
58,571
|
public function savePeriod ( $ n = 1 ) { if ( ! $ this -> shouldBeCaptured ( ) || $ n < 1 ) { return false ; } $ period = $ this -> nthPreviousPeriod ( $ n ) ; $ value = $ this -> computeValue ( $ period ) ; $ d = date ( 'Y-m-d' , $ period [ 'start' ] ) ; $ stat = new Statistic ( [ $ this -> key ( ) , $ d ] ) ; if ( ! $ stat -> exists ( ) ) { $ stat = new Statistic ( ) ; return $ stat -> create ( [ 'metric' => $ this -> key ( ) , 'day' => $ d , 'val' => $ value , ] ) ; } else { return $ stat -> set ( 'val' , $ value ) ; } }
|
Saves the Nth previous period . Creates the statistic entry if it does not exist otherwise overwrites the previous value .
|
58,572
|
public function toArray ( ) { $ name = $ this -> name ( ) ; $ value = $ this -> computeValue ( ) ; $ delta = $ this -> computeDelta ( ) ; return [ 'name' => $ name , 'key' => $ this -> key ( ) , 'granularity' => $ this -> granularity ( ) , 'prefix' => $ this -> prefix ( ) , 'suffix' => $ this -> suffix ( ) , 'hasChart' => $ this -> hasChart ( ) , 'span' => $ this -> span ( ) , 'value' => $ value , 'abbreviated_value' => ( is_numeric ( $ value ) ) ? U :: number_abbreviate ( round ( $ value , 2 ) , 1 ) : $ value , 'delta' => $ delta , 'abbreviated_delta' => ( is_numeric ( $ delta ) ) ? U :: number_abbreviate ( round ( $ delta , 2 ) , 1 ) : $ delta , ] ; }
|
Bundles up some useful properties of the statistic for convenience .
|
58,573
|
public function nthPreviousPeriod ( $ n = 0 ) { $ n = max ( 0 , $ n ) ; $ interval = $ this -> interval ( $ this -> granularity ( ) ) ; $ start = $ this -> startOfDay ( strtotime ( 'this ' . $ interval ) ) ; $ i = $ n ; while ( $ i > 0 ) { $ start = $ this -> startOfDay ( strtotime ( '-1 ' . $ interval , $ start ) ) ; -- $ i ; } $ end = $ this -> endOfDay ( strtotime ( '+1 ' . $ interval , $ start ) - 1 ) ; return [ 'start' => $ start , 'end' => $ end , ] ; }
|
Returns the start and end timestamps for the nth - previous period since the current period . 0 will return the current period .
|
58,574
|
public function handle ( TableInterface $ table , Request $ request = null ) { foreach ( $ this -> extensions as $ extension ) { $ extension -> handle ( $ table , $ request ) ; } $ this -> type -> handle ( $ table , $ request ) ; }
|
Handle a request for a table
|
58,575
|
public function getuser ( ) { if ( empty ( $ this -> user ) ) { return NULL ; } bimport ( 'users.general' ) ; $ bu = BUsers :: getInstance ( ) ; $ user = $ bu -> itemGet ( $ this -> user ) ; return $ user ; }
|
Get user by social user .
|
58,576
|
public function getManyTranslations ( File $ file , QueryBuilder $ builder ) : LengthAwarePaginator { $ query = $ file -> translations ( ) -> newQuery ( ) -> getQuery ( ) ; $ builder -> applyFilters ( $ query ) ; $ builder -> applySorts ( $ query ) ; $ count = clone $ query -> getQuery ( ) ; $ results = $ query -> limit ( $ builder -> getPageSize ( ) ) -> offset ( $ builder -> getPageSize ( ) * ( $ builder -> getPage ( ) - 1 ) ) -> get ( [ 'file_translations.*' ] ) ; return new LengthAwarePaginator ( $ results , $ count -> select ( 'file_translations.id' ) -> get ( ) -> count ( ) , $ builder -> getPageSize ( ) , $ builder -> getPage ( ) ) ; }
|
Get all translations for specified file .
|
58,577
|
public static function createFromString ( $ string ) { if ( mb_strpos ( $ string , ':' ) !== false ) { list ( $ username , $ password ) = explode ( ':' , $ string , 2 ) ; } else { $ username = $ string ; $ password = $ password ; } return new self ( $ username , $ password ) ; }
|
Instanciate a new User object from a string
|
58,578
|
public function initResourceByPath ( $ path ) { $ parsed = parse_url ( $ path ) ; if ( $ parsed === false ) { return false ; } $ this -> currentPath = $ path ; if ( isset ( $ parsed [ 'host' ] ) ) { $ this -> containerName = $ parsed [ 'host' ] ; } if ( isset ( $ parsed [ 'path' ] ) ) { $ this -> resourceName = $ this -> cleanName ( $ parsed [ 'path' ] ) ; } return $ this ; }
|
Take the container and the resource name from the
|
58,579
|
public static function fromXml ( \ DOMElement $ xml ) { $ static = new static ( ) ; $ title = $ xml -> getElementsByTagName ( 'title' ) ; $ static -> title = StringLiteral :: fromXml ( $ title ) ; $ author = $ xml -> getElementsByTagName ( 'author' ) ; $ static -> author = StringLiteral :: fromXml ( $ author ) ; $ year = $ xml -> getElementsByTagName ( 'year' ) ; $ static -> year = StringLiteral :: fromXml ( $ year ) ; $ imprint = $ xml -> getElementsByTagName ( 'imprint' ) ; $ static -> imprint = StringLiteral :: fromXml ( $ imprint ) ; $ url = $ xml -> getElementsByTagName ( 'docUrl' ) ; $ static -> url = Path :: fromXml ( $ url ) ; $ isbnIssn = $ xml -> getElementsByTagName ( 'isbn_issn' ) ; $ static -> isbnIssn = StringLiteral :: fromXml ( $ isbnIssn ) ; $ docNumber = $ xml -> getElementsByTagName ( 'docNumber' ) ; $ static -> docNumber = StringLiteral :: fromXml ( $ docNumber ) ; $ itemId = $ xml -> getElementsByTagName ( 'itemId' ) ; $ static -> itemId = StringLiteral :: fromXml ( $ itemId ) ; return $ static ; }
|
Builds a LibraryItemMetadata object from XML .
|
58,580
|
protected function registerClientScript ( ) { $ view = $ this -> getView ( ) ; $ options = Json :: encode ( $ this -> jsOptions ) ; Asset :: register ( $ view ) ; $ view -> registerJs ( 'jQuery.communication(' . $ options . ');' ) ; }
|
Register widget client scripts .
|
58,581
|
function withServices ( array $ services ) { foreach ( $ services as $ method => $ type ) { $ this -> bind ( $ method , $ type ) ; } return $ this ; }
|
Bind many methods at once .
|
58,582
|
function withScoped ( array $ services ) { foreach ( $ services as $ method => $ type ) { $ this -> bind ( $ method , $ type , self :: SCOPED ) ; } return $ this ; }
|
Bind many scoped methods at once .
|
58,583
|
protected function getHeadLinkHelper ( ) { if ( $ this -> headLinkHelper ) { return $ this -> headLinkHelper ; } if ( method_exists ( $ this -> view , 'plugin' ) ) { $ this -> headLinkHelper = $ this -> view -> plugin ( 'headLink' ) ; } if ( ! $ this -> headLinkHelper instanceof HeadLink ) { $ this -> headLinkHelper = new HeadLink ( ) ; } return $ this -> headLinkHelper ; }
|
Retrieve the HeadLink helper
|
58,584
|
protected function getUrlHelper ( ) { if ( $ this -> urlHelper ) { return $ this -> urlHelper ; } if ( method_exists ( $ this -> view , 'plugin' ) ) { $ this -> urlHelper = $ this -> view -> plugin ( 'url' ) ; } if ( ! $ this -> urlHelper instanceof Url ) { $ this -> urlHelper = new Url ( ) ; } return $ this -> urlHelper ; }
|
Retrieve the Url helper
|
58,585
|
protected function getMessengerHelper ( ) { if ( $ this -> messengerHelper ) { return $ this -> messengerHelper ; } if ( method_exists ( $ this -> view , 'plugin' ) ) { $ this -> messengerHelper = $ this -> view -> plugin ( 'messenger' ) ; } if ( ! $ this -> messengerHelper instanceof Messenger ) { $ this -> messengerHelper = new Messenger ( ) ; } return $ this -> messengerHelper ; }
|
Retrieve the Messenger helper
|
58,586
|
protected function getTranslateHelper ( ) { if ( $ this -> translateHelper ) { return $ this -> translateHelper ; } if ( method_exists ( $ this -> view , 'plugin' ) ) { $ this -> translateHelper = $ this -> view -> plugin ( 'translate' ) ; } if ( ! $ this -> translateHelper instanceof Translate ) { $ this -> translateHelper = new Translate ( ) ; } return $ this -> translateHelper ; }
|
Retrieve the Translate helper
|
58,587
|
public function apply ( ) { if ( method_exists ( $ this -> view , 'plugin' ) ) { $ global = false ; $ roots = ( array ) $ this -> roots ; $ headLink = $ this -> getHeadLinkHelper ( ) ; if ( in_array ( null , $ roots ) ) { $ global = true ; } $ roots = array_filter ( $ roots ) ; if ( $ global ) { $ roots [ ] = null ; } $ find = array ( ) ; $ urls = array ( ) ; $ preview = false ; foreach ( $ roots as $ root ) { if ( $ this -> cssPreview -> hasPreviewById ( $ root ) ) { $ urls [ $ root ] = $ this -> cssPreview -> getPreviewById ( $ root ) ; } if ( empty ( $ urls [ $ root ] ) ) { $ find [ ] = $ root ; } else { $ preview = true ; } } if ( ! empty ( $ find ) ) { $ url = $ this -> getUrlHelper ( ) ; $ siteInfo = $ this -> getSiteInfo ( ) ; $ schema = $ siteInfo -> getSchema ( ) ; $ updated = $ this -> extraModel -> findUpdated ( $ find ) ; foreach ( $ find as $ root ) { if ( isset ( $ updated [ $ root ] ) ) { $ urls [ $ root ] = $ url ( 'Grid\Customize\Render\CustomCss' , array ( 'schema' => $ schema , 'id' => $ root ? ( int ) $ root : 'global' , 'hash' => $ updated [ $ root ] -> toHash ( ) , ) ) ; } } } foreach ( $ roots as $ root ) { if ( ! empty ( $ urls [ $ root ] ) ) { $ id = $ root ? ( int ) $ root : 'global' ; $ headLink -> prependStylesheet ( $ urls [ $ root ] , 'all' , false , array ( 'class' => 'customize-stylesheet' , 'data-customize' => $ id , ) ) ; } } if ( $ preview ) { if ( empty ( $ url ) ) { $ url = $ this -> getUrlHelper ( ) ; } $ translate = $ this -> getTranslateHelper ( ) ; $ this -> getMessengerHelper ( ) -> add ( sprintf ( $ translate ( 'customize.preview.applied.reset-link.%s' , 'customize' ) , $ url ( 'Grid\Customize\CssAdmin\ResetPreviews' , array ( 'locale' => \ Locale :: getDefault ( ) , ) ) ) , false , Message :: LEVEL_WARN ) ; } $ this -> roots = array ( ) ; } return $ this ; }
|
Apply custom css
|
58,588
|
public function get ( $ slug , $ parameters = [ ] ) { $ code = $ this -> request ( 'GET' , $ this -> url ( "{$this->general_config['api_version']}/$slug" ) , $ parameters ) ; return $ this -> response ( $ code ) ; }
|
Do a GET request to the Twitter API .
|
58,589
|
public function post ( $ slug , $ parameters = [ ] ) { $ code = $ this -> request ( 'POST' , $ this -> url ( "{$this->general_config['api_version']}/$slug" ) , $ parameters ) ; return $ this -> response ( $ code ) ; }
|
Do a POST request to the Twitter API .
|
58,590
|
public function request ( $ method , $ url , $ params = [ ] , $ useauth = true , $ multipart = false , $ headers = [ ] ) { foreach ( $ params as $ param => $ val ) { switch ( $ param ) { case 'user_id' : if ( ! is_numeric ( $ val ) ) { throw new \ Exception ( "user_id must be numeric $val" ) ; } break ; case 'count' : if ( isset ( $ this -> max_counts [ $ url ] ) && $ val > $ this -> max_counts ) { $ params [ $ param ] = $ this -> max_counts [ $ url ] ; } break ; default : break ; } } return parent :: request ( $ method , $ url , $ params , $ useauth , $ multipart , $ headers ) ; }
|
Owerwrite the parent s request function to clean up some parameters before sending .
|
58,591
|
public function getRequestToken ( $ oauth_callback = null ) { $ parameters = [ ] ; if ( ! empty ( $ oauth_callback ) ) { $ parameters [ 'oauth_callback' ] = $ oauth_callback ; } $ code = $ this -> request ( 'POST' , $ this -> url ( 'oauth/request_token' , '' ) , $ parameters ) ; if ( isset ( $ this -> response [ 'code' ] ) && $ this -> response [ 'code' ] == 200 && ! empty ( $ this -> response [ 'response' ] ) ) { $ get_parameters = $ this -> response [ 'response' ] ; $ token = [ ] ; parse_str ( $ get_parameters , $ token ) ; } if ( isset ( $ token [ 'oauth_token' ] , $ token [ 'oauth_token_secret' ] ) ) { return $ token ; } else { throw new \ Exception ( 'No request token found.' ) ; } }
|
Get a request_token from Twitter .
|
58,592
|
public function getAccessToken ( $ oauth_verifier = false ) { $ parameters = [ ] ; if ( ! empty ( $ oauth_verifier ) ) { $ parameters [ 'oauth_verifier' ] = $ oauth_verifier ; } $ code = $ this -> request ( 'POST' , $ this -> url ( 'oauth/access_token' , '' ) , $ parameters ) ; if ( isset ( $ this -> response [ 'code' ] ) && $ this -> response [ 'code' ] == 200 && ! empty ( $ this -> response [ 'response' ] ) ) { $ get_parameters = $ this -> response [ 'response' ] ; $ token = [ ] ; parse_str ( $ get_parameters , $ token ) ; $ this -> reconfigure ( [ 'token' => $ token [ 'oauth_token' ] , 'secret' => $ token [ 'oauth_token_secret' ] ] ) ; return $ token ; } throw new \ Exception ( 'No access token found.' ) ; }
|
Get an access token for a logged in user .
|
58,593
|
public function getAuthorizeUrl ( $ token , $ sign_in_with_twitter = true , $ force_login = false ) { if ( is_array ( $ token ) ) { $ token = $ token [ 'oauth_token' ] ; } if ( $ force_login ) { return "https://api.twitter.com/oauth/authenticate?oauth_token={$token}&force_login=true" ; } elseif ( empty ( $ sign_in_with_twitter ) ) { return "https://api.twitter.com/oauth/authorize?oauth_token={$token}" ; } else { return "https://api.twitter.com/oauth/authenticate?oauth_token={$token}" ; } }
|
Get the authorize URL .
|
58,594
|
public function block ( $ twitter_id , $ parameters = [ ] ) { if ( ! is_numeric ( $ twitter_id ) ) { return false ; } $ slug = 'blocks/create' ; $ default_parameters = [ 'user_id' => $ twitter_id , 'include_entities' => false , 'skip_status' => false , ] ; $ parameters = array_merge ( $ default_parameters , $ parameters ) ; return $ this -> post ( $ slug , $ parameters ) ; }
|
Block a given user .
|
58,595
|
public function search ( string $ query , array $ arguments = null ) { $ args = [ 'q' => $ query ] ; if ( is_array ( $ arguments ) ) { $ args = array_merge ( $ arguments , $ args ) ; } return new SearchIterator ( $ this , 'search/tweets' , $ args ) ; }
|
Get all results from tweets for the search API returns for the given query .
|
58,596
|
public function getUser ( string $ query , array $ extra_args = null ) { if ( is_numeric ( $ query ) ) { $ response = $ this -> getUserByID ( $ query , $ extra_args ) ; if ( ! isset ( $ response [ 'errors' ] ) ) { return $ response ; } } return $ this -> getUserByUsername ( $ query , $ extra_args ) ; }
|
Get info about a given user . Search can be performed based on ID screen name ...
|
58,597
|
private function response ( $ code ) { switch ( $ code ) { case 200 : case 304 : return $ this -> success ( ) ; case 403 : return $ this -> forbidden ( ) ; case 404 : return $ this -> requestDoesNotExist ( ) ; case 429 : return $ this -> rateLimit ( ) ; case 400 : default : return $ this -> generalError ( ) ; } }
|
Parse the response depending on the provided code
|
58,598
|
private function success ( ) { if ( ! isset ( $ this -> response [ 'response' ] ) or ! is_string ( $ this -> response [ 'response' ] ) ) { throw new \ Exception ( 'There is no response! PANIC!!' ) ; } $ json_output = $ this -> general_config [ 'json_decode' ] == 'array' ? true : false ; return json_decode ( $ this -> response [ 'response' ] , $ json_output ) ; }
|
Process a successful response and return the parsed output
|
58,599
|
private function rateLimit ( ) { return [ 'code' => $ this -> response [ 'code' ] , 'errors' => $ this -> response [ 'response' ] , 'tts' => isset ( $ this -> response [ 'headers' ] [ 'x-rate-limit-reset' ] ) ? ( $ this -> response [ 'headers' ] [ 'x-rate-limit-reset' ] - time ( ) ) : false , ] ; }
|
Return the error response when a rate limit has been reached on a given endpoint .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.