idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
49,700
public function capabilities ( $ path , $ token = null ) { $ params = [ 'body' => json_encode ( array_filter ( compact ( 'token' , 'path' ) ) ) ] ; if ( empty ( $ token ) ) { return $ this -> client -> post ( '/v1/sys/capabilities-self' , $ params ) ; } return $ this -> client -> post ( '/v1/sys/capabilities' , $ param...
Returns the capabilities of the token on the given path .
49,701
public function renew ( $ leaseId , $ increment = null ) { $ params = [ 'body' => json_encode ( array_filter ( compact ( 'increment' ) ) ) ] ; return $ this -> client -> put ( '/v1/sys/renew/' . $ leaseId , $ params ) ; }
Renew a secret requesting to extend the lease
49,702
public function raw ( $ path , $ value = null ) { if ( $ value === null ) { return $ this -> client -> get ( '/v1/sys/raw/' . $ path ) ; } $ params = [ 'body' => json_encode ( compact ( 'value' ) ) ] ; return $ this -> client -> put ( '/v1/sys/raw/' . $ path , $ params ) ; }
Reads the value of the key at the given path .
49,703
public function create ( array $ body = [ ] ) { $ body = OptionsResolver :: resolve ( $ body , [ 'id' , 'policies' , 'meta' , 'no_parent' , 'no_default_policy' , 'renewable' , 'ttl' , 'explicit_max_ttl' , 'display_name' , 'num_uses' ] ) ; $ params = [ 'body' => json_encode ( $ body ) ] ; return $ this -> client -> post...
Creates a new token .
49,704
public function renewSelf ( array $ body = [ ] ) { $ body = OptionsResolver :: resolve ( $ body , [ 'increment' ] ) ; $ params = [ 'body' => json_encode ( $ body ) ] ; return $ this -> client -> post ( '/v1/auth/token/renew-self' , $ params ) ; }
Renews a lease associated with the calling token .
49,705
public function getOptionParser ( ) { $ requireProject = [ 'arguments' => [ 'project' => [ 'help' => 'Project name (folder)' , 'required' => true ] ] ] ; return parent :: getOptionParser ( ) -> addSubCommand ( 'all' , [ 'help' => 'Same as "start" + "create" + "unseal" + "mounts"' ] ) -> addSubCommand ( 'start' , [ 'hel...
Nice CLI validation and help output
49,706
public function all ( ) { $ this -> hr ( ) ; $ this -> out ( 'Ensure Vault is running' ) ; $ this -> hr ( ) ; $ this -> start ( ) ; $ this -> out ( '' ) ; $ this -> hr ( ) ; $ this -> out ( 'Ensure Vault is initialized' ) ; $ this -> hr ( ) ; $ this -> create ( ) ; $ this -> out ( '' ) ; $ this -> Vault -> waitFor ( [ ...
Same as start + create + unseal + mounts
49,707
public function status ( ) { $ status = $ this -> Vault -> sys ( ) -> status ( ) -> json ( ) ; if ( $ status [ 'initialized' ] !== true ) { $ this -> warn ( 'Vault is not initialized. Please run the "create" command' ) ; return false ; } if ( $ this -> Vault -> sys ( ) -> sealed ( ) ) { $ this -> warn ( 'Vault is not u...
Check the status of Vault
49,708
public function create ( ) { if ( $ this -> status ( ) ) { $ this -> success ( 'Vault already initialized' ) ; return false ; } $ response = $ this -> Vault -> sys ( ) -> init ( [ 'secret_shares' => 5 , 'secret_threshold' => 3 ] ) -> json ( ) ; $ file = env ( 'HOME' ) . '/.bownty_vault_keys' ; file_put_contents ( $ fil...
Create a new Vault instance
49,709
public function env ( ) { $ token = $ this -> Vault -> getVaultToken ( ) ; if ( empty ( $ token ) ) { return $ this -> abort ( 'Token file does not exist - call "create" first' ) ; } $ this -> out ( 'export VAULT_ADDR="http://127.0.0.1:8200" VAULT_TOKEN="' . $ token . '";' ) ; $ this -> out ( 'echo "You can now execute...
Export ENV variables for Vault CLI usage
49,710
public function mounts ( ) { $ config = yaml_parse ( file_get_contents ( CONFIG . 'vault.yml' ) ) ; $ mounts = $ this -> Vault -> sys ( ) -> mounts ( ) -> json ( ) ; foreach ( $ config [ 'secret_backends' ] as $ backend ) { $ this -> out ( 'Backend: ' . $ backend [ 'path' ] ) ; if ( ! array_key_exists ( $ backend [ 'pa...
Create the required mount points
49,711
protected function _secretBackend ( $ backend ) { $ data = $ this -> Vault -> data ( ) ; foreach ( $ backend [ 'secrets' ] as $ secret ) { $ this -> info ( ' ' . $ secret [ 'path' ] ) ; $ data -> write ( 'secret/' . $ secret [ 'path' ] , $ secret [ 'payload' ] ) ; } }
Specific handler for secret secret backends
49,712
protected function _mysqlBackend ( array $ backend ) { if ( empty ( $ backend [ 'config' ] [ 'ini_file' ] ) ) { return $ this -> abort ( 'Missing config.ini_file key for mysql backend' ) ; } if ( ! is_file ( $ backend [ 'config' ] [ 'ini_file' ] ) ) { return $ this -> abort ( 'ini file do not exist (' . $ backend [ 'co...
Specific handler for MySQL secret backends
49,713
public static function determineHostModel ( ) : string { $ hostModel = config ( 'server-monitor.host_model' ) ?? Host :: class ; if ( ! is_a ( $ hostModel , Host :: class , true ) ) { throw InvalidConfiguration :: hostModelIsNotValid ( $ hostModel ) ; } return $ hostModel ; }
Determine the host model class name .
49,714
public function setEvent ( \ Spatie \ ServerMonitor \ Events \ Event $ event ) : self { $ this -> event = $ event ; return $ this ; }
Set the event for the notification .
49,715
public function actionIndex ( ) { $ searchModel = new FansSearch ( ) ; $ dataProvider = $ searchModel -> search ( Yii :: $ app -> request -> queryParams , true ) ; $ dataProvider -> query -> andWhere ( [ 'wid' => $ this -> getWechat ( ) -> id ] ) ; return $ this -> render ( 'index' , [ 'searchModel' => $ searchModel , ...
Lists all Fans models .
49,716
protected function findModel ( $ id ) { $ query = Fans :: find ( ) -> andWhere ( [ 'id' => $ id , 'wid' => $ this -> getWechat ( ) -> id ] ) ; if ( ( $ model = $ query -> one ( ) ) !== null ) { return $ model ; } else { throw new NotFoundHttpException ( 'The requested page does not exist.' ) ; } }
Finds the Fans model based on its primary key value . If the model is not found a 404 HTTP exception will be thrown .
49,717
function get ( $ id ) { $ params = [ 'index' => $ this -> config -> index , 'type' => $ this -> config -> type , 'id' => $ id , ] ; $ response = $ this -> client -> get ( $ params ) ; return $ response [ '_source' ] ; }
Returns collected data with the specified id
49,718
protected static function debugbar ( ) { if ( ! self :: $ debugbar ) { $ di = Di :: getDefault ( ) ; if ( $ di -> has ( 'debugbar' ) ) { return self :: $ debugbar = $ di -> getShared ( 'debugbar' ) ; } else { return self :: $ debugbar = new \ Snowair \ Debugbar \ EmptyDebugbar ( ) ; } } return self :: $ debugbar ; }
GET the debugbar service Instance
49,719
public function startProfile ( $ sqlStatement , $ sqlVariables = null , $ sqlBindTypes = null ) { $ this -> handleFailed ( ) ; $ activeProfile = new Item ( ) ; if ( ! $ sqlVariables ) { $ sqlVariables = $ this -> _db -> getSqlVariables ( ) ; } $ activeProfile -> setSqlStatement ( $ sqlStatement ) ; $ activeProfile -> s...
Starts the profile of a SQL sentence
49,720
public function stopProfile ( ) { $ finalTime = microtime ( true ) ; $ activeProfile = $ this -> _activeProfile ; $ activeProfile -> setFinalTime ( $ finalTime ) ; $ initialTime = $ activeProfile -> getInitialTime ( ) ; $ this -> _totalSeconds = $ this -> _totalSeconds + ( $ finalTime - $ initialTime ) ; if ( $ this ->...
Stops the active profile
49,721
private function deleteAllRoutes ( ) { $ routes = $ this -> getDbRoutes ( ) ; foreach ( $ routes as $ route ) { Craft :: $ app -> routes -> deleteRouteById ( $ route [ 'id' ] ) ; } }
Deletes all routes
49,722
public static function isVersion ( $ version ) { $ currentVersion = Craft :: $ app -> getVersion ( ) ; $ version = explode ( '.' , $ version ) ; $ currentVersion = explode ( '.' , $ currentVersion ) ; $ isVersion = true ; foreach ( $ version as $ key => $ value ) { if ( ( int ) $ currentVersion [ $ key ] < $ version [ ...
check to see if current version is greater than or equal to a version
49,723
public static function getTagGroupByUid ( string $ uid ) : TagGroup { $ query = TagGroup :: find ( ) ; $ query -> andWhere ( [ 'uid' => $ uid ] ) ; return $ query -> one ( ) ?? new TagGroup ( ) ; }
Get a tag record by uid
49,724
public function createSettingMigration ( $ data ) { $ manifest = [ ] ; $ migration = array ( 'settings' => array ( 'dependencies' => array ( ) , 'elements' => array ( ) , ) , ) ; $ empty = true ; $ plugin = MigrationManager :: getInstance ( ) ; foreach ( $ this -> _settingsDependencyTypes as $ key => $ value ) { $ serv...
create a new migration file based on input element types
49,725
public function createContentMigration ( $ data ) { $ manifest = [ ] ; $ migration = array ( 'content' => array ( ) , ) ; $ empty = true ; $ plugin = MigrationManager :: getInstance ( ) ; foreach ( $ this -> _contentMigrationTypes as $ key => $ value ) { $ service = $ plugin -> get ( $ value ) ; if ( array_key_exists (...
create a new migration file based on selected content elements
49,726
public function onBeforeExport ( $ element , array $ newElement ) { $ event = new ExportEvent ( array ( 'element' => $ element , 'value' => $ newElement ) ) ; $ this -> trigger ( $ this :: EVENT_BEFORE_EXPORT_ELEMENT , $ event ) ; return $ event -> value ; }
Fires an onBeforeExport event .
49,727
public function onAfterImport ( $ element , array $ data ) { $ event = new ImportEvent ( array ( 'element' => $ element , 'value' => $ data ) ) ; $ this -> trigger ( $ this :: EVENT_AFTER_IMPORT_ELEMENT , $ event ) ; }
Fires an onAfterImport event .
49,728
protected function commonAction ( $ model , $ redirectUrl , $ view ) { $ request = Yii :: $ app -> getRequest ( ) ; if ( $ request -> getIsPost ( ) && $ this -> repository -> save ( $ model , $ request -> post ( ) ) ) { return $ this -> redirect ( $ redirectUrl ) ; } return $ this -> render ( $ view , \ compact ( 'mode...
Common code for create and update actions .
49,729
protected function registerDependencies ( ) { Yii :: $ container -> setDefinitions ( [ EmailTemplatesRepositoryInterface :: class => $ this -> repository , LanguageProviderInterface :: class => $ this -> languageProvider , ] ) ; }
Register dependencies to DI container .
49,730
public function getByKeyWithTranslation ( $ key , $ language ) { return EmailTemplate :: find ( ) -> byKey ( $ key ) -> withTranslation ( $ language ) -> one ( ) ; }
Find template by key with translation .
49,731
public function getAll ( $ key ) { $ template = EmailTemplate :: find ( ) -> byKey ( $ key ) -> with ( 'translations' ) -> one ( ) ; return empty ( $ template -> translations ) ? null : $ template -> translations ; }
Find all language versions of template by key .
49,732
public function save ( $ entity , array $ data = [ ] ) { try { if ( empty ( $ data ) ) { return $ entity -> save ( ) ; } $ this -> saveInternal ( $ entity , $ data ) ; return true ; } catch ( \ Exception $ ex ) { Yii :: $ app -> getErrorHandler ( ) -> logException ( $ ex ) ; } return false ; }
Save entity .
49,733
public function deleteObject ( $ entity ) { try { return ( bool ) $ entity -> delete ( ) ; } catch ( \ Exception $ ex ) { Yii :: $ app -> getErrorHandler ( ) -> logException ( $ ex ) ; return false ; } }
Removes email template object .
49,734
protected function saveInternal ( EmailTemplate $ entity , array $ data ) { if ( $ entity -> getIsNewRecord ( ) && ! $ entity -> load ( $ data ) ) { throw new \ DomainException ( 'Cannot load data to primary model' ) ; } foreach ( $ data [ EmailTemplateTranslation :: internalFormName ( ) ] as $ language => $ dataSet ) ...
Save entity to database .
49,735
public static function buildMultiply ( $ entities ) { $ templates = [ ] ; foreach ( $ entities as $ entity ) { $ templates [ $ entity -> language ] = static :: buildFromEntity ( $ entity ) ; } return $ templates ; }
Build email templates array from entities .
49,736
public function parse ( $ data ) { if ( isset ( $ data [ 'subject' ] ) ) { $ this -> replaceKeys ( $ data [ 'subject' ] , '_subject' ) ; } if ( isset ( $ data [ 'body' ] ) ) { $ this -> replaceKeys ( $ data [ 'body' ] , '_body' ) ; } }
Replace keys to real data in subject and body .
49,737
public function getTemplate ( $ key , $ language = null , $ default = null ) { $ template = $ this -> repository -> getByKeyWithTranslation ( $ key , $ language ? : Yii :: $ app -> language ) ; return empty ( $ template -> translations [ 0 ] ) ? $ default : EmailTemplate :: buildFromEntity ( $ template -> translations ...
Returns template model by key and language .
49,738
public function getAllTemplates ( $ key , $ default = null ) { $ templates = $ this -> repository -> getAll ( $ key ) ; return null === $ templates ? $ default : EmailTemplate :: buildMultiply ( $ templates ) ; }
Returns email template on all languages .
49,739
public function fetchEmailTemplate ( ) { if ( null !== $ this -> owner ) { $ this -> _template = $ this -> _repository -> getByKeyWithTranslation ( $ this -> generateKey ( ) , $ this -> owner -> { $ this -> _languageAttribute } ) ; } else { $ this -> _template = $ this -> _repository -> create ( ) ; } }
Fetch email template from database .
49,740
public function saveEmailTemplate ( ) { if ( null === $ this -> _template -> key ) { $ this -> _template -> key = $ this -> generateKey ( ) ; } $ this -> _repository -> save ( $ this -> _template ) ; }
Save email template to database .
49,741
protected function generateKey ( ) { return Json :: encode ( [ 'model' => \ get_class ( $ this -> owner ) , 'id' => $ this -> owner -> getPrimaryKey ( ) , 'key' => $ this -> _key , ] ) ; }
Generates key for email template .
49,742
private function getTransferEnvValue ( $ value , bool $ isArray ) { if ( $ value === null ) { return null ; } if ( $ isArray == false ) { return $ value ; } if ( empty ( $ value ) ) { $ value = [ ] ; } else { $ value = explode ( "," , $ value ) ; } return $ value ; }
transfer the value of env
49,743
private function isEnvArrayValue ( string $ className , string $ propertyName ) { $ rc = new \ ReflectionClass ( $ className ) ; $ rp = $ rc -> getProperty ( $ propertyName ) ; $ doc = $ rp -> getDocComment ( ) ; $ tags = DocumentHelper :: tagList ( $ doc ) ; if ( isset ( $ tags [ 'var' ] ) && $ tags [ 'var' ] == 'arra...
whether the value of env is array
49,744
private function getEnvValue ( string $ envValue ) { $ value = $ envValue ; if ( preg_match ( '/^\$\{(.*)\}$/' , $ envValue , $ match ) ) { $ value = env ( $ match [ 1 ] ) ; } return $ value ; }
match env value
49,745
public function onStart ( Server $ server ) { \ file_put_contents ( $ this -> serverSetting [ 'pfile' ] , $ server -> master_pid . ',' . $ server -> manager_pid ) ; ProcessHelper :: setProcessTitle ( $ this -> serverSetting [ 'pname' ] . ' master process (' . $ this -> scriptFile . ')' ) ; $ this -> fireServerEvent ( S...
onStart event callback
49,746
public function onManagerStart ( Server $ server ) { $ this -> fireServerEvent ( SwooleEvent :: ON_MANAGER_START , [ $ server ] ) ; ProcessHelper :: setProcessTitle ( $ this -> serverSetting [ 'pname' ] . ' manager process' ) ; }
onManagerStart event callback
49,747
public function onWorkerStop ( Server $ server , int $ worker_id ) { $ this -> fireServerEvent ( SwooleEvent :: ON_WORKER_STOP , [ $ server , $ worker_id ] ) ; }
onWorkerStop event callback
49,748
public function onWorkerStart ( Server $ server , int $ workerId ) { $ setting = $ server -> setting ; $ isWorker = false ; if ( $ workerId >= $ setting [ 'worker_num' ] ) { ApplicationContext :: setContext ( ApplicationContext :: TASK ) ; ProcessHelper :: setProcessTitle ( $ this -> serverSetting [ 'pname' ] . ' task ...
OnWorkerStart event callback
49,749
public function onPipeMessage ( Server $ server , int $ srcWorkerId , string $ message ) { $ pipeMessage = App :: getBean ( PipeMessage :: class ) ; list ( $ type , $ data ) = $ pipeMessage -> unpack ( $ message ) ; App :: trigger ( AppEvent :: PIPE_MESSAGE , null , $ type , $ data , $ srcWorkerId ) ; }
onPipeMessage event callback
49,750
protected function fireServerEvent ( string $ event , array $ params ) { $ collector = ServerListenerCollector :: getCollector ( ) ; if ( ! isset ( $ collector [ $ event ] ) || empty ( $ collector [ $ event ] ) ) { return ; } foreach ( $ collector [ $ event ] as $ beanClass ) { $ listener = App :: getBean ( $ beanClass...
fire server event listeners
49,751
public static function setResponse ( ResponseInterface $ response ) { $ coroutineId = self :: getCoroutineId ( ) ; self :: $ context [ $ coroutineId ] [ self :: RESPONSE_KEY ] = $ response ; }
Set the object of response
49,752
public static function setContextData ( array $ contextData = [ ] ) { $ existContext = [ ] ; $ coroutineId = self :: getCoroutineId ( ) ; if ( isset ( self :: $ context [ $ coroutineId ] [ self :: DATA_KEY ] ) ) { $ existContext = self :: $ context [ $ coroutineId ] [ self :: DATA_KEY ] ; } self :: $ context [ $ corout...
Set the context data
49,753
public static function setContextDataByKey ( string $ key , $ val ) { $ coroutineId = self :: getCoroutineId ( ) ; self :: $ context [ $ coroutineId ] [ self :: DATA_KEY ] [ $ key ] = $ val ; }
Update context data by key
49,754
public static function getContextDataByKey ( string $ key , $ default = null ) { $ coroutineId = self :: getCoroutineId ( ) ; if ( isset ( self :: $ context [ $ coroutineId ] [ self :: DATA_KEY ] [ $ key ] ) ) { return self :: $ context [ $ coroutineId ] [ self :: DATA_KEY ] [ $ key ] ; } return $ default ; }
Get context data by key
49,755
public static function setContextDataByChildKey ( string $ key , string $ child , $ val ) { $ coroutineId = self :: getCoroutineId ( ) ; self :: $ context [ $ coroutineId ] [ self :: DATA_KEY ] [ $ key ] [ $ child ] = $ val ; }
Update context data by child key
49,756
public static function hasContextDataByChildKey ( string $ key , string $ child ) : bool { $ coroutineId = self :: getCoroutineId ( ) ; return isset ( self :: $ context [ $ coroutineId ] [ self :: DATA_KEY ] [ $ key ] [ $ child ] ) ; }
has exists child key
49,757
public static function getLogid ( ) : string { $ contextData = self :: getCoroutineContext ( self :: DATA_KEY ) ; $ logid = $ contextData [ 'logid' ] ?? '' ; return $ logid ; }
Get Current Request Log ID
49,758
public static function destroy ( ) { $ coroutineId = self :: getCoroutineId ( ) ; if ( isset ( self :: $ context [ $ coroutineId ] ) ) { unset ( self :: $ context [ $ coroutineId ] ) ; } }
Destroy all current coroutine context data
49,759
private static function getCoroutineContext ( string $ key ) { $ coroutineId = self :: getCoroutineId ( ) ; if ( ! isset ( self :: $ context [ $ coroutineId ] ) ) { return null ; } $ coroutineContext = self :: $ context [ $ coroutineId ] ; if ( isset ( $ coroutineContext [ $ key ] ) ) { return $ coroutineContext [ $ ke...
Get data from coroutine context by key
49,760
protected function registerSwooleServerEvents ( ) { $ swooleListeners = SwooleListenerCollector :: getCollector ( ) ; if ( ! isset ( $ swooleListeners [ SwooleEvent :: TYPE_SERVER ] ) || empty ( $ swooleListeners [ SwooleEvent :: TYPE_SERVER ] ) ) { return ; } $ swooleServerListeners = $ swooleListeners [ SwooleEvent :...
Register the event callback of swoole server
49,761
protected function registerSwooleEvents ( $ handler , array $ events ) { foreach ( $ events as $ event => $ beanName ) { $ object = bean ( $ beanName ) ; $ method = SwooleEvent :: getHandlerFunction ( $ event ) ; $ handler -> on ( $ event , [ $ object , $ method ] ) ; } }
Register swoole server events
49,762
public static function md5File ( $ dir ) { if ( ! is_dir ( $ dir ) ) { return '' ; } $ md5File = array ( ) ; $ d = dir ( $ dir ) ; while ( false !== ( $ entry = $ d -> read ( ) ) ) { if ( $ entry !== '.' && $ entry !== '..' ) { if ( is_dir ( $ dir . '/' . $ entry ) ) { $ md5File [ ] = self :: md5File ( $ dir . '/' . $ ...
md5 of dir
49,763
public static function newProxyInstance ( string $ className , HandlerInterface $ handler ) { $ reflectionClass = new \ ReflectionClass ( $ className ) ; $ reflectionMethods = $ reflectionClass -> getMethods ( \ ReflectionMethod :: IS_PUBLIC | \ ReflectionMethod :: IS_PROTECTED ) ; $ id = \ uniqid ( '' , false ) ; $ pr...
Return a proxy instance
49,764
private static function getMethodsTemplate ( array $ reflectionMethods , string $ handlerPropertyName ) : string { $ template = '' ; foreach ( $ reflectionMethods as $ reflectionMethod ) { $ methodName = $ reflectionMethod -> getName ( ) ; if ( $ reflectionMethod -> isConstructor ( ) || $ reflectionMethod -> isStatic (...
Return the template of method
49,765
private static function getParameterTemplate ( \ ReflectionMethod $ reflectionMethod ) : string { $ template = '' ; $ reflectionParameters = $ reflectionMethod -> getParameters ( ) ; $ paramCount = \ count ( $ reflectionParameters ) ; foreach ( $ reflectionParameters as $ reflectionParameter ) { $ paramCount -- ; $ typ...
Return the template of parameter
49,766
private static function getParameterDefaultValue ( \ ReflectionParameter $ reflectionParameter ) : string { $ template = '' ; $ defaultValue = $ reflectionParameter -> getDefaultValue ( ) ; if ( $ reflectionParameter -> isDefaultValueConstant ( ) ) { $ defaultConst = $ reflectionParameter -> getDefaultValueConstantName...
Get default value of parameter
49,767
private static function validateError ( string $ message , bool $ throws ) : bool { if ( $ throws ) { throw new ValidatorException ( $ message ) ; } return false ; }
Throw a ValidatorException
49,768
public function autoloadServerAnnotation ( ) { $ bootScan = $ this -> getScanNamespaceFromProperties ( 'bootScan' ) ; $ resource = new ServerAnnotationResource ( $ this -> properties ) ; $ resource -> addScanNamespace ( $ bootScan ) ; $ definitions = $ resource -> getDefinitions ( ) ; $ this -> definitions = array_merg...
Register the annotation of server
49,769
public function autoloadWorkerAnnotation ( ) { $ beanScan = $ this -> getBeanScanNamespace ( ) ; $ resource = new WorkerAnnotationResource ( $ this -> properties ) ; $ resource -> addScanNamespace ( $ beanScan ) ; $ definitions = $ resource -> getDefinitions ( ) ; $ this -> definitions = \ array_merge ( $ definitions ,...
Register the annotation of worker
49,770
public function registerServerNamespace ( ) { foreach ( $ this -> customComponents as $ ns => $ componentDir ) { if ( is_int ( $ ns ) ) { $ ns = $ componentDir ; $ componentDir = ComposerHelper :: getDirByNamespace ( $ ns ) ; $ ns = rtrim ( $ ns , "\\" ) ; $ componentDir = rtrim ( $ componentDir , "/" ) ; } $ this -> c...
Register the server namespace
49,771
public function registerWorkerNamespace ( ) { foreach ( $ this -> customComponents as $ ns => $ componentDir ) { if ( is_int ( $ ns ) ) { $ ns = $ componentDir ; $ componentDir = ComposerHelper :: getDirByNamespace ( $ ns ) ; $ ns = rtrim ( $ ns , "\\" ) ; $ componentDir = rtrim ( $ componentDir , "/" ) ; } $ this -> c...
Register the worker namespace
49,772
public static function getComponentNs ( string $ component ) : string { if ( $ component === 'framework' ) { return '' ; } $ namespace = '' ; $ nsAry = explode ( '-' , $ component ) ; foreach ( $ nsAry as $ ns ) { $ namespace .= "\\" . ucfirst ( $ ns ) ; } return $ namespace ; }
Get the default namespace of component
49,773
public function handle ( ServerRequestInterface $ request ) : ResponseInterface { if ( ! empty ( $ this -> default ) && empty ( $ this -> middlewares [ $ this -> offset ] ) ) { $ handler = App :: getBean ( $ this -> default ) ; } else { $ handler = $ this -> middlewares [ $ this -> offset ] ; \ is_string ( $ handler ) ...
Process the request using the current middleware .
49,774
public function insertMiddlewares ( array $ middlewares , $ offset = null ) { null === $ offset && $ offset = $ this -> offset ; $ chunkArray = array_chunk ( $ this -> middlewares , $ offset ) ; $ after = [ ] ; $ before = $ chunkArray [ 0 ] ; if ( isset ( $ chunkArray [ 1 ] ) ) { $ after = $ chunkArray [ 1 ] ; } $ midd...
Insert middlewares to the next position
49,775
public function getConnectionAddress ( ) : string { $ serviceList = $ this -> getServiceList ( ) ; if ( App :: hasBean ( 'balancerSelector' ) ) { $ balancerType = $ this -> poolConfig -> getBalancer ( ) ; $ balancer = balancer ( ) -> select ( $ balancerType ) ; return $ balancer -> select ( $ serviceList ) ; } return c...
Get one address
49,776
protected function getServiceList ( ) { $ name = $ this -> poolConfig -> getName ( ) ; if ( $ this -> poolConfig -> isUseProvider ( ) && App :: hasBean ( 'providerSelector' ) ) { $ type = $ this -> poolConfig -> getProvider ( ) ; return provider ( ) -> select ( $ type ) -> getServiceList ( $ name ) ; } $ uri = $ this -...
Get service list
49,777
private function releaseToChannel ( ConnectionInterface $ connection ) { $ stats = $ this -> channel -> stats ( ) ; $ maxActive = $ this -> poolConfig -> getMaxActive ( ) ; if ( $ stats [ 'queue_num' ] < $ maxActive ) { $ this -> channel -> push ( $ connection ) ; } }
Release to channel
49,778
private function getEffectiveConnection ( int $ queueNum , bool $ isChannel = true ) : ConnectionInterface { $ minActive = $ this -> poolConfig -> getMinActive ( ) ; if ( $ queueNum <= $ minActive ) { return $ this -> getOriginalConnection ( $ isChannel ) ; } $ time = time ( ) ; $ moreActive = $ queueNum - $ minActive ...
Get effective connection
49,779
private function getOriginalConnection ( bool $ isChannel = true ) : ConnectionInterface { if ( $ isChannel ) { return $ this -> channel -> pop ( ) ; } return $ this -> queue -> shift ( ) ; }
Get original connection
49,780
public function execute ( $ target , string $ method , array $ params ) { $ class = \ get_class ( $ target ) ; if ( ! isset ( $ this -> map [ $ class ] [ $ method ] ) || empty ( $ this -> map [ $ class ] [ $ method ] ) ) { return $ target -> $ method ( ... $ params ) ; } $ advices = $ this -> map [ $ class ] [ $ method...
Execute origin method by aop
49,781
private function matchBeanAndAnnotation ( array $ pointAry , array $ classAry ) : bool { $ intersectAry = \ array_intersect ( $ pointAry , $ classAry ) ; if ( empty ( $ intersectAry ) ) { return false ; } return true ; }
Match bean and annotation
49,782
public function addParam ( $ name , $ value ) : self { if ( ! isset ( $ this -> params [ $ name ] ) ) { $ this -> setParam ( $ name , $ value ) ; } return $ this ; }
add a argument
49,783
public function setParam ( $ name , $ value ) : self { if ( null === $ name ) { throw new \ InvalidArgumentException ( 'The argument name cannot be null.' ) ; } $ this -> params [ $ name ] = $ value ; return $ this ; }
set a argument
49,784
public static function getPool ( string $ name ) : PoolInterface { $ collector = PoolCollector :: getCollector ( ) ; if ( ! isset ( $ collector [ $ name ] ) ) { throw new InvalidArgumentException ( "the pool of $name is not exist!" ) ; } $ poolBeanName = $ collector [ $ name ] ; return self :: getBean ( $ poolBeanName ...
get pool by name
49,785
public static function hasAlias ( string $ alias ) : bool { if ( ! $ alias || $ alias [ 0 ] !== '@' ) { return false ; } return isset ( self :: $ aliases [ $ alias ] ) ; }
Is alias exist ?
49,786
protected function addIgnoredNames ( AnnotationReader $ reader ) { foreach ( $ this -> ignoredNames as $ name ) { $ reader -> addGlobalIgnoredName ( $ name ) ; } return $ reader ; }
add ignored names
49,787
public function trigger ( $ event , $ target = null , array $ args = [ ] ) : EventInterface { if ( ! $ event instanceof EventInterface ) { $ event = ( string ) $ event ; if ( isset ( $ this -> events [ $ event ] ) ) { $ event = $ this -> events [ $ event ] ; } else { $ event = $ this -> wrapperEvent ( $ event ) ; } } i...
Trigger an event Can accept an EventInterface or will create one if not passed
49,788
public static function reload ( array $ definitions = [ ] ) { $ properties = self :: getProperties ( ) ; $ workerDefinitions = self :: getWorkerDefinition ( ) ; $ definitions = ArrayHelper :: merge ( $ workerDefinitions , $ definitions ) ; self :: $ container -> setProperties ( $ properties ) ; self :: $ container -> a...
Reload bean definitions
49,789
public static function create ( callable $ cb ) { $ tid = self :: tid ( ) ; return SwCoroutine :: create ( function ( ) use ( $ cb , $ tid ) { $ id = SwCoroutine :: getuid ( ) ; self :: $ idMap [ $ id ] = $ tid ; PhpHelper :: call ( $ cb ) ; } ) ; }
Create a coroutine
49,790
public function withNoArgs ( ) { if ( ! in_array ( $ this -> target -> type ( ) , self :: NO_ARGS_EXPECTATION_TYPES , true ) ) { throw Exception \ ExpectationArgsRequired :: forExpectationType ( $ this -> target ) ; } $ this -> expectation = $ this -> expectation -> withNoArgs ( ) ; return $ this ; }
WordPress action and filters addition and filters applying requires at least one argument and setting an expectation of no arguments for those triggers an error in Brain Monkey .
49,791
private function assertMethodCallable ( $ class_name , $ method , $ callable ) { if ( class_exists ( $ class_name ) && ! ( method_exists ( $ class_name , $ method ) || is_callable ( [ $ class_name , $ method ] ) ) ) { throw Exception \ InvalidCallable :: forCallable ( $ callable ) ; } }
Ensure method existence only if class is available .
49,792
public function alias ( callable $ callback ) { $ fqn = $ this -> function_name -> fullyQualifiedName ( ) ; \ Patchwork \ redefine ( $ fqn , $ callback ) ; $ this -> assertRedefined ( $ fqn ) ; }
Redefine target function replacing it on the fly with a given callable .
49,793
public function redefineUsingExpectation ( Expectation $ expectation ) { $ fqn = $ this -> function_name -> fullyQualifiedName ( ) ; $ this -> alias ( function ( ... $ args ) use ( $ expectation , $ fqn ) { $ mock = $ expectation -> mockeryExpectation ( ) -> getMock ( ) ; $ target = new ExpectationTarget ( ExpectationT...
Redefine target function replacing it with a function that execute Brain Monkey expectation target method on the mock associated with given Brain Monkey expectation .
49,794
public function justReturn ( $ return = null ) { $ fqn = ltrim ( $ this -> function_name -> fullyQualifiedName ( ) , '\\' ) ; \ Patchwork \ redefine ( $ fqn , function ( ) use ( $ return ) { return $ return ; } ) ; $ this -> assertRedefined ( $ fqn ) ; }
Redefine target function making it return an arbitrary value .
49,795
public function justEcho ( $ value = null ) { is_null ( $ value ) and $ value = '' ; $ fqn = ltrim ( $ this -> function_name -> fullyQualifiedName ( ) , '\\' ) ; $ this -> assertPrintable ( $ value , 'provided to justEcho' ) ; \ Patchwork \ redefine ( $ fqn , function ( ) use ( $ value ) { echo $ value ; } ) ; $ this -...
Redefine target function making it echo an arbitrary value .
49,796
public function returnArg ( $ arg_num = 1 ) { $ arg_num = $ this -> assertValidArgNum ( $ arg_num ) ; $ fqn = $ this -> function_name -> fullyQualifiedName ( ) ; \ Patchwork \ redefine ( $ fqn , function ( ... $ args ) use ( $ fqn , $ arg_num ) { if ( ! array_key_exists ( $ arg_num - 1 , $ args ) ) { $ count = count ( ...
Redefine target function making it return one of the received arguments the first by default . Redefined function will throw an exception if the function does not receive desired argument .
49,797
public function echoArg ( $ arg_num = 1 ) { $ arg_num = $ this -> assertValidArgNum ( $ arg_num ) ; $ fqn = $ this -> function_name -> fullyQualifiedName ( ) ; \ Patchwork \ redefine ( $ fqn , function ( ... $ args ) use ( $ fqn , $ arg_num ) { if ( ! array_key_exists ( $ arg_num - 1 , $ args ) ) { $ count = count ( $ ...
Redefine target function making it echo one of the received arguments the first by default . Redefined function will throw an exception if the function does not receive desired argument .
49,798
public function find ( $ themeName ) { foreach ( $ this -> themes as $ theme ) { if ( $ theme -> name == $ themeName ) { return $ theme ; } } throw new Exceptions \ themeNotFound ( $ themeName ) ; }
Find a theme by it s name
49,799
public function add ( Theme $ theme ) { if ( $ this -> exists ( $ theme -> name ) ) { throw new Exceptions \ themeAlreadyExists ( $ theme ) ; } $ this -> themes [ ] = $ theme ; return $ theme ; }
Register a new theme