idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
7,300
function add ( $ other ) { if ( $ other instanceof self ) { $ this -> parts = array_merge ( $ this -> parts , $ other -> parts ) ; } else { $ this -> parts [ ] = $ other ; } }
Add another part to this range .
7,301
public function translate ( $ key , $ defaultValue = '' , $ locale = null ) { if ( $ locale === null ) { $ locale = $ this -> getlocale ( ) ; } if ( isset ( $ this -> translations [ $ locale ] [ $ key ] ) ) { return $ this -> translations [ $ locale ] [ $ key ] ; } return $ defaultValue ; }
Translate an identifier to specific value .
7,302
protected function readConfig ( ) { $ file = $ this -> path -> getConfigPath ( ) . '/translation.php' ; if ( file_exists ( $ file ) ) { $ config = require ( $ file ) ; if ( isset ( $ config [ 'translations' ] ) ) { $ this -> translations = $ config [ 'translations' ] ; } if ( isset ( $ config [ 'defaultLocale' ] ) ) { $ this -> setDefaultLocale ( $ config [ 'defaultLocale' ] ) ; } } return $ this ; }
Read configurations .
7,303
public function getQueueingCookie ( ) : ? QueueingFactory { if ( ! $ this -> hasQueueingCookie ( ) ) { $ this -> setQueueingCookie ( $ this -> getDefaultQueueingCookie ( ) ) ; } return $ this -> queueingCookie ; }
Get queueing cookie
7,304
private function buildRequestError ( PlugException $ e ) { $ data = $ e -> getResponse ( ) ? json_decode ( $ e -> getResponse ( ) -> getBody ( ) , true ) : [ 'error' => $ e -> getMessage ( ) ] ; $ message = isset ( $ data [ 'error' ] ) ? $ data [ 'error' ] : 'Server Error' ; $ status = $ e -> getResponse ( ) ? $ e -> getResponse ( ) -> getStatusCode ( ) : 500 ; return new CommunicationException ( sprintf ( '%s : %s' , $ status , $ message ) ) ; }
builds the error exception .
7,305
public function findNextEntry ( Entry $ entry ) { $ list = $ this -> findAfter ( $ entry , 1 ) ; if ( count ( $ list ) === 1 ) { return current ( $ list ) ; } return NULL ; }
Returns the element right after the given element
7,306
public function has ( $ class ) { if ( isset ( $ this -> singletons [ $ class ] ) ) { return true ; } if ( isset ( $ this -> aliases [ $ class ] ) ) { $ class = $ this -> aliases [ $ class ] ; } try { $ this -> getReflectionClass ( $ class ) ; } catch ( Exception $ e ) { return false ; } return true ; }
Check if the class is resolvable .
7,307
public function configMethod ( $ class , $ method , $ rules ) { foreach ( $ rules as $ param => $ rule ) { if ( ctype_upper ( $ param [ 0 ] ) && ( ! is_string ( $ rule ) && ! ( $ rule instanceof Closure ) ) ) { throw new InvalidRuleException ( "Type $param only allowed string or Closure as an extra rule." ) ; } } $ this -> rules [ $ class ] [ $ method ] = $ rules ; return $ this ; }
Configure method parameters of a class .
7,308
public function getMethod ( $ class , $ method , $ extraMappings = [ ] ) { if ( isset ( $ this -> aliases [ $ class ] ) ) { $ class = $ this -> aliases [ $ class ] ; } return [ $ this -> getSingleton ( $ class ) , $ this -> resolveArgs ( $ class , $ method , " when resolving method $class::$method" , $ extraMappings ) ] ; }
Resolve a method for method injection .
7,309
public function getNewInstance ( $ class ) { if ( isset ( $ this -> aliases [ $ class ] ) ) { $ class = $ this -> aliases [ $ class ] ; } $ args = $ this -> resolveArgs ( $ class , '__construct' , " when constructing $class" ) ; if ( $ args ) { $ instance = new $ class ( ... $ args ) ; } else { $ instance = new $ class ; } return $ instance ; }
Construct an new instance of a class with its dependencies .
7,310
protected function getSingleton ( $ class ) { if ( isset ( $ this -> singletons [ $ class ] ) ) { return $ this -> singletons [ $ class ] ; } $ instance = $ this -> getNewInstance ( $ class ) ; $ this -> singletons [ $ class ] = $ instance ; return $ instance ; }
Get singleton of a class .
7,311
protected function getFactory ( $ class ) { if ( isset ( $ this -> factories [ $ class ] ) ) { return $ this -> factories [ $ class ] ; } $ factory = new $ class ( $ this ) ; $ this -> factories [ $ class ] = $ factory ; return $ factory ; }
Construct a factory instance and inject this container to the instance .
7,312
protected function getReflectionClass ( $ className ) { if ( isset ( $ this -> reflectionClasses [ $ className ] ) ) { return $ this -> reflectionClasses [ $ className ] ; } try { $ reflectionClass = new ReflectionClass ( $ className ) ; } catch ( ReflectionException $ e ) { throw new NotFoundException ( "Class $className is not found" ) ; } if ( ! $ reflectionClass -> isInstantiable ( ) ) { throw new NotInstantiableException ( "$className is not an instantiable class" ) ; } $ this -> reflectionClasses [ $ className ] = $ reflectionClass ; return $ reflectionClass ; }
Create and cache a ReflectionClass .
7,313
protected function getReflectionMethod ( $ className , $ methodName = '__construct' ) { if ( isset ( $ this -> reflectionMethods [ $ className ] ) && array_key_exists ( $ methodName , $ this -> reflectionMethods [ $ className ] ) ) { return $ this -> reflectionMethods [ $ className ] [ $ methodName ] ; } try { $ reflectionClass = $ this -> getReflectionClass ( $ className ) ; if ( $ methodName === '__construct' ) { $ reflectionMethod = $ reflectionClass -> getConstructor ( ) ; } else { $ reflectionMethod = $ reflectionClass -> getMethod ( $ methodName ) ; } $ this -> reflectionMethods [ $ className ] [ $ methodName ] = $ reflectionMethod ; } catch ( ReflectionException $ e ) { throw new NotFoundException ( "Method $className::$methodName is not found" ) ; } return $ reflectionMethod ; }
Create and cache a ReflectionMethod .
7,314
protected function resolveArgs ( $ className , $ methodName , $ errorMessageSuffix = '' , $ extraMappings = [ ] ) { $ reflectionMethod = $ this -> getReflectionMethod ( $ className , $ methodName ) ; if ( is_null ( $ reflectionMethod ) && $ methodName === '__construct' ) { return [ ] ; } $ extraMappings = ( array ) $ extraMappings ; if ( isset ( $ this -> rules [ $ className ] [ $ methodName ] ) ) { $ extraMappings += $ this -> rules [ $ className ] [ $ methodName ] ; } $ args = [ ] ; try { foreach ( $ reflectionMethod -> getParameters ( ) as $ param ) { if ( $ extraMappings ) { $ paramName = $ param -> getName ( ) ; if ( array_key_exists ( $ paramName , $ extraMappings ) ) { $ args [ ] = $ extraMappings [ $ paramName ] ; continue ; } } $ paramType = $ param -> getType ( ) ; if ( $ paramType -> isBuiltin ( ) ) { throw new NotAllowedException ( "Parameter type \"$paramType\" is not allowed" . $ errorMessageSuffix ) ; } $ paramClassName = $ param -> getClass ( ) -> getName ( ) ; if ( array_key_exists ( $ paramClassName , $ extraMappings ) ) { if ( is_string ( $ extraMappings [ $ paramClassName ] ) ) { $ args [ ] = $ this -> get ( $ extraMappings [ $ paramClassName ] ) ; } else { $ args [ ] = $ extraMappings [ $ paramClassName ] ; } } else { $ args [ ] = $ this -> get ( $ paramClassName ) ; } } } catch ( ReflectionException $ e ) { throw new NotFoundException ( "Parameter class $paramType is not found" . $ errorMessageSuffix ) ; } return $ args ; }
Resolve parameters of ReflectionMethod .
7,315
public function setInput ( $ value ) { if ( stripos ( $ value , 'html>' ) === false ) { $ this -> input = '<!DOCTYPE html><html><head><meta charset="utf-8" /><title>Title</title></head><body>' . $ value . '</body></html>' ; } else { $ this -> input = $ value ; } }
Ensure that HTML fragments are submitted as complete webpages .
7,316
public function setStatusMessage ( $ message ) { $ message = ( string ) trim ( $ message ) ; if ( $ message === '' ) { $ this -> statusMessage = $ this -> getStatusMessage ( ) ; } else { $ this -> statusMessage = $ message ; } return $ this ; }
Sets the HTTP response message
7,317
public function setErrorMessage ( $ message ) { switch ( gettype ( $ message ) ) { case 'string' : $ this -> errorMessage = trim ( $ message ) ; break ; case 'array' : $ this -> errorMessage = empty ( $ message ) ? '' : $ message ; break ; default : $ this -> errorMessage = '' ; break ; } return $ this ; }
Sets the error message
7,318
protected function setResponseHeaders ( array $ headers ) { $ this -> headers = [ ] ; $ this -> headers [ ] = 'HTTP/1.1 ' . $ this -> getStatusCode ( ) . ' ' . $ this -> getStatusText ( ) ; $ this -> headers [ 'Content-Type' ] = 'application/json' ; foreach ( $ headers as $ key => $ value ) { $ this -> headers [ $ key ] = $ value ; } }
Sets the response headers
7,319
protected function getSuccessResponse ( $ data , $ statusText , $ headers = [ ] ) { return $ this -> setStatusText ( $ this -> statusTexts [ $ statusText ] ) -> setStatusCode ( $ statusText ) -> setStatusMessage ( self :: SUCCESS_TEXT ) -> respondWithSuccessMessage ( $ data , $ headers ) ; }
Gets the success response
7,320
protected function getErrorResponse ( $ msg , $ errorCode , $ statusText , $ headers = [ ] ) { return $ this -> setStatusText ( $ this -> statusTexts [ $ statusText ] ) -> setStatusCode ( $ statusText ) -> setStatusMessage ( self :: ERROR_TEXT ) -> setErrorCode ( $ errorCode ) -> setErrorMessage ( $ msg ) -> respondWithErrorMessage ( $ headers ) ; }
Gets the error response
7,321
protected function respond ( $ data , $ headers = [ ] ) { $ this -> setResponseHeaders ( $ headers ) ; return response ( ) -> json ( $ data , $ this -> getStatusCode ( ) , $ this -> getResponseHeaders ( ) ) ; }
Returns JSON Encoded HTTP Reponse
7,322
public static function bootAppliesScopes ( ) { if ( SurveyorProvider :: isActive ( ) ) { $ repository = SurveyorProvider :: retrieve ( ) ; foreach ( $ repository [ 'scopes' ] as $ model => $ scopes ) { foreach ( $ scopes as $ scope ) { if ( get_called_class ( ) == $ model ) { static :: addGlobalScope ( new $ scope ( ) ) ; } } } } else { if ( Auth :: user ( ) != null ) { throw RepositoryException :: notInitialized ( ) ; } } }
Apply model global scopes given the current logged user profiles .
7,323
public function registerAssets ( ) { $ dirs = array ( 'css' , 'js' ) ; foreach ( $ this -> assets as $ key => $ files ) { if ( in_array ( $ key , $ dirs ) ) { $ files = is_array ( $ files ) ? $ files : array ( $ files ) ; foreach ( $ files as $ file ) { $ filePath = Foundation :: getAssetsPath ( ) . DIRECTORY_SEPARATOR . $ key . DIRECTORY_SEPARATOR . $ file ; if ( file_exists ( $ filePath ) && is_file ( $ filePath ) ) { $ method = strcasecmp ( $ key , 'css' ) === 0 ? 'registerCssFile' : 'registerScriptFile' ; call_user_func ( array ( \ Yii :: app ( ) -> clientScript , "$method" ) , Foundation :: getAssetsUrl ( ) . "/$key/$file" ) ; } } } } }
Registers the assets . Makes sure the assets pre - existed on the published folder prior registration .
7,324
public static function display ( $ config = array ( ) ) { ob_start ( ) ; ob_implicit_flush ( false ) ; $ config [ 'class' ] = get_called_class ( ) ; $ widget = \ Yii :: createComponent ( $ config ) ; $ widget -> init ( ) ; $ widget -> run ( ) ; return ob_get_clean ( ) ; }
Ported from Yii2 widget s function . Creates a widget instance and runs it . We cannot use widget name as it conflicts with CBaseController component .
7,325
public function createService ( ServiceLocatorInterface $ serviceLocator ) { $ pdfRenderer = $ serviceLocator -> get ( PdfRenderer :: class ) ; $ pdfStrategy = new PdfStrategy ( $ pdfRenderer ) ; return $ pdfStrategy ; }
Create and return the PDF view strategy
7,326
public function getArrayResponse ( ) { $ json = [ ] ; $ json [ 'jsonrpc' ] = '2.0' ; if ( $ this -> errorCode ) { $ json [ 'error' ] = [ ] ; $ json [ 'error' ] [ 'code' ] = $ this -> errorCode ; $ json [ 'error' ] [ 'message' ] = $ this -> errorMessage ; if ( ! empty ( $ this -> errorData ) ) { $ json [ 'error' ] [ 'data' ] = $ this -> errorData ; } } else { $ json [ 'result' ] = $ this -> result ; } $ json [ 'id' ] = ! empty ( $ this -> id ) ? $ this -> id : null ; return $ json ; }
Return array response .
7,327
public function addColumn ( $ column , $ options ) { if ( is_string ( $ options ) ) { $ options = [ 'type' => $ options ] ; } $ options = $ options + [ 'field' => $ column , 'type' => '' , 'length' => '' , 'default' => '' , 'comment' => '' , 'charset' => '' , 'collate' => '' , 'null' => true , 'ai' => false , 'index' => false , 'primary' => false , 'unique' => false , 'foreign' => false ] ; if ( $ options [ 'primary' ] || $ options [ 'ai' ] ) { $ options [ 'null' ] = false ; } $ this -> _columns [ $ column ] = array_filter ( $ options , function ( $ value ) { return ( $ value !== '' && $ value !== false ) ; } ) ; if ( $ options [ 'primary' ] ) { $ this -> addPrimary ( $ column , $ options [ 'primary' ] ) ; } else if ( $ options [ 'unique' ] ) { $ this -> addUnique ( $ column , $ options [ 'unique' ] ) ; } else if ( $ options [ 'foreign' ] ) { $ this -> addForeign ( $ column , $ options [ 'foreign' ] ) ; } if ( $ options [ 'index' ] ) { $ this -> addIndex ( $ column , $ options [ 'index' ] ) ; } return $ this ; }
Add a column to the table schema .
7,328
public function addColumns ( array $ columns ) { foreach ( $ columns as $ column => $ options ) { $ this -> addColumn ( $ column , $ options ) ; } return $ this ; }
Add multiple columns . Index is the column name the value is the array of options .
7,329
public function addForeign ( $ column , $ options = [ ] ) { if ( is_string ( $ options ) ) { $ options = [ 'references' => $ options ] ; } if ( empty ( $ options [ 'references' ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Foreign key for %s must reference an external table' , $ column ) ) ; } $ this -> _foreignKeys [ $ column ] = $ options + [ 'column' => $ column , 'constraint' => '' ] ; }
Add a foreign key for a column . Multiple foreign keys can exist so group by column .
7,330
public function addPrimary ( $ column , $ options = false ) { $ symbol = is_string ( $ options ) ? $ options : '' ; if ( empty ( $ this -> _primaryKey ) ) { $ this -> _primaryKey = [ 'constraint' => $ symbol , 'columns' => [ $ column ] ] ; } else { $ this -> _primaryKey [ 'columns' ] [ ] = $ column ; } return $ this ; }
Add a primary key for a column . Only one primary key can exist . However multiple columns can exist in a primary key .
7,331
public function addUnique ( $ column , $ options = [ ] ) { $ symbol = '' ; $ index = $ column ; if ( is_array ( $ options ) ) { if ( isset ( $ options [ 'constraint' ] ) ) { $ symbol = $ options [ 'constraint' ] ; } if ( isset ( $ options [ 'index' ] ) ) { $ index = $ options [ 'index' ] ; } } else if ( is_string ( $ options ) ) { $ index = $ options ; } if ( empty ( $ this -> _uniqueKeys [ $ index ] ) ) { $ this -> _uniqueKeys [ $ index ] = [ 'index' => $ index , 'constraint' => $ symbol , 'columns' => [ $ column ] ] ; } else { $ this -> _uniqueKeys [ $ index ] [ 'columns' ] [ ] = $ column ; } }
Add a unique key for a column . Multiple unique keys can exist so group by index .
7,332
public function getColumn ( $ name ) { if ( $ this -> hasColumn ( $ name ) ) { return $ this -> _columns [ $ name ] ; } throw new MissingColumnException ( sprintf ( 'Repository column %s does not exist' , $ name ) ) ; }
Return column options by name .
7,333
public function getModel ( $ sModel ) { $ namespacedClass = $ this [ 'database.models_namespace' ] . '\\' . $ sModel ; if ( ! isset ( static :: $ models [ $ sModel ] ) ) { static :: $ models [ $ sModel ] = new $ namespacedClass ( $ this ) ; } return static :: $ models [ $ sModel ] ; }
Return the instance of specified model .
7,334
public function parse ( $ fm , array $ default = [ ] ) { $ pieces = [ ] ; $ parsed = [ ] ; $ regexp = '/^-{3}(?:\n|\r)(.+?)-{3}(.*)$/ms' ; if ( preg_match ( $ regexp , $ fm , $ pieces ) && $ yaml = $ pieces [ 1 ] ) { $ parsed = $ this -> yaml -> parse ( $ yaml , true ) ; if ( is_array ( $ parsed ) ) { $ parsed [ 'content' ] = trim ( $ pieces [ 2 ] ) ; return $ this -> fillDefault ( $ parsed , $ default ) ; } } throw new Exceptions \ FrontMatterHeaderNotFoundException ( 'Parser failed to find a proper Front Matter header' ) ; }
Parse a front matter file and return an array with its content
7,335
protected function fillDefault ( array $ parsed , array $ default = [ ] ) { foreach ( $ default as $ key => $ value ) { if ( ! isset ( $ parsed [ $ key ] ) ) { $ parsed [ $ key ] = $ value ; } } return $ parsed ; }
Add default value to key that are not defined in the front matter
7,336
public function setEntry ( Entry $ entry ) { $ entry -> setScriptEvents ( true ) -> checkId ( ) ; $ this -> entry = $ entry ; return $ this ; }
Set the Entry
7,337
protected function getEntrySubmitScriptText ( ) { $ url = $ this -> buildCompatibleUrl ( ) ; $ entryName = $ this -> entry -> getName ( ) ; $ link = Builder :: escapeText ( $ url . $ entryName . "=" ) ; return "declare Value = TextLib::URLEncode(Entry.Value);OpenLink({$link}^Value, CMlScript::LinkType::Goto);" ; }
Get the entry submit event script text
7,338
protected function buildCompatibleUrl ( ) { $ url = $ this -> url ; $ parametersIndex = stripos ( $ url , "?" ) ; if ( ! is_int ( $ parametersIndex ) || $ parametersIndex < 0 ) { $ url .= "?" ; } else { $ url .= "&" ; } return $ url ; }
Build the submit url compatible for the entry parameter
7,339
private function matchesHash ( $ hash , \ DateTime $ date ) { $ ordinals = array ( '1' => 'first' , '2' => 'second' , '3' => 'third' , '4' => 'fourth' , '5' => 'fifth' ) ; $ hashParts = explode ( '#' , $ hash ) ; if ( $ hashParts [ 0 ] != $ this -> getFieldValueFromDate ( $ date ) ) { return false ; } return $ this -> matchesRelativeDate ( $ date , $ ordinals [ $ hashParts [ 1 ] ] ) ; }
Checks if the hash value matches the given date .
7,340
public function bindColumn ( $ column , & $ param , $ type = null ) { if ( $ type === null ) : $ this -> _statement -> bindColumn ( $ column , $ param ) ; else : $ this -> _statement -> bindColumn ( $ column , $ param , $ type ) ; endif ; }
Bind a value of the column or field table
7,341
public function bindParam ( $ column , & $ param , $ type = null ) { if ( $ type === null ) : $ this -> _statement -> bindParam ( $ column , $ param ) ; else : $ this -> _statement -> bindParam ( $ column , $ param , $ type ) ; endif ; }
Bind a value of the param SQL
7,342
public function pgettext ( $ context , $ message ) { if ( $ this -> reader === null ) { return $ message ; } return $ this -> reader -> pgettext ( ( string ) $ context , ( string ) $ message ) ; }
gettext with contect .
7,343
public function npgettext ( $ context , $ singular , $ plural , $ count ) { if ( $ this -> reader === null ) { return $ count > 1 ? $ plural : $ singular ; } return $ this -> reader -> npgettext ( ( string ) $ context , ( string ) $ singular , ( string ) $ plural , $ count ) ; }
Plural version of gettext with context .
7,344
public function addBaseUrlScript ( ) { $ arrJsPosHEad = empty ( $ this -> js [ static :: POS_HEAD ] ) ? [ ] : $ this -> js [ static :: POS_HEAD ] ; array_unshift ( $ arrJsPosHEad , "var absoluteBaseUrl = \"" . Yii :: $ app -> urlManager -> createAbsoluteUrl ( 'site/index' ) . "\";" ) ; array_unshift ( $ arrJsPosHEad , "var baseUrl = \"" . Yii :: $ app -> urlManager -> baseUrl . "\";" ) ; $ this -> js [ static :: POS_HEAD ] = $ arrJsPosHEad ; }
Put javascript for base url to head
7,345
public function setBrowserTitle ( $ title , $ isFrontend = true , $ prefix = 'Backend' ) { $ strResult = ( $ isFrontend ? $ title : $ prefix . ' :: ' . $ title ) ; $ this -> title = $ strResult ; }
Set title for browser with prefix
7,346
public static function getVar ( string $ name , $ defaultValue = null ) { $ value = getenv ( $ name ) ; return $ value !== false ? $ value : $ defaultValue ; }
Returns value of environment variable or default value
7,347
public static function getRequiredVar ( string $ name ) { $ value = getenv ( $ name ) ; if ( $ value === false ) { throw EnvVarNotFoundException :: create ( $ name ) ; } return $ value ; }
Returns value of environment variable or throws Exception when is not defined
7,348
public static function getVars ( array $ schema , string $ prefix = "" ) : array { $ env = [ ] ; foreach ( $ schema as $ name => $ default ) { $ env [ $ name ] = self :: getVar ( $ prefix . $ name , $ default ) ; } return $ env ; }
Returns values of environment variables defined in schema parameter
7,349
public function setPosition ( $ posX , $ posY , $ posZ = null ) { $ this -> setX ( $ posX ) -> setY ( $ posY ) ; if ( $ posZ !== null ) { $ this -> setZ ( $ posZ ) ; } return $ this ; }
Set the Control position
7,350
public function getDataAttribute ( $ name ) { if ( isset ( $ this -> dataAttributes [ $ name ] ) ) { return $ this -> dataAttributes [ $ name ] ; } return null ; }
Get data attribute
7,351
public function addDataAttributes ( array $ dataAttributes ) { foreach ( $ dataAttributes as $ name => $ value ) { $ this -> addDataAttribute ( $ name , $ value ) ; } return $ this ; }
Add multiple data attributes
7,352
public function addScriptFeature ( ScriptFeature $ scriptFeature ) { if ( ! in_array ( $ scriptFeature , $ this -> scriptFeatures , true ) ) { array_push ( $ this -> scriptFeatures , $ scriptFeature ) ; } return $ this ; }
Add a new Script Feature
7,353
public function addActionTriggerFeature ( $ actionName , $ eventLabel = ScriptLabel :: MOUSECLICK ) { $ actionTrigger = new ActionTrigger ( $ actionName , $ this , $ eventLabel ) ; $ this -> addScriptFeature ( $ actionTrigger ) ; return $ this ; }
Add a dynamic Action Trigger
7,354
public function addMapInfoFeature ( $ eventLabel = ScriptLabel :: MOUSECLICK ) { $ mapInfo = new MapInfo ( $ this , $ eventLabel ) ; $ this -> addScriptFeature ( $ mapInfo ) ; return $ this ; }
Add a dynamic Feature opening the current map info
7,355
public function addPlayerProfileFeature ( $ login , $ eventLabel = ScriptLabel :: MOUSECLICK ) { $ playerProfile = new PlayerProfile ( $ login , $ this , $ eventLabel ) ; $ this -> addScriptFeature ( $ playerProfile ) ; return $ this ; }
Add a dynamic Feature to open a specific player profile
7,356
public function addUISoundFeature ( $ soundName , $ variant = 0 , $ eventLabel = ScriptLabel :: MOUSECLICK ) { $ uiSound = new UISound ( $ soundName , $ this , $ variant , $ eventLabel ) ; $ this -> addScriptFeature ( $ uiSound ) ; return $ this ; }
Add a dynamic Feature playing a UISound
7,357
public function addToggleFeature ( Control $ toggledControl , $ labelName = ScriptLabel :: MOUSECLICK , $ onlyShow = false , $ onlyHide = false ) { $ toggle = new Toggle ( $ this , $ toggledControl , $ labelName , $ onlyShow , $ onlyHide ) ; $ this -> addScriptFeature ( $ toggle ) ; return $ this ; }
Add a dynamic Feature toggling another Control
7,358
public function addScriptText ( $ scriptText , $ label = ScriptLabel :: MOUSECLICK ) { $ customText = new ControlScript ( $ this , $ scriptText , $ label ) ; $ this -> addScriptFeature ( $ customText ) ; return $ this ; }
Add a custom Control Script text part
7,359
public function saveEntity ( $ context , FormData $ requestData , $ subResource = NULL ) { $ this -> setContext ( $ context ) ; return $ this -> saveFormular ( ( array ) $ requestData ) ; }
Overrides the saving of the AbstractEntityController to just save the navigation tree from UI
7,360
public function createNewNode ( stdClass $ jsonNode ) { $ nodeClass = $ this -> container -> getRoleFQN ( 'NavigationNode' ) ; $ node = new $ nodeClass ( ( array ) $ jsonNode -> title ) ; $ node -> generateSlugs ( ) ; $ defaultSlug = current ( $ node -> getI18nSlug ( ) ) ; $ page = $ this -> createNewPage ( $ defaultSlug ) ; $ this -> dc -> getEntityManager ( ) -> persist ( $ page ) ; $ node -> setPage ( $ page ) ; return $ node ; }
Just create one the attributes will be set automatically
7,361
public function nextGeneration ( ) { Cond :: broadcast ( $ this -> cond ) ; $ this -> count = $ this -> parties ; $ this -> generation = new Generation ( ) ; }
Updates state on barrier trip and wakes up everyone . Called only while holding lock .
7,362
public function breakBarrier ( ) { $ this -> generation -> broken = true ; $ this -> count = $ this -> parties ; Cond :: broadcast ( $ this -> cond ) ; }
Sets current barrier generation as broken and wakes up everyone . Called only while holding lock .
7,363
public function storeDebugNode ( NodeInterface $ node ) { $ nodeId = count ( $ this -> debugNodes ) ; $ this -> debugNodes [ ] = $ node ; return $ nodeId ; }
Store a node in a debug list and return the allocated index for it .
7,364
public function getDebugError ( $ error , $ code , $ path = null ) { $ line = $ this -> getSourceLine ( $ error ) ; if ( $ line === false ) { return $ error ; } $ source = explode ( "\n" , $ code , max ( 2 , $ line ) ) ; array_pop ( $ source ) ; $ source = implode ( "\n" , $ source ) ; $ pos = mb_strrpos ( $ source , 'PUG_DEBUG:' ) ; if ( $ pos === false ) { throw $ error ; } $ nodeId = intval ( mb_substr ( $ source , $ pos + 10 , 32 ) ) ; if ( ! $ this -> debugIdExists ( $ nodeId ) ) { throw $ error ; } $ node = $ this -> getNodeFromDebugId ( $ nodeId ) ; $ nodeLocation = $ node -> getSourceLocation ( ) ; $ location = new SourceLocation ( ( $ nodeLocation ? $ nodeLocation -> getPath ( ) : null ) ? : $ path , $ nodeLocation ? $ nodeLocation -> getLine ( ) : 0 , $ nodeLocation ? $ nodeLocation -> getOffset ( ) : 0 , $ nodeLocation ? $ nodeLocation -> getOffsetLength ( ) : 0 ) ; $ className = $ this -> getOption ( 'located_exception_class_name' ) ; return new $ className ( $ location , $ error -> getMessage ( ) , $ error -> getCode ( ) , $ error ) ; }
Return a formatted error linked to pug source .
7,365
public function setFormatHandler ( $ doctype , $ format ) { if ( ! is_a ( $ format , FormatInterface :: class , true ) ) { throw new \ InvalidArgumentException ( "Passed format class $format must " . 'implement ' . FormatInterface :: class ) ; } $ this -> setOption ( [ 'formats' , $ doctype ] , $ format ) ; return $ this ; }
Set the format handler for a given doctype identifier .
7,366
public function initFormats ( ) { $ this -> dependencies = new DependencyInjection ( ) ; $ this -> mixins = new DependencyInjection ( ) ; $ this -> destructors = new SplObjectStorage ( ) ; $ this -> formats = [ ] ; return $ this ; }
Initialize the formats list and dependencies .
7,367
public function getFormatInstance ( $ format = null ) { $ format = $ format ? : $ this -> format ; if ( ! ( $ format instanceof FormatInterface ) ) { if ( ! isset ( $ this -> formats [ $ format ] ) ) { $ event = new NewFormatEvent ( $ this , new $ format ( $ this ) ) ; $ this -> trigger ( $ event ) ; $ this -> formats [ $ format ] = $ event -> getFormat ( ) ; } $ format = $ this -> formats [ $ format ] ; } return $ format ; }
Return current format as instance of FormatInterface .
7,368
public function setFormat ( $ doctype ) { $ formats = $ this -> getOption ( 'formats' ) ; $ this -> format = empty ( $ formats [ $ doctype ] ) ? $ this -> getOption ( 'default_format' ) : $ formats [ $ doctype ] ; return $ this ; }
Set a format name as the current or fallback to default if not available .
7,369
public function format ( ElementInterface $ element , $ format = null ) { if ( $ element instanceof DoctypeElement ) { $ formats = $ this -> getOption ( 'formats' ) ; $ doctype = $ element -> getValue ( ) ; $ this -> setFormat ( $ doctype ) ; if ( isset ( $ formats [ $ doctype ] ) ) { $ element -> setValue ( null ) ; } } $ format = $ this -> getFormatInstance ( $ format ) ; $ format -> setFormatter ( $ this ) ; $ formatEvent = new FormatEvent ( $ element , $ format ) ; $ this -> trigger ( $ formatEvent ) ; $ element = $ formatEvent -> getElement ( ) ; $ format = $ formatEvent -> getFormat ( ) ; $ stringifyEvent = new StringifyEvent ( $ formatEvent , $ element ? $ format ( $ element ) : '' ) ; $ this -> trigger ( $ stringifyEvent ) ; return $ stringifyEvent -> getOutput ( ) ; }
Entry point of the Formatter typically waiting for a DocumentElement and a format to return a string with HTML and PHP nested .
7,370
public function create ( $ type , array $ properties = [ ] ) { $ type = ( string ) $ type ; if ( isset ( $ this -> classes [ $ type ] ) ) { $ class = $ this -> classes [ $ type ] ; return new $ class ( $ properties ) ; } else if ( class_exists ( $ type ) ) { $ class = new $ type ( $ properties ) ; if ( $ class instanceof FilterInterface ) { return $ class ; } } throw new Exception \ InvalidArgumentException ( sprintf ( 'The given class <code>%s</code> does not exists.' , $ type ) ) ; }
Creates and returns a new filter instance of the given type .
7,371
public function match ( ) { $ result = false ; $ this -> matchedStatus = $ this -> result -> getStatus ( ) ; if ( $ this -> result -> hasHandler ( ) ) { $ result = true ; $ this -> matchedHandler = $ this -> result -> getHandler ( ) ; } else { $ this -> matchedHandler = $ this -> notFoundHandler ; } return $ result ; }
Match current HTTP request .
7,372
public function register_autoload_filter ( $ namespace , $ filter ) { if ( is_callable ( $ filter ) ) { if ( ! isset ( $ this -> filters [ $ namespace ] ) ) { $ this -> filters [ $ namespace ] = array ( ) ; } $ this -> filters [ $ namespace ] [ ] = $ filter ; } }
Autoload filters are functions that are used to autoload classes . These functions accept a class name as an argument and return the appropriate file path to that class . Autoload filters are applied per namespace . Each namespace can have multiple autoload filters . The class loader will loop through all the filters until a file is found . The filters are looped through in the order in which they were registered .
7,373
public function getCanonicalName ( ) { if ( mb_strpos ( $ this -> name , 'i18n' ) === 0 ) { return mb_strtolower ( mb_substr ( $ this -> name , 4 , 1 ) ) . mb_substr ( $ this -> name , 5 ) ; } return $ this -> name ; }
Returns the name of the property but cannonical
7,374
public function getFiles ( $ file = null ) { if ( $ file !== null ) { $ return = array ( ) ; foreach ( $ this -> _files as $ name => $ content ) { if ( $ name === $ file ) { $ return [ $ file ] = $ this -> _files [ $ name ] ; } if ( $ content [ 'name' ] === $ file ) { $ return [ $ name ] = $ this -> _files [ $ name ] ; } } if ( count ( $ return ) === 0 ) { require_once 'Zend/Validate/Exception.php' ; throw new Zend_Validate_Exception ( "The file '$file' was not found" ) ; } return $ return ; } return $ this -> _files ; }
Returns the array of set files
7,375
public function setFiles ( $ files = array ( ) ) { if ( count ( $ files ) === 0 ) { $ this -> _files = $ _FILES ; } else { $ this -> _files = $ files ; } foreach ( $ this -> _files as $ file => $ content ) { if ( ! isset ( $ content [ 'error' ] ) ) { unset ( $ this -> _files [ $ file ] ) ; } } return $ this ; }
Sets the files to be checked
7,376
public function set ( $ key , $ value ) { $ result = $ this -> allowed ( $ value ) ; if ( $ this -> passes ( $ result ) ) { parent :: set ( $ key , $ this -> normalize ( $ value ) ) ; } else { throw new \ UnexpectedValueException ( sprintf ( 'Value of type "%s" forbidden in this instance of %s' , gettype ( $ value ) , get_class ( $ this ) ) ) ; } }
Set the value at a given key provided that the value passes the defined guard . Optionally normalize the value before setting .
7,377
public static function create ( $ modelAlias = null , $ criteria = null ) { if ( $ criteria instanceof RoleQuery ) { return $ criteria ; } $ query = new RoleQuery ( null , null , $ modelAlias ) ; if ( $ criteria instanceof Criteria ) { $ query -> mergeWith ( $ criteria ) ; } return $ query ; }
Returns a new RoleQuery object .
7,378
public function filterByRole ( $ role = null , $ comparison = null ) { if ( null === $ comparison ) { if ( is_array ( $ role ) ) { $ comparison = Criteria :: IN ; } elseif ( preg_match ( '/[\%\*]/' , $ role ) ) { $ role = str_replace ( '*' , '%' , $ role ) ; $ comparison = Criteria :: LIKE ; } } return $ this -> addUsingAlias ( RolePeer :: ROLE , $ role , $ comparison ) ; }
Filter the query on the role column
7,379
public function send ( $ command , $ host = '' ) { $ host = $ host ? : $ this -> host ; if ( ! $ host ) { throw new \ InvalidArgumentException ( 'Unknown host that will run the command' ) ; } $ content = 'command=' . urlencode ( $ command ) ; $ fp = fsockopen ( $ this -> host , 80 , $ errno , $ errstr , self :: TIMEOUT ) ; $ request = 'POST ' . $ this -> path . " HTTP/1.1\r\n" ; $ request .= 'Host: ' . $ host . "\r\n" ; $ request .= "Content-Type: application/x-www-form-urlencoded\r\n" ; $ request .= 'Content-Length: ' . strlen ( $ content ) . "\r\n" ; $ request .= "Connection: Close\r\n\r\n" ; $ request .= $ content ; fwrite ( $ fp , $ request ) ; fclose ( $ fp ) ; }
Send the command to perform in a new thread .
7,380
public function onRequestComplete ( Event $ event ) { if ( $ body = $ event [ 'response' ] -> getBody ( ) ) { if ( substr ( $ body , 0 , 3 ) === "\xef\xbb\xbf" ) { $ event [ 'response' ] -> setBody ( substr ( $ body , 3 ) ) ; } else if ( substr ( $ body , 0 , 4 ) === "\xff\xfe\x00\x00" || substr ( $ body , 0 , 4 ) === "\x00\x00\xfe\xff" ) { $ event [ 'response' ] -> setBody ( substr ( $ body , 4 ) ) ; } else if ( substr ( $ body , 0 , 2 ) === "\xff\xfe" || substr ( $ body , 0 , 2 ) === "\xfe\xff" ) { $ event [ 'response' ] -> setBody ( substr ( $ body , 2 ) ) ; } } }
When the request is complete check the message body and strip any BOMs if they exist .
7,381
public function REJECT ( int $ http_code = 403 , string $ message = "Access denied" ) : self { $ this -> rejectHttpCode = $ http_code ; $ this -> rejectMessage = $ message ; $ this -> action = self :: ACTION_REJECT ; return $ this ; }
Reject the Request
7,382
function placehold ( $ rules ) { if ( 'development' == WP_ENV || 'staging' == WP_ENV ) { $ dir = wp_upload_dir ( ) ; $ uploads_rel_path = str_replace ( trailingslashit ( home_url ( ) ) , '' , $ dir [ 'baseurl' ] ) ; $ tp_images_rules = array ( '' , '# BEGIN TP Development uploads' , 'RewriteCond %{REQUEST_FILENAME} !-f' , 'RewriteRule ^' . $ uploads_rel_path . '/(.*)-([0-9]+)x([0-9]+).(gif|jpe?g|png|bmp)$ http://www.placehold.it/$2x$3 [NC,L]' , 'RewriteCond %{REQUEST_FILENAME} !-f' , 'RewriteRule ^' . $ uploads_rel_path . '/(.*)(gif|jpe?g|png|bmp)$ http://www.placehold.it/600x600 [NC,L]' , '# END TP Development uploads' , '' , ) ; $ rules = explode ( "\n" , $ rules ) ; $ rules = wp_parse_args ( $ rules , $ tp_images_rules ) ; $ rules = implode ( "\n" , $ rules ) ; } return $ rules ; }
Redirect images from uploads to placehold . it on develop and release environments if they don t exist
7,383
public function storeLead ( LeadData $ lead_data , $ notification_email = '' ) { $ form_params = [ 'debug' => $ this -> debug , 'action' => 'create' , 'appkey' => $ this -> getAppKey ( ) , ] ; $ form_params = array_merge ( $ form_params , $ lead_data -> toArray ( ) ) ; if ( ! empty ( $ notification_email ) ) { $ form_params [ 'notification_email' ] = $ notification_email ; } $ response = $ this -> guzzleClient -> post ( self :: BASE_URI , [ 'body' => $ form_params ] ) ; if ( $ response -> getStatusCode ( ) === 200 ) { $ content = json_decode ( $ response -> getBody ( ) -> getContents ( ) ) ; if ( $ content -> success === false ) { throw new InvalidArgumentException ( $ content -> data ) ; } return $ content ; } }
Stores a lead
7,384
public static function addSectionMediaElement ( $ src , $ type , PHPWord_Section_MemoryImage $ memoryImage = null ) { $ mediaId = md5 ( $ src ) ; $ key = ( $ type == 'image' ) ? 'images' : 'embeddings' ; if ( ! array_key_exists ( $ mediaId , self :: $ _sectionMedia [ $ key ] ) ) { $ cImg = self :: countSectionMediaElements ( 'images' ) ; $ cObj = self :: countSectionMediaElements ( 'embeddings' ) ; $ rID = self :: countSectionMediaElements ( ) + 7 ; $ media = array ( ) ; if ( $ type == 'image' ) { $ cImg ++ ; $ inf = pathinfo ( $ src ) ; $ isMemImage = ( substr ( strtolower ( $ inf [ 'extension' ] ) , 0 , 3 ) == 'php' && $ type == 'image' ) ? true : false ; if ( $ isMemImage ) { $ ext = $ memoryImage -> getImageExtension ( ) ; $ media [ 'isMemImage' ] = true ; $ media [ 'createfunction' ] = $ memoryImage -> getImageCreateFunction ( ) ; $ media [ 'imagefunction' ] = $ memoryImage -> getImageFunction ( ) ; } else { $ ext = $ inf [ 'extension' ] ; if ( $ ext == 'jpeg' ) { $ ext = 'jpg' ; } } $ folder = 'media' ; $ file = $ type . $ cImg . '.' . strtolower ( $ ext ) ; } elseif ( $ type == 'oleObject' ) { $ cObj ++ ; $ folder = 'embedding' ; $ file = $ type . $ cObj . '.bin' ; } $ media [ 'source' ] = $ src ; $ media [ 'target' ] = "$folder/section_$file" ; $ media [ 'type' ] = $ type ; $ media [ 'rID' ] = $ rID ; self :: $ _sectionMedia [ $ key ] [ $ mediaId ] = $ media ; if ( $ type == 'oleObject' ) { return array ( $ rID , ++ self :: $ _objectId ) ; } else { return $ rID ; } } else { if ( $ type == 'oleObject' ) { $ rID = self :: $ _sectionMedia [ $ key ] [ $ mediaId ] [ 'rID' ] ; return array ( $ rID , ++ self :: $ _objectId ) ; } else { return self :: $ _sectionMedia [ $ key ] [ $ mediaId ] [ 'rID' ] ; } } }
Add new Section Media Element
7,385
public static function addSectionLinkElement ( $ linkSrc ) { $ rID = self :: countSectionMediaElements ( ) + 7 ; $ link = array ( ) ; $ link [ 'target' ] = $ linkSrc ; $ link [ 'rID' ] = $ rID ; $ link [ 'type' ] = 'hyperlink' ; self :: $ _sectionMedia [ 'links' ] [ ] = $ link ; return $ rID ; }
Add new Section Link Element
7,386
public static function getSectionMediaElements ( $ key = null ) { if ( ! is_null ( $ key ) ) { return self :: $ _sectionMedia [ $ key ] ; } else { $ arrImages = self :: $ _sectionMedia [ 'images' ] ; $ arrObjects = self :: $ _sectionMedia [ 'embeddings' ] ; $ arrLinks = self :: $ _sectionMedia [ 'links' ] ; return array_merge ( $ arrImages , $ arrObjects , $ arrLinks ) ; } }
Get Section Media Elements
7,387
public static function countSectionMediaElements ( $ key = null ) { if ( ! is_null ( $ key ) ) { return count ( self :: $ _sectionMedia [ $ key ] ) ; } else { $ cImages = count ( self :: $ _sectionMedia [ 'images' ] ) ; $ cObjects = count ( self :: $ _sectionMedia [ 'embeddings' ] ) ; $ cLinks = count ( self :: $ _sectionMedia [ 'links' ] ) ; return ( $ cImages + $ cObjects + $ cLinks ) ; } }
Get Section Media Elements Count
7,388
public static function addHeaderMediaElement ( $ headerCount , $ src , PHPWord_Section_MemoryImage $ memoryImage = null ) { $ mediaId = md5 ( $ src ) ; $ key = 'header' . $ headerCount ; if ( ! array_key_exists ( $ key , self :: $ _headerMedia ) ) { self :: $ _headerMedia [ $ key ] = array ( ) ; } if ( ! array_key_exists ( $ mediaId , self :: $ _headerMedia [ $ key ] ) ) { $ cImg = self :: countHeaderMediaElements ( $ key ) ; $ rID = $ cImg + 1 ; $ cImg ++ ; $ inf = pathinfo ( $ src ) ; $ isMemImage = ( substr ( strtolower ( $ inf [ 'extension' ] ) , 0 , 3 ) == 'php' ) ? true : false ; $ media = array ( ) ; if ( $ isMemImage ) { $ ext = $ memoryImage -> getImageExtension ( ) ; $ media [ 'isMemImage' ] = true ; $ media [ 'createfunction' ] = $ memoryImage -> getImageCreateFunction ( ) ; $ media [ 'imagefunction' ] = $ memoryImage -> getImageFunction ( ) ; } else { $ ext = $ inf [ 'extension' ] ; if ( $ ext == 'jpeg' ) { $ ext = 'jpg' ; } } $ file = 'image' . $ cImg . '.' . strtolower ( $ ext ) ; $ media [ 'source' ] = $ src ; $ media [ 'target' ] = 'media/' . $ key . '_' . $ file ; $ media [ 'type' ] = 'image' ; $ media [ 'rID' ] = $ rID ; self :: $ _headerMedia [ $ key ] [ $ mediaId ] = $ media ; return $ rID ; } else { return self :: $ _headerMedia [ $ key ] [ $ mediaId ] [ 'rID' ] ; } }
Add new Header Media Element
7,389
public static function addFooterMediaElement ( $ footerCount , $ src , PHPWord_Section_MemoryImage $ memoryImage = null ) { $ mediaId = md5 ( $ src ) ; $ key = 'footer' . $ footerCount ; if ( ! array_key_exists ( $ key , self :: $ _footerMedia ) ) { self :: $ _footerMedia [ $ key ] = array ( ) ; } if ( ! array_key_exists ( $ mediaId , self :: $ _footerMedia [ $ key ] ) ) { $ cImg = self :: countFooterMediaElements ( $ key ) ; $ rID = $ cImg + 1 ; $ cImg ++ ; $ inf = pathinfo ( $ src ) ; $ isMemImage = ( substr ( strtolower ( $ inf [ 'extension' ] ) , 0 , 3 ) == 'php' ) ? true : false ; $ media = array ( ) ; if ( $ isMemImage ) { $ ext = $ memoryImage -> getImageExtension ( ) ; $ media [ 'isMemImage' ] = true ; $ media [ 'createfunction' ] = $ memoryImage -> getImageCreateFunction ( ) ; $ media [ 'imagefunction' ] = $ memoryImage -> getImageFunction ( ) ; } else { $ ext = $ inf [ 'extension' ] ; if ( $ ext == 'jpeg' ) { $ ext = 'jpg' ; } } $ file = 'image' . $ cImg . '.' . strtolower ( $ ext ) ; $ media [ 'source' ] = $ src ; $ media [ 'target' ] = 'media/' . $ key . '_' . $ file ; $ media [ 'type' ] = 'image' ; $ media [ 'rID' ] = $ rID ; self :: $ _footerMedia [ $ key ] [ $ mediaId ] = $ media ; return $ rID ; } else { return self :: $ _footerMedia [ $ key ] [ $ mediaId ] [ 'rID' ] ; } }
Add new Footer Media Element
7,390
public static function database_dump_structure ( $ dump_directory ) { if ( is_dir ( $ dump_directory ) == false ) { $ exception = bootstrap :: get_library ( 'exception' ) ; throw new $ exception ( 'directory not found' ) ; } $ mysql = bootstrap :: get_library ( 'mysql' ) ; $ tables = $ mysql :: select ( $ mysql :: AS_ARRAY , "SHOW TABLES;" ) ; foreach ( $ tables as $ table ) { $ table_name = current ( $ table ) ; $ drop = "DROP TABLE IF EXISTS `" . $ table_name . "`;" ; $ dump = $ mysql :: select ( $ mysql :: AS_ROW , "SHOW CREATE TABLE `%s`;" , $ table_name ) ; $ dump = $ dump [ 'Create Table' ] ; $ dump = preg_replace ( '{ AUTO_INCREMENT=[0-9]+}i' , '' , $ dump ) ; $ full_dump = $ drop . "\n\n" . $ dump . ";\n" ; file_put_contents ( $ dump_directory . '/' . $ table_name . '.sql' , $ full_dump ) ; } }
dumps create table statements per table in the specified path
7,391
public static function check_composer_updates ( ) { $ composer_json = file_get_contents ( ROOT_DIR . '/composer.json' ) ; $ composer_json = json_decode ( $ composer_json , true ) ; if ( empty ( $ composer_json [ 'require' ] ) ) { $ exception = bootstrap :: get_library ( 'exception' ) ; throw new $ exception ( 'there are no required packages to check' ) ; } $ composer_lock = file_get_contents ( ROOT_DIR . '/composer.lock' ) ; $ composer_lock = json_decode ( $ composer_lock , true ) ; if ( empty ( $ composer_lock [ 'packages' ] ) ) { $ exception = bootstrap :: get_library ( 'exception' ) ; throw new $ exception ( 'lock file is missing its packages' ) ; } $ composer_executable = 'composer' ; if ( file_exists ( ROOT_DIR . 'composer.phar' ) ) { $ composer_executable = 'php composer.phar' ; } $ required_packages = $ composer_json [ 'require' ] ; $ installed_packages = $ composer_lock [ 'packages' ] ; $ update_packages = [ ] ; foreach ( $ installed_packages as $ installed_package ) { $ package_name = $ installed_package [ 'name' ] ; $ installed_version = preg_replace ( '/v([0-9].*)/' , '$1' , $ installed_package [ 'version' ] ) ; $ version_regex = '/versions\s*:.+v?([0-9]+\.[0-9]+(\.[0-9]+)?)(,|$)/U' ; if ( empty ( $ required_packages [ $ package_name ] ) ) { continue ; } if ( strpos ( $ installed_version , 'dev-' ) === 0 ) { $ installed_version = $ installed_package [ 'source' ] [ 'reference' ] ; $ version_regex = '/source\s*:.+ ([a-f0-9]{40})$/m' ; } $ package_info = shell_exec ( $ composer_executable . ' show -a ' . escapeshellarg ( $ package_name ) ) ; preg_match ( $ version_regex , $ package_info , $ possible_version ) ; if ( empty ( $ possible_version ) ) { $ exception = bootstrap :: get_library ( 'exception' ) ; throw new $ exception ( 'can not find out newest release for ' . $ package_name ) ; } if ( ENVIRONMENT == 'development' ) { echo 'installed ' . $ package_name . ' at ' . $ installed_version . ', possible version is ' . $ possible_version [ 1 ] . PHP_EOL ; } if ( $ possible_version [ 1 ] == $ installed_version ) { continue ; } $ update_packages [ $ package_name ] = [ 'required' => $ required_packages [ $ package_name ] , 'installed' => $ installed_version , 'possible' => $ possible_version [ 1 ] , ] ; } return $ update_packages ; }
checks composer packages for new releases since the installed version
7,392
public function getConfig ( $ module ) { if ( ! isset ( $ this -> cache [ 'paths' ] [ $ module ] ) ) { $ path = $ this -> getPath ( $ module ) ; $ file = $ path . DIRECTORY_SEPARATOR . 'slender.yml' ; $ parsed = $ this -> parser -> parseFile ( $ file ) ; $ parsed [ 'path' ] = $ path ; $ this -> cache [ 'paths' ] [ $ module ] = $ parsed ; } return $ this -> cache [ 'paths' ] [ $ module ] ; }
Return parsed config file for module
7,393
public function getHttpVersion ( ) { if ( ! isset ( $ this -> httpVersion ) ) { $ serverProtocol = $ _SERVER [ 'SERVER_PROTOCOL' ] ; $ this -> httpVersion = substr ( $ serverProtocol , strpos ( $ serverProtocol , '/' ) + 1 ) ; } return $ this -> httpVersion ; }
Get request HTTP version .
7,394
public function getHost ( ) { if ( ! is_null ( $ this -> host ) ) { return $ this -> host ; } if ( $ _SERVER [ 'HTTP_X_FORWARDED_HOST' ] ) { $ elements = explode ( ',' , $ value ) ; $ host = trim ( end ( $ elements ) ) ; } else if ( $ _SERVER [ 'HTTP_HOST' ] ) { $ host = $ _SERVER [ 'HTTP_HOST' ] ; } else if ( $ _SERVER [ 'SERVER_NAME' ] ) { $ host = $ _SERVER [ 'SERVER_NAME' ] ; } if ( isset ( $ host ) ) { $ host = preg_replace ( '/:\d+$/' , '' , $ host ) ; $ this -> host = $ host ; } return $ this -> host ; }
Get HTTP host .
7,395
public function getContentType ( ) { if ( ! isset ( $ this -> contentType ) ) { $ numOfMatches = preg_match ( '/^([^;]*)/' , $ this -> getHeader ( 'Content-Type' ) , $ matches ) ; if ( $ numOfMatches ) { $ this -> contentType = trim ( $ matches [ 1 ] ) ; } else { $ this -> contentType = '' ; } } return $ this -> contentType ; }
Get content type .
7,396
public function getInput ( ) { if ( ! isset ( $ this -> input ) ) { switch ( $ this -> method ) { case 'POST' : switch ( $ this -> getContentType ( ) ) { case 'application/x-www-form-urlencoded' : case 'multipart/form-data' : $ this -> input = $ _POST ; break ; default : $ this -> input = $ this -> getParamsFromInput ( ) ; break ; } break ; case 'PUT' : case 'DELETE' : $ this -> input = $ this -> getParamsFromInput ( ) ; break ; default : $ this -> input = [ ] ; break ; } } return $ this -> input ; }
Return HTTP POST PUT or DELETE variables .
7,397
public function getDiRequirements ( $ className ) { if ( ! isset ( $ this -> classCache [ $ className ] ) ) { $ reflectionClass = new \ ReflectionClass ( $ className ) ; $ injects = [ ] ; $ props = $ reflectionClass -> getProperties ( ) ; foreach ( $ props as $ prop ) { $ inject = $ this -> annotationReader -> getPropertyAnnotation ( $ prop , 'Slender\Core\DependencyInjector\Annotation\Inject' ) ; if ( $ inject ) { $ identifier = $ inject -> getIdentifier ( ) ; if ( ! $ identifier ) { $ identifier = Util :: hyphenCase ( $ prop -> getName ( ) ) ; } $ data = array ( 'identifier' => $ identifier , 'isPublic' => $ prop -> isPublic ( ) , 'setter' => false ) ; if ( ! $ prop -> isPublic ( ) ) { $ setter = Util :: setterMethodName ( $ prop -> getName ( ) ) ; if ( method_exists ( $ className , $ setter ) ) { $ data [ 'hasSetter' ] = $ setter ; } ; } ; $ injects [ $ prop -> getName ( ) ] = $ data ; } } $ this -> classCache [ $ className ] = $ injects ; } return $ this -> classCache [ $ className ] ; }
Interrogate a class and see what dependencies it wants to be passed into its constructor
7,398
public function prepare ( & $ instance ) { $ requirements = $ this -> getDiRequirements ( get_class ( $ instance ) ) ; foreach ( $ requirements as $ propertyName => $ property ) { $ dependencyIdentifier = $ property [ 'identifier' ] ; $ dependency = $ this -> container [ $ dependencyIdentifier ] ; if ( ! isset ( $ this -> container [ $ dependencyIdentifier ] ) ) { throw new \ InvalidArgumentException ( "Unable to resolve dependency $dependencyIdentifier for injection" ) ; } if ( $ property [ 'isPublic' ] ) { $ instance -> $ propertyName = $ dependency ; } else { if ( $ property [ 'setter' ] ) { call_user_func ( $ instance , $ property [ 'setter' ] , $ dependency ) ; } else { $ refl = new \ ReflectionClass ( $ instance ) ; $ prop = $ refl -> getProperty ( $ propertyName ) ; $ prop -> setAccessible ( true ) ; $ prop -> setValue ( $ instance , $ this -> container [ $ dependencyIdentifier ] ) ; $ prop -> setAccessible ( false ) ; } } } }
Scan a class instance for injectable dependencies and inject them if found then return prepared instance .
7,399
public function getAuthFactory ( ) : ? Factory { if ( ! $ this -> hasAuthFactory ( ) ) { $ this -> setAuthFactory ( $ this -> getDefaultAuthFactory ( ) ) ; } return $ this -> authFactory ; }
Get auth factory