idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
53,800
public function addItem ( Item $ item ) { if ( $ this -> has ( $ item -> name ) ) { throw new DuplicateItemNameException ( sprintf ( 'An item with name `%s` already exists in the menu `%s`' , $ item -> name , $ item -> menu -> name ) ) ; } return $ this -> put ( $ item -> name , $ item ) ; }
Add new Item to the collection . Performs check for name uniqueness
53,801
public function remove ( $ item ) { $ key = $ item instanceof Item ? $ item -> name : $ item ; if ( $ this -> has ( $ key ) ) { $ this -> forget ( $ key ) ; return true ; } return false ; }
Remove an item from the list
53,802
public function attr ( ... $ args ) { $ this -> each ( function ( $ item ) use ( $ args ) { $ item -> attr ( ... $ args ) ; } ) ; return $ this ; }
Add attributes to a collection of items
53,803
public function data ( ... $ args ) { $ this -> each ( function ( $ item ) use ( $ args ) { $ item -> data ( ... $ args ) ; } ) ; return $ this ; }
Add meta data to a collection of items
53,804
public function appendHtml ( $ html ) { $ this -> each ( function ( $ item ) use ( $ html ) { $ item -> title .= $ html ; } ) ; return $ this ; }
Appends text or HTML to a collection of items
53,805
public function prependHtml ( $ html ) { $ this -> each ( function ( $ item ) use ( $ html ) { $ item -> title = $ html . $ item -> title ; } ) ; return $ this ; }
Prepends text or HTML to a collection of items
53,806
public function addSubItem ( $ name , $ title , $ options = [ ] ) { $ options = is_array ( $ options ) ? $ options : [ 'url' => $ options ] ; $ options [ 'parent' ] = $ this ; return $ this -> menu -> addItem ( $ name , $ title , $ options ) ; }
Creates a sub Item
53,807
public function isAllowed ( Authenticatable $ user = null ) : bool { $ user = $ user ? : Auth :: user ( ) ; foreach ( $ this -> authorizationStack as $ auth ) { if ( is_callable ( $ auth ) ) { if ( ! $ auth ( $ user ) ) { return false ; } } elseif ( $ user && $ user -> cannot ( $ auth ) ) { return false ; } } return tr...
Returns whether the menu item is allowed for the user
53,808
public function children ( ) { return $ this -> menu -> items -> filter ( function ( $ item ) { return $ item -> hasParent ( ) && $ item -> parent -> name == $ this -> name ; } ) ; }
Returns children of the item
53,809
public function childrenAllowed ( Authenticatable $ user = null ) { return $ this -> children ( ) -> filter ( function ( $ item ) use ( $ user ) { return $ item -> isAllowed ( $ user ) ; } ) ; }
Returns allowed children of the item
53,810
public function activate ( ) { if ( $ this -> menu -> config -> activeElement == 'item' ) { $ this -> setToActive ( ) ; } else { if ( $ this -> link ) { $ this -> link -> activate ( ) ; } } if ( $ this -> menu -> config -> activateParents ) { if ( $ this -> parent ) { $ this -> parent -> activate ( ) ; } } }
Sets the item as active
53,811
public function data ( ... $ args ) { if ( isset ( $ args [ 0 ] ) && is_array ( $ args [ 0 ] ) ) { $ this -> data = array_merge ( $ this -> data , array_change_key_case ( $ args [ 0 ] ) ) ; if ( $ this -> menu -> config -> cascadeData ) { $ this -> cascadeData ( ... $ args ) ; } return $ this ; } elseif ( isset ( $ arg...
Set or get items s meta data
53,812
public function hasProperty ( $ property ) { return property_exists ( $ this , $ property ) || $ this -> hasAttribute ( $ property ) || $ this -> hasData ( $ property ) ; }
Check if property exists either in the class or the meta collection
53,813
protected function setToActive ( ) { $ this -> attributes [ 'class' ] = Utils :: addHtmlClass ( array_get ( $ this -> attributes , 'class' ) , $ this -> menu -> config -> activeClass ) ; $ this -> isActive = true ; return $ this ; }
Make the item active
53,814
protected function currentUrlMatches ( ) { if ( $ this -> url ( ) == Request :: url ( ) ) { return true ; } if ( $ this -> activeUrlPattern ) { $ pattern = ltrim ( preg_replace ( '/\/\*/' , '(/.*)?' , $ this -> activeUrlPattern ) , '/' ) ; return preg_match ( "@^{$pattern}\z@" , Request :: path ( ) ) ; } return false ;...
Returns whether the current URL matches this link s URL
53,815
public function create ( $ name , $ options = [ ] ) { if ( $ this -> menus -> has ( $ name ) ) { throw new MenuAlreadyExistsException ( "Can not create menu named `$name` because it already exists" ) ; } $ this -> menus -> put ( $ name , $ instance = MenuFactory :: create ( $ name , $ options ) ) ; return $ instance ; ...
Create a new menu instance
53,816
public function addItem ( $ name , $ title , $ options = [ ] ) { $ options = is_string ( $ options ) ? [ 'url' => $ options ] : $ options ; $ item = new Item ( $ this , $ name , $ title , $ options ) ; $ this -> items -> addItem ( $ item ) ; return $ item ; }
Adds an item to the menu
53,817
public function removeItem ( string $ name , $ removeChildren = true ) { if ( $ removeChildren ) { if ( $ item = $ this -> getItem ( $ name ) ) { $ item -> children ( ) -> each ( function ( $ item ) { $ this -> removeItem ( $ item -> name ) ; } ) ; } } return $ this -> items -> remove ( $ name ) ; }
Remove a menu item by name
53,818
public function activate ( ) { $ this -> isActive = true ; $ this -> attributes [ 'class' ] = Utils :: addHtmlClass ( array_get ( $ this -> attributes , 'class' , '' ) , $ this -> activeClass ) ; return $ this ; }
Make the anchor active
53,819
public function url ( ) { if ( ! is_null ( $ this -> href ) ) { return $ this -> href ; } elseif ( isset ( $ this -> path [ 'url' ] ) ) { return $ this -> getUrl ( ) ; } elseif ( isset ( $ this -> path [ 'route' ] ) ) { return $ this -> getRoute ( ) ; } elseif ( isset ( $ this -> path [ 'action' ] ) ) { return $ this -...
Return the URL for the link
53,820
protected function getUrl ( ) { $ url = $ this -> path [ 'url' ] ; $ uri = is_array ( $ url ) ? $ url [ 0 ] : $ url ; $ params = is_array ( $ url ) ? array_slice ( $ url , 1 ) : null ; if ( Utils :: isAbsoluteUrl ( $ uri ) ) { return $ uri ; } return url ( $ uri , $ params ) ; }
Get the action for url option .
53,821
protected function getRoute ( ) { $ route = $ this -> path [ 'route' ] ; if ( is_array ( $ route ) ) { return route ( $ route [ 0 ] , array_slice ( $ route , 1 ) ) ; } return route ( $ route ) ; }
Get the url for a route option .
53,822
protected function getControllerAction ( ) { $ action = $ this -> path [ 'action' ] ; if ( is_array ( $ action ) ) { return action ( $ action [ 0 ] , array_slice ( $ action , 1 ) ) ; } return action ( $ action ) ; }
Get the url for an action option
53,823
public function setNotifyLevel ( $ notifyLevel ) { if ( ! in_array ( $ notifyLevel , $ this -> getLogLevelOrder ( ) ) ) { syslog ( LOG_WARNING , 'Bugsnag Warning: Invalid notify level supplied to Bugsnag Logger' ) ; } else { $ this -> notifyLevel = $ notifyLevel ; } }
Set the notifyLevel of the logger as defined in Psr \ Log \ LogLevel .
53,824
protected function aboveLevel ( $ level , $ base ) { $ levelOrder = $ this -> getLogLevelOrder ( ) ; $ baseIndex = array_search ( $ base , $ levelOrder ) ; $ levelIndex = array_search ( $ level , $ levelOrder ) ; return $ levelIndex >= $ baseIndex ; }
Checks whether the selected level is above another level .
53,825
public static function createWithConfig ( array $ config = [ ] ) { $ plates = new self ( ) ; $ plates -> register ( new PlatesExtension ( ) ) ; $ plates -> register ( new Extension \ Data \ DataExtension ( ) ) ; $ plates -> register ( new Extension \ Path \ PathExtension ( ) ) ; $ plates -> register ( new Extension \ R...
Create a configured engine and pass in an array to configure after extension registration
53,826
public function fork ( $ name , array $ data = [ ] , array $ attributes = [ ] ) { return new self ( $ name , $ data , $ attributes , null , $ this -> reference ) ; }
Create a new template based off of this current one
53,827
protected function doMap ( $ source , $ destination , MappingInterface $ mapping , array $ context = [ ] ) { $ propertyNames = $ mapping -> getTargetProperties ( $ destination , $ source ) ; foreach ( $ propertyNames as $ propertyName ) { $ mappingOperation = $ mapping -> getMappingOperationFor ( $ propertyName ) ; if ...
Performs the actual transferring of properties .
53,828
protected function getSourcePropertyName ( string $ propertyName ) : string { return $ this -> nameResolver -> getSourcePropertyName ( $ propertyName , $ this , $ this -> options ) ; }
Returns the name of the property we should fetch from the source object .
53,829
public static function mapTo ( string $ destinationClass , bool $ sourceIsObjectArray = false , array $ context = [ ] ) : MapTo { return new MapTo ( $ destinationClass , $ sourceIsObjectArray , $ context ) ; }
Map a property to a class .
53,830
protected function getMostSpecificCandidate ( array $ candidates , string $ sourceClassName , string $ destinationClassName ) : ? MappingInterface { $ lowestDistance = PHP_INT_MAX ; $ selectedCandidate = null ; foreach ( $ candidates as $ candidate ) { $ sourceDistance = $ this -> getClassDistance ( $ sourceClassName ,...
Searches the most specific candidate in the list . This means the mapping that is closest to the given source and destination in the inheritance chain .
53,831
protected function getClassDistance ( string $ childClass , string $ parentClass ) : int { if ( $ childClass === $ parentClass ) { return 0 ; } $ result = 0 ; $ childParents = class_parents ( $ childClass , true ) ; foreach ( $ childParents as $ childParent ) { $ result ++ ; if ( $ childParent === $ parentClass ) { ret...
Returns the distance in the inheritance chain between 2 classes .
53,832
protected function getPrivate ( $ object , string $ propertyName ) { $ objectArray = ( array ) $ object ; foreach ( $ objectArray as $ name => $ value ) { if ( substr ( $ name , - \ strlen ( $ propertyName ) - 1 ) === "\x00" . $ propertyName ) { return $ value ; } } return null ; }
Abuses PHP s internal representation of properties when casting an object to an array .
53,833
private function isPublic ( $ object , string $ propertyName ) : bool { $ objectArray = ( array ) $ object ; return array_key_exists ( $ propertyName , $ objectArray ) ; }
Checks if the given property is public .
53,834
public static function wrap ( $ text , $ left_margin = 0 , $ right_margin = 0 , $ width = null ) { if ( empty ( $ width ) ) { $ width = self :: getWidth ( ) ; } $ width = $ width - abs ( $ left_margin ) - abs ( $ right_margin ) ; $ margin = str_repeat ( ' ' , $ left_margin ) ; return $ margin . wordwrap ( $ text , $ wi...
Wrap text for printing
53,835
public static function pad ( $ text , $ width , $ pad = ' ' , $ mode = STR_PAD_RIGHT ) { $ width = strlen ( $ text ) - mb_strlen ( $ text , 'UTF-8' ) + $ width ; return str_pad ( $ text , $ width , $ pad , $ mode ) ; }
A UT8 compatible string pad
53,836
public function setNeeds ( $ option ) { if ( ! is_array ( $ option ) ) { $ option = array ( $ option ) ; } foreach ( $ option as $ opt ) { $ this -> needs [ ] = $ opt ; } return $ this ; }
Set an option as required
53,837
public function hasNeeds ( $ optionsList ) { $ needs = $ this -> getNeeds ( ) ; $ definedOptions = array_keys ( $ optionsList ) ; $ notFound = array ( ) ; foreach ( $ needs as $ need ) { if ( ! in_array ( $ need , $ definedOptions ) ) { $ notFound [ ] = $ need ; } elseif ( ! $ optionsList [ $ need ] -> getValue ( ) ) {...
Check to see if requirements list for option are met
53,838
function text ( ) { if ( isset ( $ this -> _ [ HDOM_INFO_INNER ] ) ) return $ this -> _ [ HDOM_INFO_INNER ] ; switch ( $ this -> nodetype ) { case HDOM_TYPE_TEXT : return $ this -> dom -> restore_noise ( $ this -> _ [ HDOM_INFO_TEXT ] ) ; case HDOM_TYPE_COMMENT : return '' ; case HDOM_TYPE_UNKNOWN : return '' ; } if ( ...
get dom node s plain text
53,839
function makeup ( ) { if ( isset ( $ this -> _ [ HDOM_INFO_TEXT ] ) ) return $ this -> dom -> restore_noise ( $ this -> _ [ HDOM_INFO_TEXT ] ) ; $ ret = '<' . $ this -> tag ; $ i = - 1 ; foreach ( $ this -> attr as $ key => $ val ) { ++ $ i ; if ( $ val === null || $ val === false ) continue ; $ ret .= $ this -> _ [ HD...
build node s text with tag
53,840
function find ( $ selector , $ idx = null , $ lowercase = false ) { $ selectors = $ this -> parse_selector ( $ selector ) ; if ( ( $ count = count ( $ selectors ) ) === 0 ) return array ( ) ; $ found_keys = array ( ) ; for ( $ c = 0 ; $ c < $ count ; ++ $ c ) { if ( ( $ levle = count ( $ selectors [ $ c ] ) ) === 0 ) r...
PaperG - added ability for find to lowercase the value of the selector .
53,841
public function getUrl ( $ page ) { $ request = Craft :: $ app -> getRequest ( ) ; parse_str ( $ request -> getQueryString ( ) , $ params ) ; $ pathParam = Craft :: $ app -> getConfig ( ) -> getGeneral ( ) -> pathParam ; unset ( $ params [ $ pathParam ] , $ params [ 'pattern' ] ) ; $ params [ $ this -> pageParam ] = $ ...
Get the url for the given page .
53,842
private function _currentPage ( ) : int { $ currentPage = Craft :: $ app -> getRequest ( ) -> getQueryParam ( $ this -> pageParam , 1 ) ; if ( is_numeric ( $ currentPage ) && $ currentPage > $ this -> totalPages ) { $ currentPage = $ this -> totalPages > 0 ? $ this -> totalPages : 1 ; } else if ( ! is_numeric ( $ curre...
Determines the current page .
53,843
protected function getTransformer ( ) { if ( is_callable ( $ this -> transformer ) || $ this -> transformer instanceof TransformerAbstract ) { return $ this -> transformer ; } return Craft :: createObject ( $ this -> transformer ) ; }
Returns the transformer based on the given endpoint
53,844
public function getDefaultResourceAdapterConfig ( ) : array { if ( $ this -> _defaultResourceAdapterConfig !== null ) { return $ this -> _defaultResourceAdapterConfig ; } return $ this -> _defaultResourceAdapterConfig = $ this -> getSettings ( ) -> defaults ; }
Returns the default endpoint configuration .
53,845
public function registerUrlRules ( RegisterUrlRulesEvent $ event ) { foreach ( $ this -> getSettings ( ) -> endpoints as $ pattern => $ config ) { $ event -> rules [ $ pattern ] = [ 'route' => 'element-api' , 'defaults' => [ 'pattern' => $ pattern ] , ] ; } }
Registers the site URL rules .
53,846
public function createResource ( $ config ) : ResourceInterface { if ( $ config instanceof ResourceInterface ) { return $ config ; } if ( $ config instanceof ResourceAdapterInterface ) { return $ config -> getResource ( ) ; } if ( ! isset ( $ config [ 'class' ] ) ) { $ config [ 'class' ] = ElementResource :: class ; } ...
Creates a Fractal resource based on the given config .
53,847
private function _callWithParams ( $ func , $ params ) { if ( empty ( $ params ) ) { return $ func ( ) ; } $ ref = new ReflectionFunction ( $ func ) ; $ args = [ ] ; foreach ( $ ref -> getParameters ( ) as $ param ) { $ name = $ param -> getName ( ) ; if ( isset ( $ params [ $ name ] ) ) { if ( $ param -> isArray ( ) )...
Calls a given function . If any params are given they will be mapped to the function s arguments .
53,848
public function addLoader ( $ id , $ loader ) { if ( ! array_key_exists ( $ id , $ this -> loaders ) ) { $ this -> loaders [ $ id ] = $ loader ; } }
Add a translation loader if it does not exist .
53,849
public function dump ( $ target = 'web/js' , $ pattern = self :: DEFAULT_TRANSLATION_PATTERN , array $ formats = array ( ) , \ stdClass $ merge = null ) { $ availableFormats = array ( 'js' , 'json' ) ; $ parts = array_filter ( explode ( '/' , $ pattern ) ) ; $ this -> filesystem -> remove ( $ target . '/' . current ( $...
Dump all translation files .
53,850
private function compare_float ( $ a , $ b ) { $ a = number_format ( $ a , 4 ) ; $ b = number_format ( $ b , 4 ) ; if ( 0 === $ a - $ b ) { return 0 ; } elseif ( $ a - $ b < 0 ) { return - 1 ; } else { return 1 ; } }
Function to compare floats .
53,851
public function start ( ) { global $ wpdb , $ wp_object_cache ; $ this -> start_time = microtime ( true ) ; $ this -> query_offset = ! empty ( $ wpdb -> queries ) ? count ( $ wpdb -> queries ) : 0 ; if ( false === ( $ key = array_search ( $ this , self :: $ active_loggers ) ) ) { self :: $ active_loggers [ ] = $ this ;...
Start this logger
53,852
public function stop ( ) { global $ wpdb , $ wp_object_cache ; if ( ! is_null ( $ this -> start_time ) ) { $ this -> time += microtime ( true ) - $ this -> start_time ; } if ( ! is_null ( $ this -> query_offset ) && isset ( $ wpdb ) && ! empty ( $ wpdb -> queries ) ) { for ( $ i = $ this -> query_offset ; $ i < count (...
Stop this logger
53,853
public function start_hook_timer ( ) { $ this -> hook_count ++ ; if ( ! is_null ( $ this -> hook_start_time ) ) { $ this -> hook_depth ++ ; } else { $ this -> hook_start_time = microtime ( true ) ; } }
Start this logger s hook timer
53,854
public function stop_hook_timer ( ) { if ( $ this -> hook_depth ) { $ this -> hook_depth -- ; } else { if ( ! is_null ( $ this -> hook_start_time ) ) { $ this -> hook_time += microtime ( true ) - $ this -> hook_start_time ; } $ this -> hook_start_time = null ; } }
Stop this logger s hook timer
53,855
public function stop_request_timer ( ) { if ( ! is_null ( $ this -> request_start_time ) ) { $ this -> request_time += microtime ( true ) - $ this -> request_start_time ; } $ this -> request_start_time = null ; }
Stop this logger s request timer
53,856
public function eval_ ( $ args , $ assoc_args ) { $ statement = $ args [ 0 ] ; $ order = Utils \ get_flag_value ( $ assoc_args , 'order' , 'ASC' ) ; $ orderby = Utils \ get_flag_value ( $ assoc_args , 'orderby' , null ) ; self :: profile_eval_ish ( $ assoc_args , function ( ) use ( $ statement ) { eval ( $ statement ) ...
Profile arbitrary code execution .
53,857
public function eval_file ( $ args , $ assoc_args ) { $ file = $ args [ 0 ] ; $ order = Utils \ get_flag_value ( $ assoc_args , 'order' , 'ASC' ) ; $ orderby = Utils \ get_flag_value ( $ assoc_args , 'orderby' , null ) ; if ( ! file_exists ( $ file ) ) { WP_CLI :: error ( "'$file' does not exist." ) ; } self :: profile...
Profile execution of an arbitrary file .
53,858
private static function profile_eval_ish ( $ assoc_args , $ profile_callback , $ order = 'ASC' , $ orderby = null ) { $ hook = Utils \ get_flag_value ( $ assoc_args , 'hook' ) ; $ type = $ focus = false ; $ fields = array ( ) ; if ( $ hook ) { $ type = 'hook' ; if ( true !== $ hook ) { $ focus = $ hook ; $ fields [ ] =...
Profile an eval or eval - file statement .
53,859
private static function shine_spotlight ( $ loggers , $ metrics ) { foreach ( $ loggers as $ k => $ logger ) { $ non_zero = false ; foreach ( $ metrics as $ metric ) { switch ( $ metric ) { case 'cache_ratio' : case 'cache_hits' : case 'cache_misses' : if ( $ logger -> cache_ratio && '100%' !== $ logger -> cache_ratio ...
Filter loggers with zero - ish values .
53,860
public function run ( ) { WP_CLI :: add_wp_hook ( 'muplugins_loaded' , function ( ) { if ( $ url = WP_CLI :: get_runner ( ) -> config [ 'url' ] ) { WP_CLI :: set_url ( trailingslashit ( $ url ) ) ; } else { WP_CLI :: set_url ( home_url ( '/' ) ) ; } } ) ; WP_CLI :: add_hook ( 'after_wp_config_load' , function ( ) { if ...
Run the profiler against WordPress
53,861
public function wp_tick_profile_begin ( $ value = null ) { if ( version_compare ( PHP_VERSION , '7.0.0' ) >= 0 ) { WP_CLI :: error ( 'Profiling intermediate hooks is broken in PHP 7, see https://bugs.php.net/bug.php?id=72966' ) ; } if ( extension_loaded ( 'xcache' ) ) { @ ini_set ( 'xcache.optimizer' , false ) ; } else...
Start profiling function calls on the end of this filter
53,862
public function wp_hook_begin ( ) { foreach ( Logger :: $ active_loggers as $ logger ) { $ logger -> start_hook_timer ( ) ; } $ current_filter = current_filter ( ) ; if ( ( 'stage' === $ this -> type && in_array ( $ current_filter , $ this -> current_stage_hooks ) ) || ( 'hook' === $ this -> type && ! $ this -> focus )...
Profiling verbosity at the beginning of every action and filter
53,863
private function wrap_current_filter_callbacks ( $ current_filter ) { $ callbacks = self :: get_filter_callbacks ( $ current_filter ) ; if ( false === $ callbacks ) { return ; } $ this -> previous_filter = $ current_filter ; $ this -> previous_filter_callbacks = $ callbacks ; foreach ( $ callbacks as $ priority => $ pr...
Wrap current filter callbacks with a timer
53,864
public function wp_hook_end ( $ filter_value = null ) { foreach ( Logger :: $ active_loggers as $ logger ) { $ logger -> stop_hook_timer ( ) ; } $ current_filter = current_filter ( ) ; if ( ( 'stage' === $ this -> type && in_array ( $ current_filter , $ this -> current_stage_hooks ) ) || ( 'hook' === $ this -> type && ...
Profiling verbosity at the end of every action and filter
53,865
private static function get_name_location_from_callback ( $ callback ) { $ name = $ location = '' ; $ reflection = false ; if ( is_array ( $ callback ) && is_object ( $ callback [ 0 ] ) ) { $ reflection = new \ ReflectionMethod ( $ callback [ 0 ] , $ callback [ 1 ] ) ; $ name = get_class ( $ callback [ 0 ] ) . '->' . $...
Get a human - readable name from a callback
53,866
private static function get_short_location ( $ location ) { $ abspath = rtrim ( realpath ( ABSPATH ) , '/' ) . '/' ; if ( defined ( 'WP_PLUGIN_DIR' ) && 0 === stripos ( $ location , WP_PLUGIN_DIR ) ) { $ location = str_replace ( trailingslashit ( WP_PLUGIN_DIR ) , '' , $ location ) ; } elseif ( defined ( 'WPMU_PLUGIN_D...
Get the short location from the full location
53,867
private function set_stage_hooks ( $ hooks ) { $ this -> current_stage_hooks = $ hooks ; $ pseudo_hook = "{$hooks[0]}:before" ; $ this -> loggers [ $ pseudo_hook ] = new Logger ( array ( 'hook' => $ pseudo_hook ) ) ; $ this -> loggers [ $ pseudo_hook ] -> start ( ) ; }
Set the hooks for the current stage
53,868
private static function get_filter_callbacks ( $ filter ) { global $ wp_filter ; if ( ! isset ( $ wp_filter [ $ filter ] ) ) { return false ; } if ( is_a ( $ wp_filter [ $ filter ] , 'WP_Hook' ) ) { $ callbacks = $ wp_filter [ $ filter ] -> callbacks ; } else { $ callbacks = $ wp_filter [ $ filter ] ; } if ( is_array (...
Get the callbacks for a given filter
53,869
private static function set_filter_callbacks ( $ filter , $ callbacks ) { global $ wp_filter ; if ( ! isset ( $ wp_filter [ $ filter ] ) && class_exists ( 'WP_Hook' ) ) { $ wp_filter [ $ filter ] = new \ WP_Hook ; } if ( is_a ( $ wp_filter [ $ filter ] , 'WP_Hook' ) ) { $ wp_filter [ $ filter ] -> callbacks = $ callbac...
Set the callbacks for a given filter
53,870
public function load ( array $ fixturesFiles , array $ parameters = [ ] , array $ objects = [ ] , PurgeMode $ purgeMode = null ) : array { $ this -> logger -> info ( 'Loading fixtures.' ) ; return $ this -> filesLoader -> loadFiles ( $ fixturesFiles , $ parameters , $ objects ) -> getObjects ( ) ; }
Loads each file one after another .
53,871
public function load ( array $ fixturesFiles , array $ parameters = [ ] , array $ objects = [ ] , PurgeMode $ purgeMode = null ) : array { $ this -> logger -> info ( 'Resolving fixture files.' ) ; $ fixturesFiles = $ this -> fileResolver -> resolve ( $ fixturesFiles ) ; return $ this -> loader -> load ( $ fixturesFiles...
Resolves the given files before loading them .
53,872
public function load ( array $ fixturesFiles , array $ parameters = [ ] , array $ objects = [ ] , PurgeMode $ purgeMode = null ) : array { $ errorTracker = new ErrorTracker ( ) ; $ filesTracker = new FileTracker ( ... $ fixturesFiles ) ; $ attempts = 0 ; $ set = new ObjectSet ( new ParameterBag ( $ parameters ) , new O...
Try to load the set of files in multiple passes by loading as many files as possible . The result of each loading is passed to the next . After the first pass if some files could not be reloaded another attempt is made until all files are loaded or the maximum number of pass is reached .
53,873
private function registerConfig ( string $ driver , string $ bundle , array $ bundles , array $ configs , LoaderInterface $ loader ) { $ isEnabled = $ configs [ 'db_drivers' ] [ $ driver ] ; if ( false === $ isEnabled ) { return ; } $ bundleIsRegistered = array_key_exists ( $ bundle , $ bundles ) ; if ( $ isEnabled && ...
Registers driver configuration .
53,874
public function decode ( $ input ) { $ input = strtolower ( $ input ) ; $ parts = explode ( '.' , $ input ) ; foreach ( $ parts as & $ part ) { $ length = strlen ( $ part ) ; if ( $ length > 63 || $ length < 1 ) { throw new LabelOutOfBoundsException ( sprintf ( 'The length of any one label is limited to between 1 and 6...
Decode a Punycode domain name to its Unicode counterpart
53,875
protected function calculateThreshold ( $ k , $ bias ) { if ( $ k <= $ bias + static :: TMIN ) { return static :: TMIN ; } elseif ( $ k >= $ bias + static :: TMAX ) { return static :: TMAX ; } return $ k - $ bias ; }
Calculate the bias threshold to fall between TMIN and TMAX
53,876
protected function charToCodePoint ( $ char ) { $ code = ord ( $ char [ 0 ] ) ; if ( $ code < 128 ) { return $ code ; } elseif ( $ code < 224 ) { return ( ( $ code - 192 ) * 64 ) + ( ord ( $ char [ 1 ] ) - 128 ) ; } elseif ( $ code < 240 ) { return ( ( $ code - 224 ) * 4096 ) + ( ( ord ( $ char [ 1 ] ) - 128 ) * 64 ) +...
Convert a single or multi - byte character to its code point
53,877
public function index ( ) { return view ( 'eyewitness::dashboard.index' ) -> withEye ( app ( Eye :: class ) ) -> withTransformer ( new ChartTransformer ) -> withNotifications ( History :: orderBy ( 'acknowledged' ) -> orderBy ( 'created_at' , 'desc' ) -> get ( ) ) -> withStatuses ( Statuses :: all ( ) ) -> withQueues (...
The main Eyewitness dashboard .
53,878
protected function getSeverity ( $ default ) { if ( $ severity = Severity :: where ( 'namespace' , $ this -> safeType ( ) ) -> where ( 'notification' , get_class ( $ this ) ) -> first ( ) ) { return $ severity -> severity ; } app ( Eye :: class ) -> logger ( ) -> debug ( 'Default Notification not found in database' , g...
The severity level for this message .
53,879
public function index ( ) { if ( ! config ( 'eyewitness.debug' ) ) { return redirect ( route ( 'eyewitness.dashboard' ) . '#overview' ) -> withError ( 'Sorry, but you need to enable eyewitness.debug mode to be able to view the debug page' ) ; } $ config = Config :: all ( ) ; $ config [ 'services' ] = null ; $ config [ ...
A method to help debug Eyewitness issues remotely .
53,880
public function poll ( ) { try { foreach ( $ this -> getMonitoredQueues ( ) as $ queue ) { $ this -> storeTubeStats ( $ queue ) ; $ this -> deploySonar ( $ queue ) ; if ( ! $ this -> isQueueOnline ( $ queue ) ) { continue ; } if ( ! $ this -> isWaitTimeOk ( $ queue ) ) { continue ; } if ( ! $ this -> isPendingCountOk (...
Poll the Queue monitor for all checks .
53,881
public function deploySonar ( QueueRepo $ queue ) { if ( ! Cache :: has ( 'eyewitness_q_sonar_deployed_' . $ queue -> id ) ) { Cache :: put ( 'eyewitness_q_sonar_deployed_' . $ queue -> id , time ( ) , 180 ) ; if ( $ this -> eye -> laravelVersionIs ( '>=' , '5.2.0' ) ) { QueueFacade :: connection ( $ queue -> connectio...
Send a sonar tracking job on the queue for each connection and tube .
53,882
public function storeTubeStats ( QueueRepo $ queue ) { $ history = History :: firstOrNew ( [ 'date' => date ( 'Y-m-d' ) , 'hour' => date ( 'H' ) , 'queue_id' => $ queue -> id ] ) ; $ history -> pending_count = $ this -> getPendingJobsCount ( $ queue ) ; $ history -> failed_count = $ this -> getFailedJobsCount ( $ queue...
Get the queue stats for a specific tube .
53,883
public function failedQueue ( $ connection , $ name , $ tube ) { if ( Cache :: has ( 'eyewitness_debounce_failed_queue' ) ) { return ; } Cache :: add ( 'eyewitness_debounce_failed_queue' , 1 , 3 ) ; $ this -> eye -> notifier ( ) -> alert ( new Failed ( [ 'connection' => $ connection , 'tube' => $ tube , 'job' => $ name...
Handle a failing queue notification .
53,884
public function getFailedJobs ( $ queue ) { try { $ list = collect ( app ( 'queue.failer' ) -> all ( ) ) -> where ( 'queue' , $ queue -> tube ) -> where ( 'connection' , $ queue -> connection ) ; $ list -> map ( function ( $ job ) { $ job = $ this -> mapJob ( $ job ) ; } ) ; return $ list ; } catch ( Exception $ e ) { ...
Get a list of failed jobs for a given queue .
53,885
public function getFailedJob ( $ job_id ) { try { $ job = app ( 'queue.failer' ) -> find ( $ job_id ) ; $ job = $ this -> mapJob ( $ job ) ; return $ job ; } catch ( Exception $ e ) { $ this -> eye -> logger ( ) -> error ( 'Unable to get Queue Failed Job' , $ e , $ job_id ) ; } return null ; }
Get a specific failed jobs for a given queue .
53,886
public function getPendingJobsCount ( $ queue ) { $ driver_class = "\\Eyewitness\\Eye\\Queue\\Handlers\\" . ucfirst ( strtolower ( $ queue -> driver ) ) . 'Queue' ; if ( ! class_exists ( $ driver_class ) ) { $ this -> eye -> logger ( ) -> error ( 'Queue Driver does not exist' , $ driver_class ) ; return 0 ; } try { $ q...
Get the number of pending jobs for this queue tube .
53,887
public function isQueueOnline ( $ queue ) { if ( $ queue -> alert_heartbeat_greater_than < 1 ) { return true ; } if ( Carbon :: now ( ) -> diffInSeconds ( $ queue -> last_heartbeat ) <= $ queue -> alert_heartbeat_greater_than ) { if ( $ this -> eye -> status ( ) -> isSick ( 'queue_online_' . $ queue -> id ) ) { $ this ...
Check if the queue is online .
53,888
public function isWaitTimeOk ( $ queue ) { if ( $ queue -> alert_wait_time_greater_than < 1 ) { return true ; } if ( $ queue -> current_wait_time <= $ queue -> alert_wait_time_greater_than ) { if ( $ this -> eye -> status ( ) -> isSick ( 'queue_wait_time_' . $ queue -> id ) ) { $ this -> eye -> notifier ( ) -> alert ( ...
Check if the queue wait time is ok .
53,889
public function isFailedCountOk ( $ queue ) { if ( $ queue -> alert_failed_jobs_greater_than < 1 ) { return true ; } if ( $ this -> getFailedJobsCount ( $ queue ) <= $ queue -> alert_failed_jobs_greater_than ) { if ( $ this -> eye -> status ( ) -> isSick ( 'queue_failed_jobs_' . $ queue -> id ) ) { $ this -> eye -> not...
Check if the queue failed count is ok .
53,890
public function isPendingCountOk ( $ queue ) { if ( $ queue -> alert_pending_jobs_greater_than < 1 ) { return true ; } if ( $ this -> getPendingJobsCount ( $ queue ) <= $ queue -> alert_pending_jobs_greater_than ) { if ( $ this -> eye -> status ( ) -> isSick ( 'queue_pending_jobs_' . $ queue -> id ) ) { $ this -> eye -...
Check if the queue pending count is ok .
53,891
protected function mapJob ( $ job ) { try { $ payload = json_decode ( $ job -> payload ) ; $ job -> job = isset ( $ payload -> displayName ) ? $ payload -> displayName : ( isset ( $ payload -> job ) ? $ payload -> job : 'Unknown' ) ; $ job -> attempts = isset ( $ payload -> attempts ) ? $ payload -> attempts : null ; $...
Map the job to a standard format .
53,892
public function alert ( MessageInterface $ message ) { ( new Database ) -> fire ( new Recipient , $ message ) ; if ( Cache :: has ( 'eyewitness_debounce_' . $ message -> safeType ( ) . '_' . strtolower ( class_basename ( $ message ) ) ) ) { return ; } foreach ( Recipient :: where ( $ message -> severity ( ) , true ) ->...
Send the notification with the given message .
53,893
public function sendTo ( Recipient $ recipient , MessageInterface $ message ) { $ driver = "\\Eyewitness\\Eye\\Notifications\\Drivers\\" . ucfirst ( strtolower ( $ recipient -> type ) ) ; if ( class_exists ( $ driver ) ) { $ channel = app ( $ driver ) ; $ channel -> fire ( $ recipient , $ message ) ; } else { app ( Eye...
Send an alert notification with the given message to a specific recipient .
53,894
public function settings ( ) { if ( is_null ( $ this -> settings ) ) { $ this -> settings [ 'version_php' ] = $ this -> getPhpVersion ( ) ; $ this -> settings [ 'version_laravel' ] = app ( ) -> version ( ) ; $ this -> settings [ 'cache_config' ] = app ( ) -> configurationIsCached ( ) ; $ this -> settings [ 'cache_route...
Get all the application settings .
53,895
public function find ( $ filter ) { if ( is_null ( $ this -> settings ) ) { $ this -> settings ( ) ; } return $ this -> settings [ $ filter ] ; }
Get a specifc application result .
53,896
protected function getNextJob ( $ connection , $ queue ) { if ( $ this -> cache ) { foreach ( $ this -> eyeQueues as $ queue ) { $ this -> eyewitnessHeartbeat ( $ queue ) ; } } foreach ( $ this -> eyeQueues as $ queue ) { $ this -> currentQueue = $ queue ; $ job = parent :: getNextJob ( $ connection , $ queue -> tube )...
Extend the worker and place a heartbeat as it is processing . Then simply feed the tubes into the next job parent . This provides the exact same functionality but this way we know exactly which tube is processing the job .
53,897
protected function eyewitnessHeartbeat ( $ queue ) { if ( ! $ this -> cache -> has ( 'eyewitness_q_heartbeat_' . $ queue -> id ) ) { $ this -> cache -> add ( 'eyewitness_q_heartbeat_' . $ queue -> id , 1 , 1 ) ; $ queue -> heartbeat ( ) ; } }
Check if we have stored a recent heartbeart . Only update the database if the cache has expired .
53,898
public function recordJobEnd ( $ startTime , $ jobName ) { $ endTime = round ( ( microtime ( true ) - $ startTime ) * 1000 ) ; $ this -> cache -> add ( 'eyewitness_q_process_time_' . $ this -> currentQueue -> id , 0 , 180 ) ; $ this -> cache -> increment ( 'eyewitness_q_process_time_' . $ this -> currentQueue -> id , $...
Record the end of the job details . Ignore the sonar job from artifically inflating the queue counters .
53,899
public function recordJobException ( $ exception ) { $ this -> cache -> add ( 'eyewitness_q_exception_count_' . $ this -> currentQueue -> id , 0 , 180 ) ; $ this -> cache -> increment ( 'eyewitness_q_exception_count_' . $ this -> currentQueue -> id ) ; throw $ exception ; }
Record the exeception count .