idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
44,400
private function parseWithMode ( $ raw_metar , $ strict ) { $ clean_metar = trim ( strtoupper ( $ raw_metar ) ) ; $ clean_metar = preg_replace ( '#=$#' , '' , $ clean_metar ) ; $ clean_metar = preg_replace ( '#[ ]{2,}#' , ' ' , $ clean_metar ) . ' ' ; $ remaining_metar = $ clean_metar ; $ decoded_metar = new DecodedMetar ( $ clean_metar ) ; $ with_cavok = false ; foreach ( $ this -> decoder_chain as $ chunk_decoder ) { try { $ decoded = $ this -> tryParsing ( $ chunk_decoder , $ strict , $ remaining_metar , $ with_cavok ) ; if ( array_key_exists ( 'exception' , $ decoded ) ) { $ decoded_metar -> addDecodingException ( $ decoded [ 'exception' ] ) ; } $ result = $ decoded [ 'result' ] ; if ( $ result != null ) { foreach ( $ result as $ key => $ value ) { if ( $ value !== null ) { $ setter_name = 'set' . ucfirst ( $ key ) ; $ decoded_metar -> $ setter_name ( $ value ) ; } } } $ remaining_metar = $ decoded [ 'remaining_metar' ] ; } catch ( ChunkDecoderException $ cde ) { $ decoded_metar -> addDecodingException ( $ cde ) ; if ( $ strict ) { break ; } $ remaining_metar = $ cde -> getRemainingMetar ( ) ; } if ( $ chunk_decoder instanceof ReportStatusChunkDecoder ) { if ( $ decoded_metar -> getStatus ( ) == 'NIL' ) { break ; } } if ( $ chunk_decoder instanceof VisibilityChunkDecoder ) { $ with_cavok = $ decoded_metar -> getCavok ( ) ; } } return $ decoded_metar ; }
Decode a full metar string into a complete metar object .
44,401
public function consume ( $ remaining_metar ) { $ chunk_regexp = $ this -> getRegexp ( ) ; if ( preg_match ( $ chunk_regexp , $ remaining_metar , $ matches ) ) { $ found = $ matches ; } else { $ found = null ; } $ new_remaining_metar = preg_replace ( $ chunk_regexp , '' , $ remaining_metar , 1 ) ; return array ( 'found' => $ found , 'remaining' => $ new_remaining_metar , ) ; }
Extract the corresponding chunk from the remaining metar .
44,402
private function getConversionMap ( ) { $ conversion_maps = array ( $ this -> speed_conversion_map , $ this -> distance_conversion_map , $ this -> pressure_conversion_map , ) ; foreach ( $ conversion_maps as $ map ) { if ( array_key_exists ( $ this -> unit , $ map ) ) { return $ map ; } } throw new \ Exception ( 'Trying to convert unsupported values' ) ; }
Returns conversion map based on original METAR unit .
44,403
private function checkValidity ( $ day , $ hour , $ minute ) { $ day_int = intval ( $ day ) ; $ hour_int = intval ( $ hour ) ; $ minute_int = intval ( $ minute ) ; if ( $ day_int < 1 || $ day_int > 31 ) { return false ; } if ( $ hour_int > 23 ) { return false ; } if ( $ minute_int > 59 ) { return false ; } return true ; }
Check the validity of the decoded information for date time .
44,404
public function build ( $ method , $ uri , $ params = null ) { $ request = [ 'http_method' => $ method , 'scheme' => $ this -> schema , 'uri' => $ this -> uri . $ uri , 'headers' => [ 'Host' => [ $ this -> host ] , 'User-Agent' => [ $ this -> getUserAgent ( ) ] , ] , 'client' => [ 'connect_timeout' => 30 , 'timeout' => 60 , ] , 'version' => 1.1 , ] ; if ( ! empty ( $ params ) ) { $ request [ 'query_string' ] = http_build_query ( $ params ) ; } return $ request ; }
Creates only basic request params
44,405
public function filaAtendimento ( Unidade $ unidade , Usuario $ usuario , array $ servicosUsuario , $ tipoFila = self :: TIPO_TODOS , $ maxResults = 0 ) { $ ids = [ ] ; foreach ( $ servicosUsuario as $ servico ) { if ( $ servico -> getUsuario ( ) -> getId ( ) === $ usuario -> getId ( ) ) { $ ids [ ] = $ servico -> getServico ( ) -> getId ( ) ; } } if ( empty ( $ ids ) ) { return [ ] ; } $ builder = $ this -> builder ( ) -> join ( ServicoUsuario :: class , 'servicoUsuario' , 'WITH' , 'servicoUsuario.servico = servico AND servicoUsuario.usuario = :usuario' ) -> andWhere ( '(atendimento.usuario IS NULL OR atendimento.usuario = :usuario)' ) -> andWhere ( 'atendimento.status = :status' ) -> andWhere ( 'atendimento.unidade = :unidade' ) -> andWhere ( 'servico.id IN (:servicos)' ) ; switch ( $ tipoFila ) { case self :: TIPO_NORMAL : case self :: TIPO_PRIORIDADE : $ s = ( $ tipoFila === self :: TIPO_NORMAL ) ? '=' : '>' ; $ where = "prioridade.peso $s 0" ; $ builder -> andWhere ( $ where ) ; break ; case self :: TIPO_AGENDAMENTO : $ builder -> andWhere ( "atendimento.dataAgendamento IS NOT NULL" ) ; break ; } $ params = [ 'status' => AtendimentoService :: SENHA_EMITIDA , 'unidade' => $ unidade , 'usuario' => $ usuario , 'servicos' => $ ids , ] ; $ this -> applyOrders ( $ builder , $ unidade , $ usuario ) ; $ query = $ builder -> setParameters ( $ params ) -> getQuery ( ) ; if ( $ maxResults > 0 ) { $ query -> setMaxResults ( $ maxResults ) ; } return $ query -> getResult ( ) ; }
Retorna a fila de atendimentos do usuario .
44,406
public function chamarSenha ( Unidade $ unidade , Atendimento $ atendimento ) { $ servico = $ atendimento -> getServico ( ) ; $ su = $ this -> storage -> getRepository ( ServicoUnidade :: class ) -> get ( $ unidade , $ servico ) ; $ senha = new PainelSenha ( ) ; $ senha -> setUnidade ( $ unidade ) ; $ senha -> setServico ( $ servico ) ; $ senha -> setNumeroSenha ( $ atendimento -> getSenha ( ) -> getNumero ( ) ) ; $ senha -> setSiglaSenha ( $ atendimento -> getSenha ( ) -> getSigla ( ) ) ; $ senha -> setMensagem ( $ su -> getMensagem ( ) . '' ) ; $ senha -> setLocal ( $ atendimento -> getLocal ( ) -> getNome ( ) ) ; $ senha -> setNumeroLocal ( $ atendimento -> getNumeroLocal ( ) ) ; $ senha -> setPeso ( $ atendimento -> getPrioridade ( ) -> getPeso ( ) ) ; $ senha -> setPrioridade ( $ atendimento -> getPrioridade ( ) -> getNome ( ) ) ; if ( $ atendimento -> getCliente ( ) ) { $ senha -> setNomeCliente ( $ atendimento -> getCliente ( ) -> getNome ( ) ) ; $ senha -> setDocumentoCliente ( $ atendimento -> getCliente ( ) -> getDocumento ( ) ) ; } $ this -> dispatcher -> createAndDispatch ( 'panel.pre-call' , [ $ atendimento , $ senha ] , true ) ; $ om = $ this -> storage -> getManager ( ) ; $ om -> persist ( $ senha ) ; $ om -> flush ( ) ; $ this -> dispatcher -> createAndDispatch ( 'panel.call' , [ $ atendimento , $ senha ] , true ) ; }
Adiciona uma nova senha na fila de chamada do painel de senhas .
44,407
public function atendimentoAndamento ( $ usuario , $ unidade = null ) { $ status = [ self :: CHAMADO_PELA_MESA , self :: ATENDIMENTO_INICIADO , ] ; try { $ qb = $ this -> storage -> getManager ( ) -> createQueryBuilder ( ) -> select ( 'e' ) -> from ( Atendimento :: class , 'e' ) -> where ( 'e.usuario = :usuario' ) -> andWhere ( 'e.status IN (:status)' ) ; $ params = [ 'usuario' => $ usuario , 'status' => $ status , ] ; if ( $ unidade ) { $ qb -> andWhere ( 'e.unidade = :unidade' ) ; $ params [ 'unidade' ] = $ unidade ; } return $ qb -> setParameters ( $ params ) -> getQuery ( ) -> getOneOrNullResult ( ) ; } catch ( \ Doctrine \ ORM \ NonUniqueResultException $ e ) { $ this -> storage -> getManager ( ) -> createQueryBuilder ( ) -> update ( Atendimento :: class , 'e' ) -> set ( 'e.status' , ':status' ) -> set ( 'e.usuario' , ':null' ) -> where ( 'e.usuario = :usuario' ) -> andWhere ( 'e.status IN (:status)' ) -> setParameters ( [ 'status' => 1 , 'null' => null , 'usuario' => $ usuario , 'status' => $ status ] ) -> getQuery ( ) -> execute ( ) ; return ; } }
Retorna o atendimento em andamento do usuario informado .
44,408
public function servicosIndisponiveis ( $ unidade , $ usuario ) { return $ this -> storage -> getManager ( ) -> createQuery ( " SELECT e FROM Novosga\Entity\ServicoUnidade e JOIN e.servico s WHERE s.deletedAt IS NULL AND e.ativo = TRUE AND e.unidade = :unidade AND s.id NOT IN ( SELECT s2.id FROM Novosga\Entity\ServicoUsuario a JOIN a.servico s2 WHERE a.usuario = :usuario AND a.unidade = :unidade ) " ) -> setParameter ( 'usuario' , $ usuario ) -> setParameter ( 'unidade' , $ unidade ) -> getResult ( ) ; }
Retorna os servicos que o usuario nao atende na unidade atual .
44,409
public static function defaultConnectionName ( ) { $ namespaceParts = explode ( '\\' , get_called_class ( ) ) ; $ plugin = array_slice ( array_reverse ( $ namespaceParts ) , 3 , 2 ) ; return Inflector :: underscore ( current ( $ plugin ) ) ; }
Get the default connection name .
44,410
public function endpoint ( $ endpoint = null ) { if ( $ endpoint !== null ) { $ this -> setName ( $ endpoint ) ; } return $ this -> getName ( ) ; }
Returns the endpoint name or sets a new one
44,411
public function setName ( $ name ) { $ inflectMethod = $ this -> getInflectionMethod ( ) ; $ this -> _name = Inflector :: $ inflectMethod ( $ name ) ; return $ this ; }
Set the name of this endpoint
44,412
public function getName ( ) { if ( $ this -> _name === null ) { $ endpoint = namespaceSplit ( get_class ( $ this ) ) ; $ endpoint = substr ( end ( $ endpoint ) , 0 , - 8 ) ; $ inflectMethod = $ this -> getInflectionMethod ( ) ; $ this -> _name = Inflector :: $ inflectMethod ( $ endpoint ) ; } return $ this -> _name ; }
Get the name of this endpoint
44,413
public function alias ( $ alias = null ) { if ( $ alias !== null ) { $ this -> setAlias ( $ alias ) ; } return $ this -> getAlias ( ) ; }
Returns the endpoint alias or sets a new one
44,414
public function registryAlias ( $ registryAlias = null ) { if ( $ registryAlias !== null ) { $ this -> setRegistryAlias ( $ registryAlias ) ; } return $ this -> getRegistryAlias ( ) ; }
Returns the endpoint registry key used to create this endpoint instance
44,415
public function setSchema ( $ schema ) { if ( is_array ( $ schema ) ) { $ schema = new Schema ( $ this -> getName ( ) , $ schema ) ; } $ this -> _schema = $ schema ; return $ this ; }
Set the endpoints schema
44,416
public function getPrimaryKey ( ) { if ( $ this -> _primaryKey === null ) { $ schema = $ this -> getSchema ( ) ; if ( ! $ schema ) { throw new UnexpectedDriverException ( __ ( 'No schema has been defined for this endpoint' ) ) ; } $ key = ( array ) $ schema -> primaryKey ( ) ; if ( count ( $ key ) === 1 ) { $ key = $ key [ 0 ] ; } $ this -> _primaryKey = $ key ; } return $ this -> _primaryKey ; }
Get the endpoints primary key if one is not set fetch it from the schema
44,417
public function getDisplayField ( ) { if ( $ this -> _displayField === null ) { $ primary = ( array ) $ this -> getPrimaryKey ( ) ; $ this -> _displayField = array_shift ( $ primary ) ; $ schema = $ this -> getSchema ( ) ; if ( ! $ schema ) { throw new UnexpectedDriverException ( __ ( 'No schema has been defined for this endpoint' ) ) ; } if ( $ schema -> column ( 'title' ) ) { $ this -> _displayField = 'title' ; } if ( $ schema -> column ( 'name' ) ) { $ this -> _displayField = 'name' ; } } return $ this -> _displayField ; }
Get the endpoints current display field
44,418
public function resourceClass ( $ name = null ) { if ( $ name !== null ) { $ this -> setResourceClass ( $ name ) ; } return $ this -> getResourceClass ( ) ; }
Returns the class used to hydrate resources for this endpoint or sets a new one
44,419
public function setResourceClass ( $ name ) { $ this -> _resourceClass = App :: className ( $ name , 'Model/Resource' ) ; if ( ! $ this -> _resourceClass ) { throw new MissingResourceClassException ( [ $ name ] ) ; } return $ this ; }
Set the resource class name used to hydrate resources for this endpoint
44,420
public function getResourceClass ( ) { if ( ! $ this -> _resourceClass ) { $ default = \ Muffin \ Webservice \ Model \ Resource :: class ; $ self = get_called_class ( ) ; $ parts = explode ( '\\' , $ self ) ; if ( $ self === __CLASS__ || count ( $ parts ) < 3 ) { return $ this -> _resourceClass = $ default ; } $ alias = Inflector :: singularize ( substr ( array_pop ( $ parts ) , 0 , - 8 ) ) ; $ name = implode ( '\\' , array_slice ( $ parts , 0 , - 1 ) ) . '\Resource\\' . $ alias ; if ( ! class_exists ( $ name ) ) { return $ this -> _resourceClass = $ default ; } else { return $ this -> _resourceClass = $ name ; } } return $ this -> _resourceClass ; }
Get the resource class name used to hydrate resources for this endpoint
44,421
public function inflectionMethod ( $ method = null ) { if ( $ method !== null ) { $ this -> setInflectionMethod ( $ method ) ; } return $ this -> getInflectionMethod ( ) ; }
Returns the inflect method or sets a new one
44,422
public function webservice ( $ webservice = null ) { if ( $ webservice !== null ) { return $ this -> setWebservice ( $ this -> getName ( ) , $ webservice ) ; } if ( $ webservice === null ) { return $ this -> getWebservice ( ) ; } $ this -> _webservice = $ webservice ; return $ this ; }
Returns an instance of the Webservice used
44,423
public function setWebservice ( $ alias , $ webservice ) { $ connection = $ this -> getConnection ( ) ; if ( ! $ connection ) { throw new UnexpectedDriverException ( __ ( 'No driver has been defined for this endpoint' ) ) ; } $ connection -> setWebservice ( $ alias , $ webservice ) ; $ this -> _webservice = $ connection -> getWebservice ( $ alias ) ; return $ this ; }
Set the webservice instance to be used for this endpoint
44,424
public function getWebservice ( ) { if ( $ this -> _webservice === null ) { $ this -> _webservice = $ this -> getConnection ( ) -> getWebservice ( $ this -> getName ( ) ) ; } return $ this -> _webservice ; }
Get this endpoints associated webservice
44,425
public function get ( $ primaryKey , $ options = [ ] ) { $ key = ( array ) $ this -> getPrimaryKey ( ) ; $ alias = $ this -> getAlias ( ) ; foreach ( $ key as $ index => $ keyname ) { $ key [ $ index ] = $ keyname ; } $ primaryKey = ( array ) $ primaryKey ; if ( count ( $ key ) !== count ( $ primaryKey ) ) { $ primaryKey = $ primaryKey ? : [ null ] ; $ primaryKey = array_map ( function ( $ key ) { return var_export ( $ key , true ) ; } , $ primaryKey ) ; throw new InvalidPrimaryKeyException ( sprintf ( 'Record not found in endpoint "%s" with primary key [%s]' , $ this -> getName ( ) , implode ( $ primaryKey , ', ' ) ) ) ; } $ conditions = array_combine ( $ key , $ primaryKey ) ; $ cacheConfig = isset ( $ options [ 'cache' ] ) ? $ options [ 'cache' ] : false ; $ cacheKey = isset ( $ options [ 'key' ] ) ? $ options [ 'key' ] : false ; $ finder = isset ( $ options [ 'finder' ] ) ? $ options [ 'finder' ] : 'all' ; unset ( $ options [ 'key' ] , $ options [ 'cache' ] , $ options [ 'finder' ] ) ; $ query = $ this -> find ( $ finder , $ options ) -> where ( $ conditions ) ; if ( $ cacheConfig ) { if ( ! $ cacheKey ) { $ cacheKey = sprintf ( "get:%s.%s%s" , $ this -> getConnection ( ) -> configName ( ) , $ this -> getName ( ) , json_encode ( $ primaryKey ) ) ; } $ query -> cache ( $ cacheKey , $ cacheConfig ) ; } return $ query -> firstOrFail ( ) ; }
Returns a single record after finding it by its primary key if no record is found this method throws an exception .
44,426
public function updateAll ( $ fields , $ conditions ) { return $ this -> query ( ) -> update ( ) -> where ( $ conditions ) -> set ( $ fields ) -> execute ( ) -> count ( ) ; }
Update all matching records .
44,427
public function save ( EntityInterface $ resource , $ options = [ ] ) { $ options = new ArrayObject ( ( array ) $ options + [ 'checkRules' => true , 'checkExisting' => false , ] ) ; if ( $ resource -> getErrors ( ) ) { return false ; } if ( $ resource -> isNew ( ) === false && ! $ resource -> isDirty ( ) ) { return $ resource ; } $ primaryColumns = ( array ) $ this -> getPrimaryKey ( ) ; if ( $ options [ 'checkExisting' ] && $ primaryColumns && $ resource -> isNew ( ) && $ resource -> has ( $ primaryColumns ) ) { $ alias = $ this -> getAlias ( ) ; $ conditions = [ ] ; foreach ( $ resource -> extract ( $ primaryColumns ) as $ k => $ v ) { $ conditions [ "$alias.$k" ] = $ v ; } $ resource -> isNew ( ! $ this -> exists ( $ conditions ) ) ; } $ mode = $ resource -> isNew ( ) ? RulesChecker :: CREATE : RulesChecker :: UPDATE ; if ( $ options [ 'checkRules' ] && ! $ this -> checkRules ( $ resource , $ mode , $ options ) ) { return false ; } $ event = $ this -> dispatchEvent ( 'Model.beforeSave' , compact ( 'resource' , 'options' ) ) ; if ( $ event -> isStopped ( ) ) { return $ event -> result ; } $ data = $ resource -> extract ( $ this -> getSchema ( ) -> columns ( ) , true ) ; if ( $ resource -> isNew ( ) ) { $ query = $ this -> query ( ) -> create ( ) ; } else { $ query = $ this -> query ( ) -> update ( ) -> where ( $ resource -> extract ( $ primaryColumns ) ) ; } $ query -> set ( $ data ) ; $ result = $ query -> execute ( ) ; if ( ! $ result ) { return false ; } if ( ( $ resource -> isNew ( ) ) && ( $ result instanceof EntityInterface ) ) { return $ result ; } $ className = get_class ( $ resource ) ; return new $ className ( $ resource -> toArray ( ) , [ 'markNew' => false , 'markClean' => true ] ) ; }
Persists an resource based on the fields that are marked as dirty and returns the same resource after a successful save or false in case of any error .
44,428
public function delete ( EntityInterface $ resource , $ options = [ ] ) { return ( bool ) $ this -> query ( ) -> delete ( ) -> where ( [ $ this -> getPrimaryKey ( ) => $ resource -> get ( $ this -> getPrimaryKey ( ) ) ] ) -> execute ( ) ; }
Delete a single resource .
44,429
public function newEntity ( $ data = null , array $ options = [ ] ) { if ( $ data === null ) { $ class = $ this -> getResourceClass ( ) ; $ entity = new $ class ( [ ] , [ 'source' => $ this -> getRegistryAlias ( ) ] ) ; return $ entity ; } $ marshaller = $ this -> marshaller ( ) ; return $ marshaller -> one ( $ data , $ options ) ; }
Create a new entity + associated entities from an array .
44,430
public static function get ( $ alias , array $ options = [ ] ) { if ( isset ( self :: $ _instances [ $ alias ] ) ) { if ( ! empty ( $ options ) && self :: $ _options [ $ alias ] !== $ options ) { throw new RuntimeException ( sprintf ( 'You cannot configure "%s", it already exists in the registry.' , $ alias ) ) ; } return self :: $ _instances [ $ alias ] ; } list ( , $ classAlias ) = pluginSplit ( $ alias ) ; $ options = [ 'alias' => $ classAlias ] + $ options ; if ( empty ( $ options [ 'className' ] ) ) { $ options [ 'className' ] = Inflector :: camelize ( $ alias ) ; } $ className = App :: className ( $ options [ 'className' ] , 'Model/Endpoint' , 'Endpoint' ) ; if ( $ className ) { $ options [ 'className' ] = $ className ; } else { if ( ! isset ( $ options [ 'endpoint' ] ) && strpos ( $ options [ 'className' ] , '\\' ) === false ) { list ( , $ endpoint ) = pluginSplit ( $ options [ 'className' ] ) ; $ options [ 'endpoint' ] = Inflector :: underscore ( $ endpoint ) ; } $ options [ 'className' ] = 'Muffin\Webservice\Model\Endpoint' ; } if ( empty ( $ options [ 'connection' ] ) ) { if ( $ options [ 'className' ] !== 'Muffin\Webservice\Model\Endpoint' ) { $ connectionName = $ options [ 'className' ] :: defaultConnectionName ( ) ; } else { $ pluginParts = explode ( '/' , pluginSplit ( $ alias ) [ 0 ] ) ; $ connectionName = Inflector :: underscore ( end ( $ pluginParts ) ) ; } $ options [ 'connection' ] = ConnectionManager :: get ( $ connectionName ) ; } $ options [ 'registryAlias' ] = $ alias ; self :: $ _instances [ $ alias ] = self :: _create ( $ options ) ; self :: $ _options [ $ alias ] = $ options ; return self :: $ _instances [ $ alias ] ; }
Get a endpoint instance from the registry .
44,431
public function validate ( $ data = null ) { if ( $ data !== null ) { $ this -> setData ( $ data ) ; } if ( $ this -> wasValidated === true ) { return $ this -> wasValidated && count ( $ this -> messages ) === 0 ; } foreach ( $ this -> rules as $ selector => $ valueValidator ) { foreach ( $ this -> getDataWrapper ( ) -> getItemsBySelector ( $ selector ) as $ valueIdentifier => $ value ) { if ( ! $ valueValidator -> validate ( $ value , $ valueIdentifier , $ this -> getDataWrapper ( ) ) ) { foreach ( $ valueValidator -> getMessages ( ) as $ message ) { $ this -> addMessage ( $ valueIdentifier , $ message ) ; } } } } $ this -> wasValidated = true ; return $ this -> wasValidated && count ( $ this -> messages ) === 0 ; }
Performs the validation
44,432
public function clearMessages ( $ item = null ) { if ( is_string ( $ item ) ) { if ( array_key_exists ( $ item , $ this -> messages ) ) { unset ( $ this -> messages [ $ item ] ) ; } } elseif ( $ item === null ) { $ this -> messages = array ( ) ; } return $ this ; }
Clears the messages of an item
44,433
public static function setBySelector ( $ array , $ selector , $ value , $ overwrite = false ) { if ( ! is_array ( $ array ) ) { $ array = array ( ) ; } list ( $ container , $ subselector ) = self :: getSelectorParts ( $ selector ) ; if ( ! $ subselector ) { if ( $ container !== '*' ) { if ( $ overwrite === true || ! array_key_exists ( $ container , $ array ) ) { $ array [ $ container ] = $ value ; } } return $ array ; } if ( $ container !== '*' && ! array_key_exists ( $ container , $ array ) ) { $ array [ $ container ] = array ( ) ; } if ( $ container === '*' ) { foreach ( $ array as $ key => $ v ) { $ array [ $ key ] = self :: setBySelector ( $ array [ $ key ] , $ subselector , $ value , $ overwrite ) ; } } else { $ array [ $ container ] = self :: setBySelector ( $ array [ $ container ] , $ subselector , $ value , $ overwrite ) ; } return $ array ; }
Set values in the array by selector
44,434
public static function getBySelector ( $ array , $ selector ) { if ( strpos ( $ selector , '[*]' ) === false ) { return array ( $ selector => self :: getByPath ( $ array , $ selector ) ) ; } $ result = array ( ) ; list ( $ preffix , $ suffix ) = explode ( '[*]' , $ selector , 2 ) ; $ base = self :: getByPath ( $ array , $ preffix ) ; if ( ! is_array ( $ base ) ) { $ base = array ( ) ; } if ( ! $ suffix ) { foreach ( $ base as $ k => $ v ) { $ result [ "{$preffix}[{$k}]" ] = $ v ; } } else { foreach ( $ base as $ itemKey => $ itemValue ) { if ( is_array ( $ itemValue ) ) { $ result [ "{$preffix}[{$itemKey}]{$suffix}" ] = self :: getByPath ( $ itemValue , $ suffix ) ; } } } return $ result ; }
Get values in the array by selector
44,435
public function remove ( $ alias ) { unset ( $ this -> _instances [ $ alias ] , $ this -> _options [ $ alias ] , $ this -> _config [ $ alias ] ) ; }
Remove a specific endpoint instance from the locator by alias
44,436
public function client ( $ client = null ) { if ( $ client === null ) { return $ this -> getClient ( ) ; } return $ this -> setClient ( $ client ) ; }
Set or return an instance of the client used for communication
44,437
public function webservice ( $ name , WebserviceInterface $ webservice = null ) { if ( $ webservice !== null ) { $ this -> setWebservice ( $ name , $ webservice ) ; } return $ this -> getWebservice ( $ name ) ; }
Set or get a instance of a webservice
44,438
public function getWebservice ( $ name ) { if ( ! isset ( $ this -> _webservices [ $ name ] ) ) { list ( $ pluginName ) = pluginSplit ( App :: shortName ( get_class ( $ this ) , 'Webservice/Driver' ) ) ; $ webserviceClass = implode ( '.' , array_filter ( [ $ pluginName , Inflector :: camelize ( $ name ) ] ) ) ; $ webservice = $ this -> _createWebservice ( $ webserviceClass , [ 'endpoint' => $ name , 'driver' => $ this , ] ) ; $ this -> _webservices [ $ name ] = $ webservice ; } return $ this -> _webservices [ $ name ] ; }
Fetch a webservice instance from the driver registry
44,439
public function logQueries ( $ enable = null ) { if ( $ enable === null ) { return $ this -> _logQueries ; } $ this -> _logQueries = $ enable ; }
Enables or disables query logging for this driver
44,440
protected function _createWebservice ( $ className , array $ options = [ ] ) { $ webservice = App :: className ( $ className , 'Webservice' , 'Webservice' ) ; if ( $ webservice ) { return new $ webservice ( $ options ) ; } $ namespaceParts = explode ( '\\' , get_class ( $ this ) ) ; $ fallbackWebserviceClass = end ( $ namespaceParts ) ; list ( $ pluginName ) = pluginSplit ( $ className ) ; if ( $ pluginName ) { $ fallbackWebserviceClass = $ pluginName . '.' . $ fallbackWebserviceClass ; } $ fallbackWebservice = App :: className ( $ fallbackWebserviceClass , 'Webservice' , 'Webservice' ) ; if ( $ fallbackWebservice ) { return new $ fallbackWebservice ( $ options ) ; } throw new MissingWebserviceClassException ( [ 'class' => $ className , 'fallbackClass' => $ fallbackWebserviceClass ] ) ; }
Creates a Webservice instance .
44,441
public function setColumnType ( $ name , $ type ) { $ this -> _columns [ $ name ] [ 'type' ] = $ type ; $ this -> _typeMap [ $ name ] = $ type ; return $ this ; }
Set the type of a column
44,442
protected function registerDefaultRules ( ) { $ rulesClasses = array ( 'Alpha' , 'AlphaNumeric' , 'AlphaNumHyphen' , 'ArrayLength' , 'ArrayMaxLength' , 'ArrayMinLength' , 'Between' , 'Callback' , 'Date' , 'DateTime' , 'Email' , 'EmailDomain' , 'Equal' , 'FullName' , 'GreaterThan' , 'InList' , 'Integer' , 'IpAddress' , 'Length' , 'LessThan' , 'Match' , 'MaxLength' , 'MinLength' , 'NotInList' , 'NotRegex' , 'Number' , 'Regex' , 'Required' , 'RequiredWhen' , 'RequiredWith' , 'RequiredWithout' , 'Time' , 'Url' , 'Website' , 'File\Extension' , 'File\Image' , 'File\ImageHeight' , 'File\ImageRatio' , 'File\ImageWidth' , 'File\Size' , 'Upload\Required' , 'Upload\Extension' , 'Upload\Image' , 'Upload\ImageHeight' , 'Upload\ImageRatio' , 'Upload\ImageWidth' , 'Upload\Size' , ) ; foreach ( $ rulesClasses as $ class ) { $ fullClassName = '\\' . __NAMESPACE__ . '\Rule\\' . $ class ; $ name = strtolower ( str_replace ( '\\' , '' , $ class ) ) ; $ errorMessage = constant ( $ fullClassName . '::MESSAGE' ) ; $ labeledErrorMessage = constant ( $ fullClassName . '::LABELED_MESSAGE' ) ; $ this -> register ( $ name , $ fullClassName , $ errorMessage , $ labeledErrorMessage ) ; } }
Set up the default rules that come with the library
44,443
public function register ( $ name , $ class , $ errorMessage = '' , $ labeledErrorMessage = '' ) { if ( is_subclass_of ( $ class , '\Sirius\Validation\Rule\AbstractRule' ) ) { $ this -> validatorsMap [ $ name ] = $ class ; } if ( $ errorMessage ) { $ this -> errorMessages [ $ name ] = $ errorMessage ; } if ( $ labeledErrorMessage ) { $ this -> labeledErrorMessages [ $ name ] = $ labeledErrorMessage ; } return $ this ; }
Register a class to be used when creating validation rules
44,444
public function createRule ( $ name , $ options = null , $ messageTemplate = null , $ label = null ) { $ validator = $ this -> construcRuleByNameAndOptions ( $ name , $ options ) ; if ( ! $ messageTemplate ) { $ messageTemplate = $ this -> getSuggestedMessageTemplate ( $ name , ! ! $ label ) ; } if ( is_string ( $ messageTemplate ) && $ messageTemplate !== '' ) { $ validator -> setMessageTemplate ( $ messageTemplate ) ; } if ( is_string ( $ label ) && $ label !== '' ) { $ validator -> setOption ( 'label' , $ label ) ; } return $ validator ; }
Factory method to construct a validator based on options that are used most of the times
44,445
public function setMessages ( $ rule , $ messageWithoutLabel = null , $ messageWithLabel = null ) { if ( $ messageWithoutLabel ) { $ this -> errorMessages [ $ rule ] = $ messageWithoutLabel ; } if ( $ messageWithLabel ) { $ this -> labeledErrorMessages [ $ rule ] = $ messageWithLabel ; } return $ this ; }
Set default error message for a rule
44,446
protected function getSuggestedMessageTemplate ( $ name , $ withLabel ) { $ noLabelMessage = is_string ( $ name ) && isset ( $ this -> errorMessages [ $ name ] ) ? $ this -> errorMessages [ $ name ] : null ; if ( $ withLabel ) { return is_string ( $ name ) && isset ( $ this -> labeledErrorMessages [ $ name ] ) ? $ this -> labeledErrorMessages [ $ name ] : $ noLabelMessage ; } return $ noLabelMessage ; }
Get the error message saved in the registry for a rule where the message is with or without a the label
44,447
protected function _normalizeConfig ( $ config ) { if ( empty ( $ config [ 'driver' ] ) ) { if ( empty ( $ config [ 'service' ] ) ) { throw new MissingConnectionException ( [ 'name' => $ config [ 'name' ] ] ) ; } if ( ! $ config [ 'driver' ] = App :: className ( $ config [ 'service' ] , 'Webservice/Driver' ) ) { throw new MissingDriverException ( [ 'driver' => $ config [ 'driver' ] ] ) ; } } return $ config ; }
Validates certain custom configuration values .
44,448
public function one ( array $ data , array $ options = [ ] ) { list ( $ data , $ options ) = $ this -> _prepareDataAndOptions ( $ data , $ options ) ; $ primaryKey = ( array ) $ this -> _endpoint -> getPrimaryKey ( ) ; $ resourceClass = $ this -> _endpoint -> getResourceClass ( ) ; $ entity = new $ resourceClass ( ) ; $ entity -> setSource ( $ this -> _endpoint -> getRegistryAlias ( ) ) ; if ( isset ( $ options [ 'accessibleFields' ] ) ) { foreach ( ( array ) $ options [ 'accessibleFields' ] as $ key => $ value ) { $ entity -> setAccess ( $ key , $ value ) ; } } $ errors = $ this -> _validate ( $ data , $ options , true ) ; $ properties = [ ] ; foreach ( $ data as $ key => $ value ) { if ( ! empty ( $ errors [ $ key ] ) ) { $ entity -> setInvalidField ( $ key , $ value ) ; continue ; } if ( $ value === '' && in_array ( $ key , $ primaryKey , true ) ) { continue ; } $ properties [ $ key ] = $ value ; } if ( ! isset ( $ options [ 'fieldList' ] ) ) { $ entity -> set ( $ properties ) ; $ entity -> setErrors ( $ errors ) ; return $ entity ; } foreach ( ( array ) $ options [ 'fieldList' ] as $ field ) { if ( array_key_exists ( $ field , $ properties ) ) { $ entity -> set ( $ field , $ properties [ $ field ] ) ; } } $ entity -> setErrors ( $ errors ) ; return $ entity ; }
Hydrate one entity .
44,449
public function beforeDispatch ( Event $ event ) { $ controller = false ; if ( isset ( $ event -> data [ 'controller' ] ) ) { $ controller = $ event -> data [ 'controller' ] ; } if ( $ controller ) { $ callback = [ 'Muffin\Webservice\Model\EndpointRegistry' , 'get' ] ; $ controller -> modelFactory ( 'Endpoint' , $ callback ) ; } }
Method called before the controller is instantiated and called to serve a request . If used with default priority it will be called after the Router has parsed the URL and set the routing params into the request object .
44,450
protected function convertBooleanStrings ( $ v ) { if ( is_array ( $ v ) ) { return array_map ( array ( $ this , 'convertBooleanStrings' ) , $ v ) ; } if ( $ v === 'true' ) { return true ; } if ( $ v === 'false' ) { return false ; } return $ v ; }
Converts true and false strings to TRUE and FALSE
44,451
public function setContext ( $ context = null ) { if ( $ context === null ) { return $ this ; } if ( is_array ( $ context ) ) { $ context = new ArrayWrapper ( $ context ) ; } if ( ! is_object ( $ context ) || ! $ context instanceof WrapperInterface ) { throw new \ InvalidArgumentException ( 'Validator context must be either an array or an instance of Sirius\Validator\DataWrapper\WrapperInterface' ) ; } $ this -> context = $ context ; return $ this ; }
The context of the validator can be used when the validator depends on other values that are not known at the moment the validator is constructed For example when you need to validate an email field matches another email field to confirm the email address
44,452
public function getMessage ( ) { if ( $ this -> success ) { return null ; } $ message = $ this -> getPotentialMessage ( ) ; $ message -> setVariables ( array ( 'value' => $ this -> value ) ) ; return $ message ; }
Retrieve the error message if validation failed
44,453
public function driver ( AbstractDriver $ driver = null ) { if ( $ driver === null ) { return $ this -> getDriver ( ) ; } return $ this -> setDriver ( $ driver ) ; }
Set the driver to use
44,454
public function endpoint ( $ endpoint = null ) { if ( $ endpoint === null ) { return $ this -> getEndpoint ( ) ; } return $ this -> setEndpoint ( $ endpoint ) ; }
Set the endpoint path to use
44,455
public function nestedResource ( array $ conditions ) { foreach ( $ this -> _nestedResources as $ url => $ options ) { if ( count ( array_intersect_key ( array_flip ( $ options [ 'requiredFields' ] ) , $ conditions ) ) !== count ( $ options [ 'requiredFields' ] ) ) { continue ; } return Text :: insert ( $ url , $ conditions ) ; } return false ; }
Checks if a set of conditions match a nested resource
44,456
public function describe ( $ endpoint ) { $ shortName = App :: shortName ( get_class ( $ this ) , 'Webservice' , 'Webservice' ) ; list ( $ plugin , $ name ) = pluginSplit ( $ shortName ) ; $ endpoint = Inflector :: classify ( str_replace ( '-' , '_' , $ endpoint ) ) ; $ schemaShortName = implode ( '.' , array_filter ( [ $ plugin , $ endpoint ] ) ) ; $ schemaClassName = App :: className ( $ schemaShortName , 'Model/Endpoint/Schema' , 'Schema' ) ; if ( $ schemaClassName ) { return new $ schemaClassName ( $ endpoint ) ; } throw new MissingEndpointSchemaException ( [ 'schema' => $ schemaShortName , 'webservice' => $ shortName ] ) ; }
Returns a schema for the provided endpoint
44,457
protected function _executeQuery ( Query $ query , array $ options = [ ] ) { switch ( $ query -> action ( ) ) { case Query :: ACTION_CREATE : return $ this -> _executeCreateQuery ( $ query , $ options ) ; case Query :: ACTION_READ : return $ this -> _executeReadQuery ( $ query , $ options ) ; case Query :: ACTION_UPDATE : return $ this -> _executeUpdateQuery ( $ query , $ options ) ; case Query :: ACTION_DELETE : return $ this -> _executeDeleteQuery ( $ query , $ options ) ; } return false ; }
Execute the appropriate method for a query
44,458
protected function _logQuery ( Query $ query , LoggerInterface $ logger ) { if ( ! $ this -> getDriver ( ) -> isQueryLoggingEnabled ( ) ) { return ; } $ logger -> debug ( $ query -> endpoint ( ) , [ 'params' => $ query -> where ( ) ] ) ; }
Logs a query to the specified logger
44,459
protected function _transformResults ( Endpoint $ endpoint , array $ results ) { $ resources = [ ] ; foreach ( $ results as $ result ) { $ resources [ ] = $ this -> _transformResource ( $ endpoint , $ result ) ; } return $ resources ; }
Loops through the results and turns them into resource objects
44,460
protected function _transformResource ( Endpoint $ endpoint , array $ result ) { $ properties = [ ] ; foreach ( $ result as $ property => $ value ) { $ properties [ $ property ] = $ value ; } return $ this -> _createResource ( $ endpoint -> getResourceClass ( ) , $ properties ) ; }
Turns a single result into a resource
44,461
public static function createFromResource ( Resource $ resource , array $ options = [ ] ) { $ entity = new self ( ) ; $ entity -> applyResource ( $ resource ) ; return $ entity ; }
Creates a instance if the current entity with the values of a resouce
44,462
public function clause ( $ name ) { if ( isset ( $ this -> _parts [ $ name ] ) ) { return $ this -> _parts [ $ name ] ; } return null ; }
Returns any data that was stored in the specified clause .
44,463
public function endpoint ( Endpoint $ endpoint = null ) { if ( $ endpoint === null ) { return $ this -> getRepository ( ) ; } $ this -> repository ( $ endpoint ) ; return $ this ; }
Set the endpoint to be used
44,464
public function webservice ( WebserviceInterface $ webservice = null ) { if ( $ webservice === null ) { return $ this -> _webservice ; } $ this -> _webservice = $ webservice ; return $ this ; }
Set the webservice to be used
44,465
public function where ( $ conditions = null , $ types = [ ] , $ overwrite = false ) { if ( $ conditions === null ) { return $ this -> clause ( 'where' ) ; } $ this -> _parts [ 'where' ] = ( ! $ overwrite ) ? Hash :: merge ( $ this -> clause ( 'where' ) , $ conditions ) : $ conditions ; return $ this ; }
Apply conditions to the query
44,466
public function action ( $ action = null ) { if ( $ action === null ) { return $ this -> clause ( 'action' ) ; } $ this -> _parts [ 'action' ] = $ action ; return $ this ; }
Charge this query s action
44,467
public function limit ( $ limit = null ) { if ( $ limit === null ) { return $ this -> clause ( 'limit' ) ; } $ this -> _parts [ 'limit' ] = $ limit ; return $ this ; }
Sets the number of records that should be retrieved from the webservice accepts an integer or an expression object that evaluates to an integer . In some webservices this operation might not be supported or will require the query to be transformed in order to limit the result set size .
44,468
public function set ( $ fields = null ) { if ( $ fields === null ) { return $ this -> clause ( 'set' ) ; } if ( ! in_array ( $ this -> action ( ) , [ self :: ACTION_CREATE , self :: ACTION_UPDATE ] ) ) { throw new \ UnexpectedValueException ( __ ( 'The action of this query needs to be either create update' ) ) ; } $ this -> _parts [ 'set' ] = $ fields ; return $ this ; }
Set fields to save in resources
44,469
public function applyOptions ( array $ options ) { if ( isset ( $ options [ 'page' ] ) ) { $ this -> page ( $ options [ 'page' ] ) ; unset ( $ options [ 'page' ] ) ; } if ( isset ( $ options [ 'limit' ] ) ) { $ this -> limit ( $ options [ 'limit' ] ) ; unset ( $ options [ 'limit' ] ) ; } if ( isset ( $ options [ 'order' ] ) ) { $ this -> order ( $ options [ 'order' ] ) ; unset ( $ options [ 'order' ] ) ; } if ( isset ( $ options [ 'conditions' ] ) ) { $ this -> where ( $ options [ 'conditions' ] ) ; unset ( $ options [ 'conditions' ] ) ; } $ this -> _options = Hash :: merge ( $ this -> _options , $ options ) ; return $ this ; }
Populates or adds parts to current query clauses using an array . This is handy for passing all query clauses at once .
44,470
public function count ( ) { if ( $ this -> action ( ) !== self :: ACTION_READ ) { return 0 ; } if ( ! $ this -> __resultSet ) { $ this -> _execute ( ) ; } if ( $ this -> __resultSet ) { return $ this -> __resultSet -> total ( ) ; } return 0 ; }
Returns the total amount of results for this query
44,471
protected function _execute ( ) { $ this -> triggerBeforeFind ( ) ; if ( $ this -> __resultSet ) { $ decorator = $ this -> _decoratorClass ( ) ; return new $ decorator ( $ this -> __resultSet ) ; } return $ this -> __resultSet = $ this -> _webservice -> execute ( $ this ) ; }
Executes this query and returns a traversable object containing the results
44,472
public function add ( $ name , $ options = null , $ messageTemplate = null , $ label = null ) { if ( is_array ( $ name ) && ! is_callable ( $ name ) ) { return $ this -> addMultiple ( $ name ) ; } if ( is_string ( $ name ) ) { if ( strpos ( $ name , ' | ' ) !== false ) { return $ this -> addMultiple ( explode ( ' | ' , $ name ) ) ; } if ( strpos ( $ name , '(' ) !== false ) { list ( $ name , $ options , $ messageTemplate , $ label ) = $ this -> parseRule ( $ name ) ; } } if ( ! $ label && $ this -> label ) { $ label = $ this -> label ; } $ validator = $ this -> ruleFactory -> createRule ( $ name , $ options , $ messageTemplate , $ label ) ; return $ this -> addRule ( $ validator ) ; }
Add 1 or more validation rules
44,473
public function remove ( $ name = true , $ options = null ) { if ( $ name === true ) { $ this -> rules = new RuleCollection ( ) ; return $ this ; } $ validator = $ this -> ruleFactory -> createRule ( $ name , $ options ) ; $ this -> rules -> detach ( $ validator ) ; return $ this ; }
Remove validation rule
44,474
protected function getAllPermissions ( ) { $ permissions = & drupal_static ( __FUNCTION__ ) ; if ( ! isset ( $ permissions ) ) { $ permissions = \ Drupal :: service ( 'user.permissions' ) -> getPermissions ( ) ; } return $ permissions ; }
Retrieve all permissions .
44,475
protected function convertPermissions ( array & $ permissions ) { $ all_permissions = $ this -> getAllPermissions ( ) ; foreach ( $ all_permissions as $ name => $ definition ) { $ key = array_search ( $ definition [ 'title' ] , $ permissions ) ; if ( FALSE !== $ key ) { $ permissions [ $ key ] = $ name ; } } }
Convert any permission labels to machine name .
44,476
public function expandEntityBaseFields ( $ entity_type , \ stdClass $ entity , array $ base_fields ) { $ this -> expandEntityFields ( $ entity_type , $ entity , $ base_fields ) ; }
Expands specified base fields on the entity object .
44,477
protected function startCollectingMailSystemMail ( ) { if ( \ Drupal :: moduleHandler ( ) -> moduleExists ( 'mailsystem' ) ) { $ config = \ Drupal :: configFactory ( ) -> getEditable ( 'mailsystem.settings' ) ; $ data = $ config -> getRawData ( ) ; $ this -> storeOriginalConfiguration ( 'mailsystem.settings' , $ data ) ; $ data = $ this -> findMailSystemSenders ( $ data ) ; $ config -> setData ( $ data ) -> save ( ) ; } }
If the Mail System module is enabled collect that mail too .
44,478
protected function findMailSystemSenders ( array $ data ) { foreach ( $ data as $ key => $ values ) { if ( is_array ( $ values ) ) { if ( isset ( $ values [ MailsystemManager :: MAILSYSTEM_TYPE_SENDING ] ) ) { $ data [ $ key ] [ MailsystemManager :: MAILSYSTEM_TYPE_SENDING ] = 'test_mail_collector' ; } else { $ data [ $ key ] = $ this -> findMailSystemSenders ( $ values ) ; } } } return $ data ; }
Find and replace all the mail system sender plugins with the test plugin .
44,479
protected function stopCollectingMailSystemMail ( ) { if ( \ Drupal :: moduleHandler ( ) -> moduleExists ( 'mailsystem' ) ) { \ Drupal :: configFactory ( ) -> getEditable ( 'mailsystem.settings' ) -> setData ( $ this -> originalConfiguration [ 'mailsystem.settings' ] ) -> save ( ) ; } }
If the Mail System module is enabled stop collecting those mails .
44,480
protected function storeOriginalConfiguration ( $ name , $ value ) { if ( ! isset ( $ this -> originalConfiguration [ $ name ] ) ) { $ this -> originalConfiguration [ $ name ] = $ value ; } }
Store the original value for a piece of configuration .
44,481
protected function isLegacyDrush ( ) { try { $ version = trim ( $ this -> drush ( 'version' , [ ] , [ 'format' => 'string' ] ) ) ; return version_compare ( $ version , '9' , '<=' ) ; } catch ( \ RuntimeException $ e ) { return TRUE ; } }
Determine if drush is a legacy version .
44,482
protected function parseUserId ( $ info ) { preg_match ( '/User ID\s+:\s+\d+/' , $ info , $ matches ) ; if ( ! empty ( $ matches ) ) { list ( , $ uid ) = explode ( ':' , $ matches [ 0 ] ) ; return ( int ) $ uid ; } }
Parse user id from drush user - information output .
44,483
protected function decodeJsonObject ( $ output ) { $ output = preg_replace ( '/^[^\{]*/' , '' , $ output ) ; $ output = preg_replace ( '/[^\}]*$/s' , '' , $ output ) ; return json_decode ( $ output ) ; }
Decodes JSON object returned by Drush .
44,484
protected static function parseArguments ( array $ arguments ) { $ string = '' ; foreach ( $ arguments as $ name => $ value ) { if ( is_null ( $ value ) ) { $ string .= ' --' . $ name ; } else { $ string .= ' --' . $ name . '=' . $ value ; } } return $ string ; }
Parse arguments into a string .
44,485
public function drush ( $ command , array $ arguments = array ( ) , array $ options = array ( ) ) { $ arguments = implode ( ' ' , $ arguments ) ; if ( isset ( static :: $ isLegacyDrush ) && static :: $ isLegacyDrush ) { $ options [ 'nocolor' ] = TRUE ; } else { $ options [ 'no-ansi' ] = NULL ; } $ string_options = $ this -> parseArguments ( $ options ) ; $ alias = isset ( $ this -> alias ) ? "@{$this->alias}" : '--root=' . $ this -> root ; $ global = $ this -> getArguments ( ) ; $ process = new Process ( "{$this->binary} {$alias} {$string_options} {$global} {$command} {$arguments}" ) ; $ process -> setTimeout ( 3600 ) ; $ process -> run ( ) ; if ( ! $ process -> isSuccessful ( ) ) { throw new \ RuntimeException ( $ process -> getErrorOutput ( ) ) ; } if ( ! $ process -> getOutput ( ) ) { return $ process -> getErrorOutput ( ) ; } else { return $ process -> getOutput ( ) ; } }
Execute a drush command .
44,486
public function getDrupalVersion ( ) { if ( ! isset ( $ this -> version ) ) { $ version_constant_paths = array ( '/modules/system/system.module' , '/includes/bootstrap.inc' , '/autoload.php' , '/core/includes/bootstrap.inc' , ) ; if ( $ this -> drupalRoot === FALSE ) { throw new BootstrapException ( '`drupal_root` parameter must be defined.' ) ; } foreach ( $ version_constant_paths as $ path ) { if ( file_exists ( $ this -> drupalRoot . $ path ) ) { require_once $ this -> drupalRoot . $ path ; } } if ( defined ( 'VERSION' ) ) { $ version = VERSION ; } elseif ( defined ( '\Drupal::VERSION' ) ) { $ version = \ Drupal :: VERSION ; } else { throw new BootstrapException ( 'Unable to determine Drupal core version. Supported versions are 6, 7, and 8.' ) ; } $ version_parts = explode ( '.' , $ version ) ; if ( is_numeric ( $ version_parts [ 0 ] ) ) { $ this -> version = ( integer ) $ version_parts [ 0 ] ; } else { throw new BootstrapException ( sprintf ( 'Unable to extract major Drupal core version from version string %s.' , $ version ) ) ; } } return $ this -> version ; }
Determine major Drupal version .
44,487
public function setCore ( array $ available_cores ) { if ( ! isset ( $ available_cores [ $ this -> version ] ) ) { throw new BootstrapException ( sprintf ( 'There is no available Drupal core controller for Drupal version %s.' , $ this -> version ) ) ; } $ this -> core = $ available_cores [ $ this -> version ] ; }
Instantiate and set Drupal core class .
44,488
public function setCoreFromVersion ( ) { $ core = '\Drupal\Driver\Cores\Drupal' . $ this -> getDrupalVersion ( ) ; $ this -> core = new $ core ( $ this -> drupalRoot , $ this -> uri ) ; }
Automatically set the core from the current version .
44,489
protected function getAllPermissions ( ) { $ permissions = array ( ) ; foreach ( module_invoke_all ( 'permission' ) as $ name => $ permission ) { $ permissions [ $ name ] = $ permission [ 'title' ] ; } return $ permissions ; }
Helper function to get all permissions .
44,490
public function getEntityLanguage ( ) { if ( field_is_translatable ( $ this -> entityType , $ this -> fieldInfo ) ) { return entity_language ( $ this -> entityType , $ this -> entity ) ; } return LANGUAGE_NONE ; }
Returns the entity language .
44,491
protected function taxonomyVocabularyLoadMultiple ( array $ vids = array ( ) ) { $ vocabularies = taxonomy_get_vocabularies ( ) ; if ( $ vids ) { return array_intersect_key ( $ vocabularies , array_flip ( $ vids ) ) ; } return $ vocabularies ; }
Load vocabularies optional by VIDs .
44,492
protected function makeCacheableDir ( ) { if ( $ this -> configure [ 'cache' ] ) { $ this -> makeDirectories ( strval ( $ this -> configure [ 'cache_dir' ] ) , 0775 ) ; $ this -> cacheable = true ; } }
make aspect cache directory
44,493
protected function registerAspectModule ( ) { if ( isset ( $ this -> configure [ 'modules' ] ) ) { foreach ( $ this -> configure [ 'modules' ] as $ module ) { $ this -> register ( $ module ) ; } } }
register Aspect Module
44,494
public function ignoredAnnotations ( ) : void { if ( isset ( $ this -> configuration [ 'ignores' ] ) ) { $ ignores = $ this -> configuration [ 'ignores' ] ; if ( count ( $ ignores ) ) { foreach ( $ ignores as $ ignore ) { AnnotationReader :: addGlobalIgnoredName ( $ ignore ) ; } } } }
Add a new annotation to the globally ignored annotation names with regard to exception handling .
44,495
public function detectLanguage ( ServerRequest $ request , $ default = null ) { if ( empty ( $ default ) ) { $ lang = $ this -> _config [ 'defaultLanguage' ] ; } else { $ lang = $ default ; } $ browserLangs = $ request -> acceptLanguage ( ) ; foreach ( $ browserLangs as $ k => $ langKey ) { if ( strpos ( $ langKey , '-' ) !== false ) { $ browserLangs [ $ k ] = substr ( $ langKey , 0 , 2 ) ; } } $ acceptedLangs = array_intersect ( $ browserLangs , array_keys ( $ this -> _config [ 'languages' ] ) ) ; if ( ! empty ( $ acceptedLangs ) ) { $ lang = reset ( $ acceptedLangs ) ; } return $ lang ; }
Get languages accepted by browser and return the one matching one of those in config var I18n . languages .
44,496
protected function _extract ( ) { $ this -> out ( ) ; $ this -> out ( ) ; $ this -> out ( 'Extracting...' ) ; $ this -> hr ( ) ; $ this -> out ( 'Paths:' ) ; foreach ( $ this -> _paths as $ path ) { $ this -> out ( ' ' . $ path ) ; } $ this -> hr ( ) ; $ this -> _extractTokens ( ) ; $ this -> _languages ( ) ; $ this -> _write ( ) ; $ this -> _paths = $ this -> _files = $ this -> _storage = [ ] ; $ this -> _translations = $ this -> _tokens = [ ] ; $ this -> out ( ) ; $ this -> out ( 'Done.' ) ; }
Extract text .
44,497
protected function _write ( ) { $ paths = $ this -> _paths ; $ paths [ ] = realpath ( APP ) . DIRECTORY_SEPARATOR ; usort ( $ paths , function ( $ a , $ b ) { return strlen ( $ a ) - strlen ( $ b ) ; } ) ; $ domains = null ; if ( ! empty ( $ this -> params [ 'domains' ] ) ) { $ domains = explode ( ',' , $ this -> params [ 'domains' ] ) ; } foreach ( $ this -> _translations as $ domain => $ translations ) { if ( ! empty ( $ domains ) && ! in_array ( $ domain , $ domains ) ) { continue ; } if ( $ this -> _merge ) { $ domain = 'default' ; } foreach ( $ translations as $ msgid => $ contexts ) { foreach ( $ contexts as $ context => $ details ) { $ references = null ; if ( ! $ this -> param ( 'no-location' ) ) { $ files = $ details [ 'references' ] ; $ occurrences = [ ] ; foreach ( $ files as $ file => $ lines ) { $ lines = array_unique ( $ lines ) ; $ occurrences [ ] = $ file . ':' . implode ( ';' , $ lines ) ; } $ occurrences = implode ( "\n" , $ occurrences ) ; $ occurrences = str_replace ( $ paths , '' , $ occurrences ) ; $ references = str_replace ( DIRECTORY_SEPARATOR , '/' , $ occurrences ) ; } $ this -> _save ( $ domain , $ msgid , $ details [ 'msgid_plural' ] === false ? null : $ details [ 'msgid_plural' ] , $ context ? : null , $ references ) ; } } } }
Write translations to database .
44,498
protected function _save ( $ domain , $ singular , $ plural = null , $ context = null , $ refs = null ) { $ model = $ this -> _model ( ) ; foreach ( $ this -> _languages as $ locale ) { $ found = $ model -> find ( ) -> where ( compact ( 'domain' , 'locale' , 'singular' ) ) -> count ( ) ; if ( ! $ found ) { $ entity = $ model -> newEntity ( compact ( 'domain' , 'locale' , 'singular' , 'plural' , 'context' , 'refs' ) , [ 'guard' => false ] ) ; $ model -> save ( $ entity ) ; } } }
Save translation record to database .
44,499
protected function _model ( ) { if ( $ this -> _model !== null ) { return $ this -> _model ; } $ model = 'I18nMessages' ; if ( ! empty ( $ this -> params [ 'model' ] ) ) { $ model = $ this -> params [ 'model' ] ; } return $ this -> _model = TableRegistry :: get ( $ model ) ; }
Get translation model .