idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
2,600
protected function log ( ) { $ this -> worker -> setInstance ( $ this -> instance ) ; if ( $ this -> worker -> ping ( ) ) { $ infos = $ this -> worker -> getInfos ( ) ; $ createdAt = new \ DateTime ( ) ; $ log = $ this -> logManager -> createNew ( ) ; $ log -> setMemory ( $ infos [ 'Memory' ] [ 'used_memory' ] ) ; $ log -> setCpu ( $ infos [ 'CPU' ] [ 'used_cpu_sys' ] ) ; $ log -> setNbClients ( sizeof ( $ this -> worker -> getClients ( ) ) ) ; $ log -> setCreatedAt ( $ createdAt ) ; $ this -> instance -> addLog ( $ log ) ; } }
Create new log for the current instance
2,601
public function deleteHandler ( $ event , $ handler ) { if ( empty ( $ event ) ) { throw new \ Exception ( "Event is not specified!" ) ; } if ( ! is_callable ( $ handler ) ) { throw new \ Exception ( "Event handler is not valid!" ) ; } try { $ f = new \ ReflectionFunction ( $ handler ) ; } catch ( \ Exception $ ex ) { throw new \ Exception ( $ ex -> getMessage ( ) ) ; } if ( isset ( self :: $ event_table [ $ event ] [ $ f -> __toString ( ) ] ) ) { unset ( self :: $ event_table [ $ event ] [ $ f -> __toString ( ) ] ) ; } return true ; }
Deletes the handler of an event .
2,602
public function deleteHandlers ( $ event ) { if ( empty ( $ event ) ) { throw new \ Exception ( "Event is not specified!" ) ; } if ( isset ( self :: $ event_table [ $ event ] ) ) { unset ( self :: $ event_table [ $ event ] ) ; } return true ; }
Deletes all handlers of an event .
2,603
public function suspendEvent ( $ event ) { if ( empty ( $ event ) ) { throw new \ Exception ( "Event is not specified!" ) ; } self :: $ suspended_events [ $ event ] = $ event ; return true ; }
Suspends an event .
2,604
public function resumeEvent ( $ event ) { if ( empty ( $ event ) ) { throw new \ Exception ( "Event is not specified!" ) ; } if ( isset ( self :: $ suspended_events [ $ event ] ) ) { unset ( self :: $ suspended_events [ $ event ] ) ; } return true ; }
Resumes a previously suspended event .
2,605
public function fireEvent ( $ event , $ parameters ) { if ( empty ( $ event ) ) { throw new \ Exception ( "Event is not specified!" ) ; } if ( ! empty ( self :: $ suspended_events [ $ event ] ) ) { return true ; } if ( empty ( self :: $ event_table [ $ event ] ) ) { return true ; } $ cnt = 0 ; try { foreach ( self :: $ event_table [ $ event ] as $ f ) { $ cnt ++ ; $ f -> invoke ( $ event , $ parameters ) ; } } catch ( \ Exception $ ex ) { throw new \ Exception ( $ ex -> getMessage ( ) ) ; } return $ cnt ; }
Fires and event .
2,606
protected function isElementValid ( $ element ) : bool { return is_a ( $ element , $ this -> getType ( ) ) || is_subclass_of ( $ element , $ this -> getType ( ) ) ; }
Check is element valid object type
2,607
protected function fetchAliasRouteNames ( ) { if ( '_list' != substr ( $ this -> getRouteName ( ) , - 5 ) ) { throw new MenuException ( 'Route name used for AdminGeneratorMenuItems must end with _list' ) ; } $ baseName = substr ( $ this -> getRouteName ( ) , 0 , - 4 ) ; $ actions = array ( 'edit' , 'update' , 'show' , 'object' , 'batch' , 'new' , 'create' , 'filters' , 'scopes' ) ; $ routes = array ( ) ; foreach ( $ actions as $ action ) { $ routes [ ] = $ baseName . $ action ; } $ this -> addAliasRoutes ( $ routes ) ; return parent :: fetchAliasRouteNames ( ) ; }
Fetch the item s alias_route_names option .
2,608
protected function initCounters ( ) { $ pos = 0 ; while ( $ pos < strlen ( $ this -> pattern ) ) { $ char = $ this -> pattern [ $ pos ] ; if ( $ char == "{" ) { $ this -> uriVars ++ ; $ pos ++ ; } else if ( $ char == "*" ) { if ( ( $ pos + 1 ) < strlen ( $ this -> pattern ) && $ this -> pattern [ $ pos + 1 ] == "*" ) { $ this -> doubleWildcards ++ ; $ pos += 2 ; } else if ( ! substr ( $ this -> pattern , $ pos - 1 ) == ".*" ) { $ this -> singleWildcards ++ ; $ pos ++ ; } else { $ pos ++ ; } } else { $ pos ++ ; } } }
Initializes the counters for the supplied pattern
2,609
public function check ( array $ items , array $ rules ) { $ this -> _items = $ items ; foreach ( $ items as $ item => $ value ) { if ( array_key_exists ( $ item , $ rules ) ) { $ this -> validate ( $ item , $ value , $ rules [ $ item ] ) ; } } return $ this ; }
Check if items can be validate
2,610
protected function validateRule ( $ caller , $ field , $ value , $ rule , $ satisfier ) { if ( in_array ( $ rule , $ this -> getRules ( ) ) ) { if ( ! call_user_func_array ( [ $ caller , $ rule ] , [ $ field , $ value , $ satisfier ] ) ) { $ this -> ruleFailed ( $ field , $ rule , $ satisfier ) ; } } }
Validate the rule by calling the correct function
2,611
protected function ruleFailed ( $ field , $ rule , $ satisfier ) { $ this -> _errorHandler -> add ( str_replace ( [ $ this -> _field_anchor , $ this -> _satisfier_anchor ] , [ $ field , $ satisfier ] , $ this -> getMessage ( $ rule , $ this -> _default_message ) ) , $ field ) ; }
Add an error with the correct error message
2,612
public function getMessage ( $ rule , $ default = NULL ) { $ messages = $ this -> getMessages ( ) ; if ( isset ( $ messages [ $ rule ] ) ) { return $ messages [ $ rule ] ; } else { return $ default ; } }
Get the error message for the rule
2,613
protected function loadSiteClass ( ) { $ site = null ; $ config = $ this -> getConfig ( ) ; if ( ! empty ( $ config [ 'SITE_CLASS' ] ) ) { $ className = "{$config['NAMESPACE_APP']}Classes\\{$config['SITE_CLASS']}" ; $ site = new $ className ( $ config ) ; $ this -> logger -> debug ( "Loaded Configured Class: {$className}" ) ; } else { $ site = new CoreClasses \ CoreSite ( $ config ) ; $ this -> logger -> debug ( "Loaded Core Site Class" ) ; } if ( empty ( $ site ) ) { $ this -> logger -> error ( "Site Class not found" ) ; exit ; } $ this -> setSite ( $ site ) ; }
Looks for a configured Site implementation to utilize falls back to CoreSite if none are found
2,614
protected function applyViewRenderer ( ) { $ config = $ this -> getConfig ( ) ; $ inputData = $ this -> getSite ( ) -> getSanitizedInputData ( ) ; if ( $ viewRendererName = $ this -> getViewRendererName ( ) ) { $ this -> getSite ( ) -> setViewRenderer ( new $ viewRendererName ( $ this -> getSite ( ) -> getGlobalUser ( ) , $ this -> getSite ( ) -> getPages ( ) , $ inputData , ( ! empty ( $ config [ 'controllerConfig' ] ) ? $ config [ 'controllerConfig' ] [ 'name' ] : null ) ) ) ; } else { $ this -> logger -> error ( "ViewRenderer Class not found" ) ; exit ; } }
Finds an appropriate ViewRenderer and sets it up for use
2,615
protected function getViewRendererName ( ) { $ config = $ this -> getConfig ( ) ; $ inputData = $ this -> getSite ( ) -> getSanitizedInputData ( ) ; $ viewRendererName = null ; $ availableCoreRenderers = array ( "json" , "csv" , "html" ) ; $ viewRenderOverride = null ; if ( ! empty ( $ inputData [ 'json' ] ) ) { $ viewRenderOverride = "JSONViewRenderer" ; } else if ( ! empty ( $ inputData [ 'view_renderer' ] ) && in_array ( $ inputData [ 'view_renderer' ] , $ availableCoreRenderers ) ) { $ viewRenderOverride = "{$inputData['view_renderer']}ViewRenderer" ; } if ( $ viewRenderOverride ) { $ viewRendererName = "{$config['NAMESPACE_CORE']}Classes\\ViewRenderers\\{$viewRenderOverride}" ; } else if ( ! empty ( $ config [ 'VIEW_RENDERER' ] ) ) { if ( class_exists ( "{$config['NAMESPACE_APP']}Classes\\ViewRenderers\\{$config['VIEW_RENDERER']}" ) ) { $ viewRendererName = "{$config['NAMESPACE_APP']}Classes\\ViewRenderers\\{$config['VIEW_RENDERER']}" ; } elseif ( class_exists ( "{$config['NAMESPACE_CORE']}Classes\\ViewRenderers\\{$config['VIEW_RENDERER']}" ) ) { $ viewRendererName = "{$config['NAMESPACE_CORE']}Classes\\ViewRenderers\\{$config['VIEW_RENDERER']}" ; } } else { $ viewRendererName = "{$config['NAMESPACE_CORE']}Classes\\ViewRenderers\\HTMLViewRenderer" ; } return $ viewRendererName ; }
Provides the fully qualified class name of the ViewRenderer that should be used to render the response App level extenders of CoreLoader can override this method to use their own criteria to select the ViewRenderer
2,616
protected function render ( ) { if ( $ this -> getSite ( ) -> hasRedirectUrl ( ) ) { $ this -> getSite ( ) -> redirect ( ) ; } $ this -> getSite ( ) -> getViewRenderer ( ) -> registerAppContextProperty ( "systemMessages" , $ this -> getSite ( ) -> getSystemMessages ( ) ) ; $ this -> getSite ( ) -> getViewRenderer ( ) -> renderView ( ) ; }
Asks the ViewRenderer to render the response
2,617
public function hydrate ( Model $ model , \ Tapestry \ Entities \ Taxonomy $ taxonomy ) { $ model -> setName ( $ taxonomy -> getName ( ) ) ; }
Taxonomy Hydration .
2,618
function clear_messages ( ) { $ this -> last_error = null ; $ this -> last_error_id = null ; $ this -> last_query = null ; }
Clears the last stored occured error its ID and the last executed query .
2,619
public static function isMatch ( $ path , $ pattern ) { if ( null !== $ path && ( ! is_string ( $ path ) || 0 >= mb_strlen ( $ path ) || 0 !== mb_strpos ( $ path , '/' ) ) ) { throw new InvalidArgumentException ( 'invalid path' ) ; } if ( ! is_string ( $ pattern ) || 0 >= mb_strlen ( $ pattern ) || ( 0 !== mb_strpos ( $ pattern , '/' ) && '*' !== $ pattern ) ) { throw new InvalidArgumentException ( 'invalid pattern' ) ; } if ( '*' === $ pattern ) { return [ ] ; } if ( $ path === $ pattern ) { return [ ] ; } if ( false === mb_strpos ( $ pattern , ':' ) ) { return false ; } $ pattern = preg_replace ( '/:([\w]+)/i' , '(?P<${1}>([^_][^/]*))' , $ pattern ) ; if ( null === $ pattern ) { throw new LogicException ( 'regular expression for parameter replacement failed' ) ; } $ pm = preg_match ( sprintf ( '#^%s$#' , $ pattern ) , $ path , $ parameters ) ; if ( false === $ pm ) { throw new LogicException ( 'regular expression for path matching failed' ) ; } if ( 0 === $ pm ) { return false ; } $ patternParameters = [ ] ; if ( null !== $ parameters ) { foreach ( $ parameters as $ k => $ v ) { if ( is_string ( $ k ) ) { $ patternParameters [ $ k ] = $ v ; } } } return $ patternParameters ; }
Determines if the provided path matches the provided pattern and returns matched parameters if specified .
2,620
public function getSiteInfo ( array $ siprop = null , $ sifilteriw = null , $ sishowalldb = false , $ sinumberingroup = false , array $ siinlanguagecode = null ) { $ path = '?action=query&meta=siteinfo' ; if ( isset ( $ siprop ) ) { $ path .= '&siprop=' . $ this -> buildParameter ( $ siprop ) ; } if ( isset ( $ sifilteriw ) ) { $ path .= '&sifilteriw=' . $ sifilteriw ; } if ( $ sishowalldb ) { $ path .= '&sishowalldb=' ; } if ( $ sinumberingroup ) { $ path .= '&sinumberingroup=' ; } if ( isset ( $ siinlanguagecode ) ) { $ path .= '&siinlanguagecode=' . $ this -> buildParameter ( $ siinlanguagecode ) ; } $ response = $ this -> client -> get ( $ this -> fetchUrl ( $ path ) ) ; return $ this -> validateResponse ( $ response ) ; }
Method to get site information .
2,621
public function getEvents ( array $ leprop = null , $ letype = null , $ leaction = null , $ letitle = null , $ leprefix = null , $ letag = null , $ leuser = null , $ lestart = null , $ leend = null , $ ledir = null , $ lelimit = null ) { $ path = '?action=query&list=logevents' ; if ( isset ( $ leprop ) ) { $ path .= '&leprop=' . $ this -> buildParameter ( $ leprop ) ; } if ( isset ( $ letype ) ) { $ path .= '&letype=' . $ letype ; } if ( isset ( $ leaction ) ) { $ path .= '&leaction=' . $ leaction ; } if ( isset ( $ letitle ) ) { $ path .= '&letitle=' . $ letitle ; } if ( isset ( $ leprefix ) ) { $ path .= '&leprefix=' . $ leprefix ; } if ( isset ( $ letag ) ) { $ path .= '&letag=' . $ letag ; } if ( isset ( $ leuser ) ) { $ path .= '&leuser=' . $ leuser ; } if ( isset ( $ lestart ) ) { $ path .= '&lestart=' . $ lestart ; } if ( isset ( $ leend ) ) { $ path .= '&leend=' . $ leend ; } if ( isset ( $ ledir ) ) { $ path .= '&ledir=' . $ ledir ; } if ( isset ( $ lelimit ) ) { $ path .= '&lelimit=' . $ lelimit ; } $ response = $ this -> client -> get ( $ this -> fetchUrl ( $ path ) ) ; return $ this -> validateResponse ( $ response ) ; }
Method to get events from logs .
2,622
public function getRecentChanges ( $ rcstart = null , $ rcend = null , $ rcdir = null , array $ rcnamespace = null , $ rcuser = null , $ rcexcludeuser = null , $ rctag = null , array $ rcprop = null , array $ rctoken = null , array $ rcshow = null , $ rclimit = null , $ rctype = null , $ rctoponly = null ) { $ path = '?action=query&list=recentchanges' ; if ( isset ( $ rcstart ) ) { $ path .= '&rcstart=' . $ rcstart ; } if ( isset ( $ rcend ) ) { $ path .= '&rcend=' . $ rcend ; } if ( isset ( $ rcdir ) ) { $ path .= '&rcdir=' . $ rcdir ; } if ( isset ( $ rcnamespace ) ) { $ path .= '&rcnamespaces=' . $ this -> buildParameter ( $ rcnamespace ) ; } if ( isset ( $ rcuser ) ) { $ path .= '&rcuser=' . $ rcuser ; } if ( isset ( $ rcexcludeuser ) ) { $ path .= '&rcexcludeuser=' . $ rcexcludeuser ; } if ( isset ( $ rctag ) ) { $ path .= '&rctag=' . $ rctag ; } if ( isset ( $ rcprop ) ) { $ path .= '&rcprop=' . $ this -> buildParameter ( $ rcprop ) ; } if ( isset ( $ rctoken ) ) { $ path .= '&rctoken=' . $ this -> buildParameter ( $ rctoken ) ; } if ( isset ( $ rcshow ) ) { $ path .= '&rcshow=' . $ this -> buildParameter ( $ rcshow ) ; } if ( isset ( $ rclimit ) ) { $ path .= '&rclimit=' . $ rclimit ; } if ( isset ( $ rctype ) ) { $ path .= '&rctype=' . $ rctype ; } if ( isset ( $ rctoponly ) ) { $ path .= '&rctoponly=' . $ rctoponly ; } $ response = $ this -> client -> get ( $ this -> fetchUrl ( $ path ) ) ; return $ this -> validateResponse ( $ response ) ; }
Method to get recent changes on a site .
2,623
public function getProtectedTitles ( array $ ptnamespace = null , array $ ptlevel = null , $ ptlimit = null , $ ptdir = null , $ ptstart = null , $ ptend = null , array $ ptprop = null ) { $ path = '?action=query&list=protectedtitles' ; if ( isset ( $ ptnamespace ) ) { $ path .= '&ptnamespace=' . $ this -> buildParameter ( $ ptnamespace ) ; } if ( isset ( $ ptlevel ) ) { $ path .= '&ptlevel=' . $ this -> buildParameter ( $ ptlevel ) ; } if ( isset ( $ ptlimit ) ) { $ path .= '&ptlimit=' . $ ptlimit ; } if ( isset ( $ ptdir ) ) { $ path .= '&ptdir=' . $ ptdir ; } if ( isset ( $ ptstart ) ) { $ path .= '&ptstart=' . $ ptstart ; } if ( isset ( $ ptend ) ) { $ path .= '&ptend=' . $ ptend ; } if ( isset ( $ ptprop ) ) { $ path .= '&ptprop=' . $ this -> buildParameter ( $ ptprop ) ; } $ response = $ this -> client -> get ( $ this -> fetchUrl ( $ path ) ) ; return $ this -> validateResponse ( $ response ) ; }
Method to get protected titles on a site .
2,624
protected function execute ( string $ command ) : ? string { if ( ! function_exists ( 'proc_open' ) ) { return null ; } $ descriptors = [ 1 => [ 'pipe' , 'w' ] , 2 => [ 'pipe' , 'w' ] ] ; if ( ! is_resource ( $ process = proc_open ( $ command , $ descriptors , $ pipes , null , null , [ 'suppress_errors' => true ] ) ) ) { return null ; } $ output = stream_get_contents ( $ pipes [ 1 ] ) ; fclose ( $ pipes [ 1 ] ) ; fclose ( $ pipes [ 2 ] ) ; proc_close ( $ process ) ; return $ output ; }
Executes a system call and returns its output while suppressing any error output .
2,625
public function setAttribute ( $ strKey , $ mixValue ) { if ( $ mixValue === true ) $ mixValue = $ strKey ; else if ( $ mixValue === false ) $ mixValue = '' ; $ this -> arrAttributes [ $ strKey ] = $ mixValue ; }
sets an antribute
2,626
protected function generateStyleAttribute ( ) { $ strClasses = '' ; foreach ( $ this -> arrCssClasses as $ strClass => $ NULL ) { if ( $ strClass != '' ) $ strClass .= ' ' ; $ strClasses .= $ strClass ; } $ this -> setAttribute ( 'class' , $ strClasses ) ; $ strPropertys = '' ; foreach ( $ this -> arrCssPropertys as $ strProperty => $ strValue ) { if ( $ strPropertys != '' ) $ strPropertys .= ' ' ; $ strPropertys .= $ strProperty . ': ' . $ strValue . ';' ; } $ this -> setAttribute ( 'style' , $ strPropertys ) ; }
writes the style collected css styles and classes into the style atribute
2,627
protected function getFormattedElementAttributes ( ) { $ strOptions = '' ; $ this -> generateStyleAttribute ( ) ; foreach ( $ this -> arrAttributes as $ strKey => $ strVal ) if ( $ strVal !== '' ) $ strOptions .= sprintf ( ' %s="%s"' , htmlspecialchars ( $ strKey , ENT_QUOTES | ENT_XHTML ) , htmlspecialchars ( $ strVal , ENT_QUOTES | ENT_XHTML ) ) ; return $ strOptions ; }
Returns what deemed to be the final atributes string
2,628
public function setComment ( $ comment ) { if ( ! is_string ( $ comment ) ) { throw new InvalidArgumentException ( 'Expected a string, but got ' . gettype ( $ comment ) ) ; } $ this -> comment = $ comment ; }
Set the comment .
2,629
public function getLines ( ) { $ lines = explode ( PHP_EOL , $ this -> comment ) ; $ wrapper = function ( $ line ) { return new Line ( $ line ) ; } ; return array_map ( $ wrapper , $ lines ) ; }
Represent the comment as an array of Line instances .
2,630
public function assign ( $ vars , $ overwrite = true ) { if ( ! $ overwrite ) { $ vars = array_merge ( $ this -> _vars , $ vars ) ; } $ this -> _vars = $ vars ; return $ this ; }
Assigns variables to the template
2,631
public function partial ( $ template , $ vars = array ( ) ) { return $ this -> _renderTemplate ( $ template , array_merge ( $ this -> _vars , $ vars ) ) ; }
Renders a template in the context of the current template
2,632
private function _renderTemplate ( $ template , $ vars ) { extract ( $ vars , EXTR_SKIP ) ; ob_start ( ) ; try { require ( $ template ) ; $ contents = ob_get_contents ( ) ; } catch ( Exception $ e ) { ob_end_clean ( ) ; throw $ e ; } ob_end_clean ( ) ; return $ contents ; }
Requires a template in the context of a function with parameters extracted as php variables
2,633
public static function comparable ( ? string $ itemType = null ) : SortedSet { assert ( Validate :: isNull ( $ itemType ) || Validate :: implementsInterface ( $ itemType , Comparable :: class ) , sprintf ( '%s expects $itemType to implement %s' , __METHOD__ , Comparable :: class ) ) ; return new static ( new ComparableComparator ( ) , $ itemType ) ; }
Creates collection of comparable items
2,634
public static function enable ( $ configuration = array ( ) ) { self :: setConfiguration ( $ configuration ) ; if ( ! self :: initialize ( ) ) { return ; } error_reporting ( self :: $ configuration -> getErrorReportingLevel ( ) ) ; }
Enables Consumerr error handlers
2,635
public static function initialize ( $ configuration = NULL ) { if ( $ configuration ) { self :: setConfiguration ( $ configuration ) ; } if ( ! self :: $ configuration instanceof Configuration ) { throw new InvalidConfigurationException ( "Consumerr is not properly configured." ) ; } if ( self :: $ enabled ) { self :: log ( "Multiple calls to initialize - ignore" ) ; return FALSE ; } if ( self :: $ configuration -> isClientDisabled ( ) ) { self :: log ( 'Client IP is disabled by current configuration.' ) ; return FALSE ; } if ( self :: $ configuration -> isCliDisabled ( ) ) { self :: log ( 'CLI is disabled by current configuration.' ) ; return FALSE ; } self :: $ enabled = TRUE ; self :: getTime ( ) ; $ errorPage = self :: $ configuration -> getErrorPage ( ) ; if ( $ errorPage !== false ) { ErrorHandler :: register ( $ errorPage ) ; } if ( ! self :: isConsole ( ) ) { if ( self :: $ configuration -> isAsyncEnabled ( ) ) { ob_start ( ) ; } self :: getAccess ( ) -> setUrl ( ( isset ( $ _SERVER [ 'HTTPS' ] ) && strcasecmp ( $ _SERVER [ 'HTTPS' ] , 'off' ) ? 'https://' : 'http://' ) . ( isset ( $ _SERVER [ 'HTTP_HOST' ] ) ? $ _SERVER [ 'HTTP_HOST' ] : ( isset ( $ _SERVER [ 'SERVER_NAME' ] ) ? $ _SERVER [ 'SERVER_NAME' ] : '' ) ) . $ _SERVER [ 'REQUEST_URI' ] ) ; if ( isset ( $ _SERVER [ 'SERVER_NAME' ] ) ) { self :: getAccess ( ) -> setServerName ( $ _SERVER [ 'SERVER_NAME' ] ) ; } if ( isset ( $ _SERVER [ 'REMOTE_ADDR' ] ) ) { self :: getAccess ( ) -> setRemoteAddr ( $ _SERVER [ 'REMOTE_ADDR' ] ) ; } if ( isset ( $ _SERVER [ 'SCRIPT_NAME' ] ) ) { self :: getAccess ( ) -> setName ( $ _SERVER [ 'SCRIPT_NAME' ] ) ; } if ( isset ( $ _SERVER [ 'REQUEST_METHOD' ] ) ) { self :: getAccess ( ) -> setMethod ( $ _SERVER [ 'REQUEST_METHOD' ] ) ; } if ( function_exists ( 'getallheaders' ) ) { self :: getAccess ( ) -> setHeaders ( getallheaders ( ) ) ; } if ( isset ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ) { self :: getAccess ( ) -> setUserAgent ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ; } } else { self :: getAccess ( ) -> setName ( self :: getCliArguments ( ) ) ; self :: getAccess ( ) -> setBackgroundJob ( TRUE ) ; } self :: registerSenderShutdownHandler ( ) ; return TRUE ; }
Initialize Consumerr WITHOUT enabling its error handlers . Usefull when error handling is done elsewhere .
2,636
public static function addErrorMessage ( $ message , $ num = E_USER_ERROR , $ file = '' , $ line = 0 , $ context = array ( ) ) { if ( is_array ( $ message ) ) { $ message = implode ( ' ' , $ message ) ; } $ exception = new \ ErrorException ( $ message , 0 , $ num , $ file , $ line ) ; $ exception -> context = $ context ; return self :: addError ( $ exception , true ) ; }
Adds PHP error
2,637
private function fclose ( ) { if ( $ this -> fp && is_resource ( $ this -> fp ) && ! is_resource ( $ this -> config -> savePath ) ) { fclose ( $ this -> fp ) ; } return $ this ; }
Closes the handler
2,638
private function doWrite ( $ level , $ message ) { $ this -> lastMessage = $ message ; $ this -> fopen ( ) ; if ( $ this -> fp && is_resource ( $ this -> fp ) ) { $ message = $ this -> buildMessage ( $ level , $ message ) ; $ this -> lastMessageFull = $ message ; $ ok = $ this -> config -> lock ? [ flock ( $ this -> fp , LOCK_EX ) , fwrite ( $ this -> fp , $ message ) , flock ( $ this -> fp , LOCK_UN ) ] : [ fwrite ( $ this -> fp , $ message ) ] ; return ! in_array ( false , $ ok , true ) ; } return false ; }
Performs the actual log operation .
2,639
private function fopen ( $ force = false ) { if ( $ force || ! $ this -> fp ) { $ this -> fclose ( ) ; $ this -> fp = is_resource ( $ this -> config -> savePath ) ? $ this -> config -> savePath : fopen ( $ this -> config -> savePath , 'ab' ) ; } return $ this ; }
Opens the file handler
2,640
protected function buildMessage ( $ level , $ text ) { $ trace = Alo :: ifnull ( $ this -> getBacktrace ( ) [ 1 ] , [ ] , true ) ; $ file = isset ( $ trace [ 'file' ] ) ? implode ( DIRECTORY_SEPARATOR , array_slice ( explode ( DIRECTORY_SEPARATOR , $ trace [ 'file' ] ) , - 2 ) ) : '<<unknown file>>' ; $ line = isset ( $ trace [ 'line' ] ) ? implode ( DIRECTORY_SEPARATOR , array_slice ( explode ( DIRECTORY_SEPARATOR , $ trace [ 'line' ] ) , - 2 ) ) : '<<unknown line>>' ; return $ level . ' ' . self :: SEPARATOR . ' ' . $ this -> time ( ) . ' ' . self :: SEPARATOR . ' ' . $ this -> config -> logLabel . ' ' . self :: SEPARATOR . ' ' . str_replace ( self :: SEPARATOR , '\\' . self :: SEPARATOR , $ text ) . ' ' . self :: SEPARATOR . ' ' . $ file . ' ' . self :: SEPARATOR . ' ' . $ line . PHP_EOL ; }
Builds the message as it will appear in the log file
2,641
protected function getBacktrace ( ) { $ trace = debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS ) ; if ( empty ( $ trace ) ) { return [ ] ; } else { foreach ( $ trace as $ k => $ v ) { foreach ( self :: $ ignoredFiles as $ i ) { if ( stripos ( Alo :: ifnull ( $ v [ 'file' ] , '' ) , $ i ) !== false ) { unset ( $ trace [ $ k ] ) ; break ; } } } } return array_values ( $ trace ) ; }
Returns the debug backtrace
2,642
protected static function replaceContext ( $ message , array $ context = [ ] ) { if ( empty ( $ context ) ) { return $ message ; } else { $ search = $ replace = [ ] ; foreach ( $ context as $ k => $ v ) { $ search [ ] = '{' . $ k . '}' ; $ replace [ ] = $ v ; } return str_ireplace ( $ search , $ replace , $ message ) ; } }
Replaces the placeholders in the message .
2,643
public function connect ( $ namespace = '' , $ level = 3 ) { if ( strtoupper ( substr ( PHP_OS , 0 , 3 ) ) === 'WIN' ) { $ connection = $ this -> com -> ConnectServer ( $ this -> getHost ( ) , $ namespace , $ this -> getDomain ( ) . $ this -> getUsername ( ) , $ this -> password ) ; } else { $ namespacePrepared = escapeshellarg ( $ namespace ) ; $ connection = "wmic -U " . $ this -> getDomain ( ) . $ this -> getUsername ( ) . " --password=" . $ this -> password . " //" . $ this -> getHost ( ) . " --namespace=" . $ namespacePrepared . " " ; } if ( $ connection ) { if ( strtoupper ( substr ( PHP_OS , 0 , 3 ) ) === 'WIN' ) { $ connection -> Security_ -> ImpersonationLevel = ( int ) $ level ; } $ this -> setConnection ( new Connection ( $ connection ) ) ; return $ this -> connection ; } return false ; }
Returns a new connection to the server using the current COM instance .
2,644
public static function map ( array $ array , $ method ) { if ( gettype ( $ method ) === 'object' ) { foreach ( $ array as $ key => $ value ) { $ array [ $ key ] = call_user_func_array ( $ method , [ $ key , $ value ] ) ; } return $ array ; } else { system :: add_error ( 'ary::map()' , 'missing_function' , 'second parameter must be a function object' ) ; } }
given and assign returning values to array s value
2,645
public static function flat ( array $ array ) { $ out = [ ] ; foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { $ out = array_merge ( $ out , self :: flat ( $ value ) ) ; } else { $ out [ ] = $ value ; } } return $ out ; }
combine these elements into a whole array
2,646
public function add ( $ postData , $ fileKey = false ) { $ postData [ 'post_type' ] = $ this -> postType ; $ newPostId = WP :: wpInsertPost ( $ postData ) ; if ( $ newPostId && ! WP :: isWpError ( $ newPostId ) ) { if ( is_uploaded_file ( $ _FILES [ $ fileKey ] [ 'tmp_name' ] ) ) { require_once ( ABSPATH . 'wp-admin/includes/image.php' ) ; require_once ( ABSPATH . 'wp-admin/includes/file.php' ) ; require_once ( ABSPATH . 'wp-admin/includes/media.php' ) ; $ attachmentId = WP :: mediaHandleUpload ( $ fileKey , $ newPostId ) ; if ( $ attachmentId && ! WP :: isWpError ( $ attachmentId ) ) { WP :: setPostThumbnail ( $ newPostId , $ attachmentId ) ; } } } return $ newPostId ; }
Creates a new post
2,647
protected function resolve ( $ class ) { if ( class_exists ( $ class ) === false ) { $ message = 'Job ' . $ class . ' is not found.' ; $ this -> log ( 'error' , $ message ) ; throw new JobNotFoundException ( $ message ) ; } elseif ( is_subclass_of ( $ class , 'Indigo\\Queue\\Job\\JobInterface' ) === false ) { throw new InvalidJobException ( $ class . 'is not a subclass of Indigo\\Queue\\Job\\JobInterface' ) ; } $ job = new $ class ; if ( isset ( $ job -> config ) ) { $ this -> config = array_merge ( $ this -> config , $ job -> config ) ; } return $ job ; }
Resolves the job class
2,648
protected function autoRetry ( ) { if ( $ this -> attempts ( ) <= $ this -> config [ 'retry' ] ) { return $ this -> connector -> release ( $ this , $ this -> config [ 'delay' ] ) ; } }
Tries to retry the job
2,649
public function header ( ) { $ tabSubHeader = '' ; $ tabHeader = $ this -> renderer -> view ( $ this -> headerContentView ) -> headName ( t ( $ this -> name , true ) ) -> headUrl ( '#' . $ this -> id ) -> set ( $ this -> size , 'subTabsCount' ) -> output ( ) ; if ( count ( $ this -> subTabs ) > 1 ) { foreach ( $ this -> subTabs as $ tab ) { $ tabSubHeader .= $ tab -> header ( ) ; } } return $ this -> renderer -> view ( $ this -> headerIndexView ) -> tabHeader ( $ tabHeader ) -> tabSubHeader ( $ tabSubHeader ) -> output ( ) ; }
Tab header rendering method
2,650
public function & push ( $ var ) { if ( is_object ( $ var ) && in_array ( 'Iterator' , class_implements ( $ var ) ) ) { return $ this -> append ( $ var ) ; } else { return $ this -> append ( new \ ArrayIterator ( func_get_args ( ) ) ) ; } }
Add an iterator or a value .
2,651
public function diff ( $ it , $ mode = self :: VALUE ) { switch ( $ mode ) { case self :: KEY : return Splash :: go ( ) -> append ( new \ ArrayIterator ( array_diff_key ( $ this -> toArray ( ) , ( array ) $ it ) ) ) ; case self :: KEY_ARRAY : return Splash :: go ( ) -> append ( new \ ArrayIterator ( array_diff_key ( $ this -> toArray ( ) , array_fill_keys ( ( array ) $ it , NULL ) ) ) ) ; case self :: VALUE : return Splash :: go ( ) -> append ( new \ ArrayIterator ( array_diff ( $ this -> toArray ( ) , ( array ) $ it ) ) ) ; case self :: KEYVALUE : return Splash :: go ( ) -> append ( new \ ArrayIterator ( array_diff_assoc ( $ this -> toArray ( ) , ( array ) $ it ) ) ) ; default : throw new \ InvalidArgumentException ( "Requested diff mode is unsupported." ) ; } }
Remove items from the iterator .
2,652
public function add ( string $ email , string $ name = null ) : void { $ bccRecipient = $ this -> make ( ) ; $ bccRecipient -> email = $ email ; if ( $ name !== null ) { $ bccRecipient -> name = $ name ; } $ this -> set ( $ bccRecipient ) ; }
Add a bcc recipient .
2,653
public function load ( array $ configs , ContainerBuilder $ container ) { $ loader = new XmlFileLoader ( $ container , new FileLocator ( __DIR__ . '/../Resources/config' ) ) ; $ loader -> load ( 'riak.xml' ) ; $ configuration = new Configuration ( ) ; $ config = $ this -> processConfiguration ( $ configuration , $ configs ) ; if ( empty ( $ config [ 'default_connection' ] ) ) { $ keys = array_keys ( $ config [ 'connections' ] ) ; $ config [ 'default_connection' ] = reset ( $ keys ) ; } $ container -> setParameter ( 'doctrine_riak.odm.default_connection' , $ config [ 'default_connection' ] ) ; if ( empty ( $ config [ 'default_document_manager' ] ) ) { $ keys = array_keys ( $ config [ 'document_managers' ] ) ; $ config [ 'default_document_manager' ] = reset ( $ keys ) ; } $ container -> setParameter ( 'doctrine_riak.odm.default_document_manager' , $ config [ 'default_document_manager' ] ) ; $ config = $ this -> overrideParameters ( $ config , $ container ) ; $ this -> loadConnections ( $ config [ 'connections' ] , $ container ) ; $ this -> loadDocumentManagers ( $ config [ 'document_managers' ] , $ config [ 'default_document_manager' ] , $ config [ 'default_database' ] , $ container ) ; if ( $ config [ 'resolve_target_documents' ] ) { $ def = $ container -> findDefinition ( 'doctrine_riak.odm.listeners.resolve_target_document' ) ; foreach ( $ config [ 'resolve_target_documents' ] as $ name => $ implementation ) { $ def -> addMethodCall ( 'addResolveTargetDocument' , array ( $ name , $ implementation , array ( ) ) ) ; } $ def -> addTag ( 'doctrine_riak.odm.event_listener' , array ( 'event' => 'loadClassMetadata' ) ) ; } }
Responds to the doctrine_riak configuration parameter .
2,654
protected function loadDocumentManagers ( array $ dmConfigs , $ defaultDM , $ defaultDB , ContainerBuilder $ container ) { $ dms = array ( ) ; foreach ( $ dmConfigs as $ name => $ documentManager ) { $ documentManager [ 'name' ] = $ name ; $ this -> loadDocumentManager ( $ documentManager , $ defaultDM , $ defaultDB , $ container ) ; $ dms [ $ name ] = sprintf ( 'doctrine_riak.odm.%s_document_manager' , $ name ) ; } $ container -> setParameter ( 'doctrine_riak.odm.document_managers' , $ dms ) ; }
Loads the document managers configuration .
2,655
public function setDescriptionHelper ( FormDescription $ descriptionHelper ) { $ descriptionHelper -> setView ( $ this -> getView ( ) ) ; $ this -> descriptionHelper = $ descriptionHelper ; return $ this ; }
Set description helper
2,656
public function getDescriptionHelper ( ) { if ( ! $ this -> descriptionHelper ) { $ this -> setDescriptionHelper ( $ this -> view -> plugin ( 'formdescription' ) ) ; } return $ this -> descriptionHelper ; }
Get description helper
2,657
protected function renderGroupWrapper ( ElementInterface $ element , $ id , $ control , $ wrapper = null ) { if ( ! $ wrapper ) { $ wrapper = $ this -> groupWrapper ; } $ addErrorClass = $ element -> getMessages ( ) ? ' has-error' : '' ; return sprintf ( $ wrapper , $ addErrorClass , $ id , $ control ) ; }
Render group wrapper
2,658
protected function renderControlWrapper ( $ id , $ element , $ elementString , $ description , $ wrapper = null ) { if ( ! $ wrapper ) { if ( $ element instanceof ButtonElement || $ element instanceof SubmitElement ) { return $ elementString . $ description ; } $ wrapper = $ this -> controlWrapper ; } return sprintf ( $ wrapper , $ id , $ elementString , $ description ) ; }
Render control wrapper
2,659
public function parse ( ) { $ scope_resource = $ this -> getScope ( ) ; if ( ! $ scope_resource instanceof AbstractResourceFile ) { throw new InvalidConfigException ( "INVALID scope resource file to parse." ) ; } $ contents = str_replace ( "\r" , "\n" , $ this -> contents ) ; $ annotation_lines = explode ( "\n" , $ contents ) ; foreach ( $ annotation_lines as $ annotation_line ) { $ annotation_line = trim ( $ annotation_line ) ; $ matches = array ( ) ; if ( '@' !== substr ( $ annotation_line , 0 , 1 ) ) { continue ; } $ this -> say ( $ annotation_line . '[' . $ this -> scope -> getRealPath ( ) . ']' ) ; if ( preg_match ( '#^@([a-zA-Z]+)\s(.+)$#' , $ annotation_line , $ matches ) ) { $ command_name = $ matches [ 1 ] ; $ params = $ matches [ 2 ] ; } elseif ( preg_match ( '#^@([0-9a-zA-Z\/\\\]+)\((.*)\)$#' , $ annotation_line , $ matches ) ) { $ command_name = $ matches [ 1 ] ; $ params = $ matches [ 2 ] ; } else { continue ; } if ( 'require' === strtolower ( $ command_name ) ) { $ command_annotation = new RequireAnnotation ( $ this ) ; } elseif ( 'use' === strtolower ( $ command_name ) ) { $ command_annotation = new UseAnnotation ( $ this ) ; } elseif ( class_exists ( $ command_name ) ) { $ command_annotation = new $ command_name ( $ this ) ; } else { continue ; } if ( $ command_annotation instanceof AbstractAnnotation ) { $ command_annotation -> parse ( $ params ) ; StaticsManager :: registAnnotation ( $ command_annotation ) ; } } }
The main parse processor for annotaion text
2,660
protected function getRealContainer ( ) { $ cont = $ this -> getContainer ( ) ; if ( $ cont instanceof DelegatorAwareInterface && $ cont -> hasDelegator ( ) ) { $ cont = $ cont -> getDelegator ( true ) ; } return $ cont ; }
Get container or its delegator
2,661
public function getResource ( string $ name , string $ entry = null ) { return $ this -> get ( 'resources' , $ name , $ entry ) ; }
Finds a resource entry in the manifest . json data .
2,662
public function getService ( string $ name , string $ entry = null ) { return $ this -> get ( 'services' , $ name , $ entry ) ; }
Finds a service entry in the manifest . json data .
2,663
private function AddItemsPerPageField ( ) { $ name = 'ItemsPerPage' ; $ val = $ this -> archive -> Exists ( ) ? $ this -> archive -> GetItemsPerPage ( ) : 10 ; $ this -> AddField ( Input :: Text ( $ name , $ val ) ) ; $ this -> SetRequired ( $ name ) ; $ this -> AddValidator ( $ name , new Integer ( 1 ) ) ; }
Adds the items per page field
2,664
private function AddDateFormatField ( ) { $ name = 'DateFormat' ; $ value = $ this -> archive -> GetDateFormat ( ) ? : Trans ( 'News.ArchiveForm.DateFormat.Default' ) ; $ field = Input :: Text ( $ name , $ value ) ; $ this -> AddField ( $ field ) ; $ this -> SetRequired ( $ name ) ; }
Adds the date format text field
2,665
private function AddMetaTitlePlacementField ( ) { $ name = 'MetaTitlePlacement' ; $ value = $ this -> archive -> GetMetaTitlePlacement ( ) ? : MetaPlacement :: Prepend ( ) -> Value ( ) ; $ this -> AddMetaPlacementSelect ( $ name , $ value ) ; }
Adds the meta title placement select field
2,666
private function AddMetaDescriptionPlacementField ( ) { $ name = 'MetaDescriptionPlacement' ; $ value = $ this -> archive -> GetMetaDescriptionPlacement ( ) ? : MetaPlacement :: Prepend ( ) -> Value ( ) ; $ this -> AddMetaPlacementSelect ( $ name , $ value ) ; }
Adds the meta descripton placement field
2,667
public function getIpV4 ( ) : ? string { if ( ! $ this -> hasIpV4 ( ) ) { $ this -> setIpV4 ( $ this -> getDefaultIpV4 ( ) ) ; } return $ this -> ipV4 ; }
Get ip v4
2,668
protected function getDefaultOptionsValues ( ) { return array ( 'data_class' => $ this -> mediaClass , 'delete_button' => false , 'enable_delete_button' => false , 'group_enabled' => true , 'group_render' => $ this -> groupRender , 'sub_group_render' => $ this -> subGroupRender ) ; }
Get Default OptionsValues
2,669
public function getOption ( $ option ) { if ( ! empty ( $ this -> options -> { $ option } ) ) { return $ this -> options -> { $ option } ; } return false ; }
Get one option
2,670
public function setFromUrl ( ) { $ cacheRebuild = true ; if ( $ this -> options -> cache ) { $ cacheKey = md5 ( $ this -> get ( ) ) ; $ cacheData = $ this -> cache -> get ( $ cacheKey ) ; if ( ! empty ( $ cacheData ) ) { $ cacheRebuild = false ; $ this -> set ( $ cacheData ) ; } } if ( $ cacheRebuild ) { $ dom = new \ PHPHtmlParser \ Dom ; $ dom -> load ( $ this -> url , $ this -> PHPHtmlParserOptions ) ; $ element = $ dom -> find ( $ this -> selector ) [ 0 ] ; if ( ! empty ( $ element ) ) { if ( ! empty ( $ this -> filter -> selector ) ) { $ newElement = new \ PHPHtmlParser \ Dom ; $ newElement -> load ( $ element -> outerHtml , $ this -> PHPHtmlParserOptions ) ; $ filter = $ newElement -> find ( $ this -> filter -> selector ) ; if ( ! empty ( $ filter ) ) { $ i = 0 ; foreach ( $ filter as $ item ) { if ( $ i >= $ this -> filter -> length ) { $ item -> delete ( ) ; } $ i ++ ; } } unset ( $ filter ) ; $ html = $ newElement -> outerHtml ; } else { $ html = $ element -> outerHtml ; } $ this -> set ( $ html ) ; if ( $ this -> options -> cache && ! empty ( $ cacheKey ) ) { $ this -> cache -> set ( $ cacheKey , $ html ) ; } } } return $ this ; }
Set markup from parsed result
2,671
public function actionViewBySlug ( $ slug ) { $ lh = $ this -> module -> langHelper ; $ language = $ lh :: normalizeLangCode ( Yii :: $ app -> language ) ; $ model = null ; $ modelI18n = $ this -> module -> model ( 'NewsI18n' ) -> findOne ( [ 'slug' => $ slug , 'lang_code' => $ language , ] ) ; if ( empty ( $ modelI18n ) ) { $ referer = Yii :: $ app -> request -> referrer ; $ hostInfo = Yii :: $ app -> request -> hostInfo ; if ( 0 === strpos ( $ referer , $ hostInfo ) ) { $ previousLanguage = substr ( $ referer , strlen ( $ hostInfo ) + 1 , 2 ) ; $ previousLanguage = $ lh :: normalizeLangCode ( $ previousLanguage ) ; $ modelI18n = $ this -> module -> model ( 'NewsI18n' ) -> findOne ( [ 'slug' => $ slug , 'lang_code' => $ previousLanguage , ] ) ; if ( ! empty ( $ modelI18n ) ) { $ model = $ modelI18n -> getMain ( ) -> one ( ) ; if ( ! empty ( $ model ) ) { $ modelsI18n = $ model :: prepareI18nModels ( $ model ) ; if ( ! empty ( $ modelsI18n [ $ language ] ) ) { $ newSlug = $ modelsI18n [ $ language ] -> slug ; $ result = Yii :: $ app -> getUrlManager ( ) -> parseRequest ( Yii :: $ app -> request ) ; if ( is_array ( $ result ) ) { list ( $ route , $ routeParams ) = $ result ; $ routeParams [ 0 ] = $ route ; $ routeParams [ 'lang' ] = $ language ; $ routeParams [ 'slug' ] = $ newSlug ; $ link = Yii :: $ app -> urlManager -> createUrl ( $ routeParams ) ; return $ this -> redirect ( $ link ) ; } } } } } } if ( ! empty ( $ modelI18n ) ) { $ contentHelper = new $ this -> contentHelperClass ; $ modelI18n -> body = $ contentHelper :: afterSelectBody ( $ modelI18n -> body ) ; $ model = $ modelI18n -> getMain ( ) -> one ( ) ; } $ searchModel = $ this -> module -> model ( 'NewsSearchFront' ) ; $ model = $ searchModel :: canShow ( $ model , $ modelI18n ) ; if ( ! $ model ) { $ modelI18n = false ; } return $ this -> render ( 'view' , compact ( 'model' , 'modelI18n' ) ) ; }
View by slug action
2,672
public function getRootName ( ) : string { $ className = \ get_class ( $ this ) ; if ( 'Bundle\\DependencyInjection\\Configuration' !== mb_substr ( $ className , - 40 ) ) { throw new BadMethodCallException ( 'This extension does not follow the naming convention; you must overwrite the getRootName() method.' ) ; } $ classBaseName = mb_substr ( $ className , 0 , mb_strlen ( $ className ) - 40 ) ; return mb_strtolower ( str_replace ( '\\' , '_' , $ classBaseName ) ) ; }
Return name like vendor_name from class name for Vendor \ NameBundle \ DependencyInjection \ Configuration .
2,673
public function getConfigTreeBuilder ( ) : TreeBuilder { $ rootName = $ this -> getRootName ( ) ; if ( method_exists ( TreeBuilder :: class , 'getRootNode' ) ) { $ treeBuilder = new TreeBuilder ( $ rootName ) ; $ rootNode = $ treeBuilder -> getRootNode ( ) ; } else { $ treeBuilder = new TreeBuilder ( ) ; $ rootNode = $ treeBuilder -> Root ( $ rootName ) ; } $ this -> build ( $ rootNode ) ; return $ treeBuilder ; }
Verify configuration .
2,674
public function view ( $ name ) { $ fullPath = $ name . ".phtml" ; $ directory = dirname ( $ fullPath ) ; $ globalDirPath = $ this -> appPath . "/Views/" . $ directory ; $ fileName = $ globalDirPath . "/" . basename ( $ fullPath ) ; if ( ! is_dir ( $ globalDirPath ) ) { mkdir ( $ globalDirPath , 0777 , true ) ; } if ( file_put_contents ( $ fileName , "<!-- Created by CLI ) ) { echo Utils :: colorize ( 'Create ' . $ fileName , 'SUCCESS' ) ; return true ; } else { echo Utils :: colorize ( 'Can\'t create ' . $ fileName , 'FAILURE' ) ; return false ; } }
Generate view file
2,675
public function template ( $ name ) { $ fullPath = $ name . ".phtml" ; $ directory = dirname ( $ fullPath ) ; $ globalDirPath = $ this -> appPath . "/Templates/" . $ directory ; $ fileName = $ globalDirPath . "/" . basename ( $ fullPath ) ; if ( ! is_dir ( $ globalDirPath ) ) { mkdir ( $ globalDirPath , 0777 , true ) ; } $ contents = array ( '<!DOCTYPE html>' ) ; $ contents [ ] = '<html>' ; $ contents [ ] = ' <head>' ; $ contents [ ] = ' <meta charset="utf-8"/>' ; $ contents [ ] = ' <title></title>' ; $ contents [ ] = ' <script type="text/javascript" src=""></script>' ; $ contents [ ] = ' <link rel="stylesheet" type="text/css" href="">' ; $ contents [ ] = ' </head>' ; $ contents [ ] = ' <body>' ; $ contents [ ] = ' <?php $this->content()?>' ; $ contents [ ] = ' </body>' ; $ contents [ ] = '</html>' ; if ( file_put_contents ( $ fileName , implode ( "\n" , $ contents ) ) ) { echo Utils :: colorize ( 'Create ' . $ fileName , 'SUCCESS' ) ; return true ; } else { echo Utils :: colorize ( 'Can\'t create ' . $ fileName , 'FAILURE' ) ; return false ; } }
Generate template file
2,676
public function controller ( $ name ) { $ fileName = "{$name}.php" ; if ( isset ( $ this -> arguments [ 2 ] ) ) { $ actions = explode ( ',' , $ this -> arguments [ 2 ] ) ; if ( count ( $ actions ) == 0 ) { $ actions = array ( 'index' ) ; } } else { $ actions = array ( 'index' ) ; } $ file = $ this -> appPath . "/Controllers/" . $ fileName ; $ class = $ name ; $ date = date ( "n/j/Y" ) ; $ contents = array ( '<?php' ) ; $ contents [ ] = '/*' ; $ contents [ ] = " * {$name} controller" ; $ contents [ ] = ' *' ; $ contents [ ] = ' * @author ' ; $ contents [ ] = ' * @version 1.0' ; $ contents [ ] = " * @date $date" ; $ contents [ ] = ' */' ; $ contents [ ] = '' ; $ contents [ ] = 'namespace Controllers;' ; $ contents [ ] = 'use \Core\Controller;' ; $ contents [ ] = '' ; $ contents [ ] = 'class ' . $ class . ' extends Controller' ; $ contents [ ] = '{' ; foreach ( $ actions as $ action ) { $ contents [ ] = "" ; $ contents [ ] = " public function " . $ action . "Action()" ; $ contents [ ] = " {" ; $ contents [ ] = " " ; $ contents [ ] = " }" ; $ contents [ ] = "" ; } $ contents [ ] = '}' ; if ( file_put_contents ( $ file , implode ( "\n" , $ contents ) ) ) { echo Utils :: colorize ( 'Create ' . $ file , 'SUCCESS' ) ; return true ; } else { echo Utils :: colorize ( 'Can\'t create ' . $ file , 'FAILURE' ) ; return false ; } }
Generate new controller with actions
2,677
public function model ( $ name , $ primaryKey ) { $ fileName = "{$name}.php" ; $ tableName = strtolower ( $ name ) ; $ class = $ name ; $ date = date ( "n/j/Y" ) ; $ fileTable = $ this -> appPath . "/Models/Table/" . $ fileName ; $ fileRow = $ this -> appPath . "/Models/Row/" . $ fileName ; $ contentsT = array ( '<?php' ) ; $ contentsT [ ] = '/*' ; $ contentsT [ ] = " * {$name} table model" ; $ contentsT [ ] = ' *' ; $ contentsT [ ] = ' * @author ' ; $ contentsT [ ] = ' * @version 1.0' ; $ contentsT [ ] = " * @date $date" ; $ contentsT [ ] = ' */' ; $ contentsT [ ] = '' ; $ contentsT [ ] = 'namespace Models\Table;' ; $ contentsT [ ] = 'use Core\Orm\TableGateway;' ; $ contentsT [ ] = '' ; $ contentsT [ ] = 'class ' . $ class . ' extends TableGateway' ; $ contentsT [ ] = "{" ; $ contentsT [ ] = " protected \$_name = '{$tableName}';" ; $ contentsT [ ] = " protected \$_primary = '{$primaryKey}';" ; $ contentsT [ ] = " protected \$_rowClass = 'Models\Row\$class';" ; $ contentsT [ ] = "" ; $ contentsT [ ] = '}' ; if ( file_put_contents ( $ fileTable , implode ( "\n" , $ contentsT ) ) ) { echo Utils :: colorize ( 'Create ' . $ fileTable , 'SUCCESS' ) ; } else { echo Utils :: colorize ( 'Can\'t create ' . $ fileTable , 'FAILURE' ) ; } $ contentsR = array ( '<?php' ) ; $ contentsR [ ] = '/*' ; $ contentsR [ ] = " * {$name} row model" ; $ contentsR [ ] = ' *' ; $ contentsR [ ] = ' * @author ' ; $ contentsR [ ] = ' * @version 1.0' ; $ contentsR [ ] = " * @date $date" ; $ contentsR [ ] = ' */' ; $ contentsR [ ] = '' ; $ contentsR [ ] = 'namespace Models\Row;' ; $ contentsR [ ] = 'use Core\Orm\RowGateway;' ; $ contentsR [ ] = '' ; $ contentsR [ ] = 'class ' . $ class . ' extends RowGateway' ; $ contentsR [ ] = "{" ; $ contentsR [ ] = "" ; $ contentsR [ ] = '}' ; if ( file_put_contents ( $ fileRow , implode ( "\n" , $ contentsR ) ) ) { echo Utils :: colorize ( 'Create ' . $ fileRow , 'SUCCESS' ) ; return true ; } else { echo Utils :: colorize ( 'Can\'t create ' . $ fileRow , 'FAILURE' ) ; return false ; } }
Generate new model
2,678
public function withScheme ( string $ scheme ) : UriInterface { $ scheme = $ this -> marshalScheme ( $ scheme ) ; if ( $ this -> scheme === $ scheme ) { return $ this ; } $ instance = clone $ this ; $ instance -> scheme = $ scheme ; $ instance -> calibratePort ( ) ; return $ instance ; }
creates a new instance of the current exact uri and changes the scheme to the provided string .
2,679
public function withHost ( string $ host ) : UriInterface { $ instance = clone $ this ; $ instance -> host = $ this -> marshalHost ( $ host ) ; return $ instance ; }
creates a new instance of the current exact uri and changes the host name to the provided host string .
2,680
public function getPort ( ) : ? int { if ( $ this -> port === null ) { return self :: DEFAULT_PORTS [ $ this -> scheme ?? '' ] ?? null ; } return $ this -> port ; }
returns the port of the uri if any otherwise null .
2,681
public function doesImplementPort ( ) : bool { if ( $ this -> port === null ) { return array_key_exists ( $ this -> scheme , self :: DEFAULT_PORTS ) ; } return true ; }
checks whether a default port is not omitted when constructing the uri string .
2,682
public function withPort ( int $ port ) : UriInterface { $ instance = clone $ this ; $ instance -> port = $ this -> marshalPort ( $ port ) ; return $ instance ; }
creates a new instance of the current exact uri and changes the port to the provided port integer .
2,683
public function withPath ( string $ path ) : UriInterface { $ instance = clone $ this ; $ instance -> path = $ this -> marshalPath ( $ path ) ; return $ instance ; }
creates a new instance of the current exact uri and changes the path to the provided path string .
2,684
public function withQuery ( string $ query ) : UriInterface { $ query = $ this -> marshalQueryAndFragment ( $ query ) ; if ( $ this -> query === $ query ) { return $ this ; } $ instance = clone $ this ; $ instance -> query = $ query ; return $ instance ; }
creates a new instance of the current exact uri and changes the query to the provided query string .
2,685
public function withQueryFromArray ( array $ data ) : UriInterface { $ query = http_build_query ( $ data ) ; if ( $ this -> query === $ query ) { return $ this ; } $ instance = clone $ this ; $ instance -> query = $ query ; return $ instance ; }
creates a new instance of the current exact uri and changes the query to the provided query array string representation .
2,686
public function withFragment ( string $ fragment ) : UriInterface { $ instance = clone $ this ; $ instance -> fragment = $ this -> marshalQueryAndFragment ( $ fragment ) ; return $ instance ; }
creates a new instance of the current exact uri and changes the fragment to the provided fragment string .
2,687
public function getUri ( ) : string { $ uri = '' ; if ( null !== $ this -> scheme ) { $ uri .= $ this -> scheme . ':' ; } $ authority = $ this -> getAuthority ( ) ; if ( null !== $ authority || $ this -> scheme === 'file' ) { $ uri .= '//' . $ authority ; } $ uri .= $ this -> path ; if ( null !== $ this -> query ) { $ uri .= '?' . $ this -> query ; } if ( null !== $ this -> fragment ) { $ uri .= '#' . $ this -> fragment ; } return $ uri ; }
renders the uri based on the currently known data .
2,688
protected function marshalInstance ( array $ parts ) { $ this -> scheme = array_key_exists ( 'scheme' , $ parts ) ? $ this -> marshalScheme ( $ parts [ 'scheme' ] ) : '' ; $ this -> userInfo = $ parts [ 'user' ] ?? null ; if ( array_key_exists ( 'pass' , $ parts ) ) { $ this -> userInfo .= ':' . $ parts [ 'pass' ] ; } $ this -> host = array_key_exists ( 'host' , $ parts ) ? $ this -> marshalHost ( $ parts [ 'host' ] ) : $ this -> host ; $ this -> port = array_key_exists ( 'port' , $ parts ) ? $ this -> marshalPort ( $ parts [ 'port' ] ) : null ; $ this -> path = array_key_exists ( 'path' , $ parts ) ? $ this -> marshalPath ( $ parts [ 'path' ] ) : '/' ; $ this -> query = array_key_exists ( 'query' , $ parts ) ? $ this -> marshalQueryAndFragment ( $ parts [ 'query' ] ) : null ; $ this -> fragment = array_key_exists ( 'fragment' , $ parts ) ? $ this -> marshalQueryAndFragment ( $ parts [ 'fragment' ] ) : null ; if ( empty ( $ this -> scheme ) && ! array_key_exists ( 'host' , $ parts ) && ! array_key_exists ( 'port' , $ parts ) ) { $ this -> scheme = 'http' ; } $ this -> calibratePort ( ) ; }
marshals the instance of this uri .
2,689
protected function calibratePort ( ) { if ( $ this -> port === null && $ this -> scheme !== null && array_key_exists ( $ this -> scheme , self :: DEFAULT_PORTS ) ) { $ this -> port = self :: DEFAULT_PORTS [ $ this -> scheme ] ; } }
calibrates the port setup of this uri .
2,690
function bind ( iEvent $ event ) { $ eventName = $ event -> getName ( ) ; if ( $ this -> has ( $ event ) ) throw new \ Exception ( sprintf ( 'Events with name "%s" is registered before.' , $ eventName ) ) ; if ( $ this -> meeter !== null ) $ event -> setMeeter ( $ this -> meeter ) ; $ this -> attached_events [ $ eventName ] = $ event ; return $ this ; }
Bind an event to this event
2,691
function bindShare ( iEvent $ event ) { $ event -> collector ( ) -> import ( $ this -> collector ( ) ) ; $ this -> bind ( $ event ) ; return $ this ; }
Bind an event to this event and share collector
2,692
function trigger ( $ event , $ bp = null , $ pb = null ) { if ( $ this -> isShutdown ( ) ) return $ this ; $ Collector = $ this -> collector ( ) ; if ( $ bp === null ) $ bp = $ Collector ; elseif ( $ bp instanceof iData || is_array ( $ bp ) ) $ bp = $ Collector -> import ( $ bp ) ; if ( is_string ( $ event ) || $ event instanceof iEvent ) $ event = array ( $ event ) ; else if ( ! is_array ( $ event ) ) throw new \ InvalidArgumentException ( sprintf ( 'Events must be a string or iEvent instance, or array of these two.' ) ) ; foreach ( $ event as $ e ) { $ event = $ this -> byEvent ( $ e ) ; $ event = clone $ event ; try { $ event = $ event -> emit ( $ bp , $ pb ) ; } catch ( \ Exception $ exception ) { if ( $ this -> failure ) { call_user_func ( $ this -> failure , $ exception , $ this ) ; return $ this ; } throw $ exception ; } $ Collector -> import ( $ event -> collector ( ) ) ; } return $ this ; }
Helper To Emit Events Listener
2,693
function shutdown ( ) { foreach ( $ this -> listEvents ( ) as $ event ) $ this -> byEvent ( $ event ) -> stopPropagation ( ) ; $ this -> stopPropagation ( ) ; $ this -> isShutdown = true ; return $ this ; }
Shutdown all listeners attached to all events
2,694
function unbind ( $ event ) { ( ! $ event instanceof iEvent ) ? : $ event = $ event -> getName ( ) ; unset ( $ this -> attached_events [ ( string ) $ event ] ) ; return $ this ; }
Un - Register an event
2,695
function byEvent ( $ event ) { if ( ! $ this -> has ( $ event ) ) { if ( $ event instanceof iEvent ) $ this -> bind ( $ event ) ; else throw new \ Exception ( "Events ({$event}) not found." ) ; } $ event = ( $ event instanceof iEvent ) ? $ event -> getName ( ) : $ event ; $ event = $ this -> attached_events [ $ event ] ; if ( $ this -> meeter ) $ event -> setMeeter ( $ this -> meeter ) ; return $ event ; }
Find an event object by name
2,696
public static function toJson ( $ data , $ options = array ( ) ) { $ defaults = array ( 'hide' => array ( 'password' ) ) ; $ options = array_merge ( $ defaults , $ options ) ; if ( ! is_array ( $ data ) ) { $ data = Arr :: convert ( $ data ) ; } foreach ( $ data as $ k => $ v ) { $ data [ $ k ] = Arr :: convert ( $ v ) ; } if ( isset ( $ options [ 'hide' ] ) and is_array ( $ data ) ) { $ data = Arr :: removeKeys ( $ data , $ options [ 'hide' ] ) ; } return json_encode ( $ data ) ; }
Returns the JSON encoded version of the passed data .
2,697
public function neighbourAddressTypes ( $ translate = false ) { $ types = $ this -> getSNMP ( ) -> subOidWalk ( self :: OID_CDP_CACHE_NEIGHBOUR_ADDRESS_TYPE , 15 ) ; if ( ! $ translate ) return $ types ; return $ this -> getSNMP ( ) -> translate ( $ types , self :: $ CDP_CACHE_NEIGHBOUR_ADDRESS_TYPES ) ; }
Get the CDP neighbours address type indexed by the current device s port ID
2,698
public function neighbourAddresses ( ) { $ addresses = $ this -> getSNMP ( ) -> subOidWalk ( self :: OID_CDP_CACHE_NEIGHBOUR_ADDRESS , 15 ) ; foreach ( $ addresses as $ portId => $ address ) { if ( strlen ( $ address ) == 8 && $ this -> neighbourAddressTypes ( ) [ $ portId ] == self :: CDP_CACHE_NEIGHBOUR_ADDRESS_TYPE_IP ) $ addresses [ $ portId ] = long2ip ( hexdec ( $ address ) ) ; } return $ addresses ; }
Get the device s CDP neighbour addresses indexed by the current device s port ID
2,699
public function crawl ( & $ devices = array ( ) , $ device = null , $ ignore = array ( ) ) { if ( ! count ( $ devices ) ) { $ device = $ this -> id ( ) ; $ devices [ $ device ] = $ this -> neighbours ( true , $ ignore ) ; } foreach ( $ devices [ $ device ] as $ feNeighbour => $ feConnections ) { if ( in_array ( $ feNeighbour , $ ignore ) ) { if ( isset ( $ devices [ $ device ] [ $ feNeighbour ] ) ) unset ( $ devices [ $ device ] [ $ feNeighbour ] ) ; continue ; } if ( ! isset ( $ devices [ $ feNeighbour ] ) ) { $ snmp = new \ Cityware \ Snmp \ SNMP ( $ feNeighbour , $ this -> getSNMP ( ) -> getCommunity ( ) ) ; try { $ devices [ $ feNeighbour ] = $ snmp -> useCisco_CDP ( ) -> neighbours ( true , $ ignore ) ; unset ( $ snmp ) ; $ this -> crawl ( $ devices , $ feNeighbour , $ ignore ) ; } catch ( \ Cityware \ Snmp \ Exception $ e ) { unset ( $ devices [ $ feNeighbour ] ) ; } } } return $ devices ; }
Recursivily crawls all CDP neighbours to build up a flat array of all devices indexed by the CDP device id .