idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
11,600
public function get ( $ url , $ params = null ) { $ this -> params = $ params ; $ this -> method = 'GET' ; $ this -> url = $ url ; return $ this -> request ( ) ; }
Make a GET query
11,601
public function getSetting ( $ key = null , $ default = null ) { return $ this -> getSettingsComponent ( ) -> get ( $ this -> getSettingsCategory ( ) , $ key , $ default ) ; }
Returns settings from current category .
11,602
public function add ( $ value ) { if ( ! is_string ( $ value ) ) { throw new UnexpectedTypeException ( $ value , 'string' , 'value' ) ; } if ( empty ( $ value ) ) { return ; } if ( $ this -> allowTokenize ) { $ this -> values = array_merge ( $ this -> values , explode ( $ this -> delimiter , $ value ) ) ; } else { $ this -> values [ ] = $ value ; } }
Requests to add new value
11,603
public function remove ( $ value ) { if ( ! is_string ( $ value ) ) { throw new UnexpectedTypeException ( $ value , 'string' , 'value' ) ; } if ( empty ( $ value ) ) { return ; } if ( $ this -> allowTokenize ) { $ this -> values = array_diff ( $ this -> values , explode ( $ this -> delimiter , $ value ) ) ; } else { $ this -> values = array_diff ( $ this -> values , [ $ value ] ) ; } }
Requests to remove existing value
11,604
public function replace ( $ oldValue , $ newValue ) { if ( ! is_string ( $ oldValue ) ) { throw new UnexpectedTypeException ( $ oldValue , 'string' , 'oldValue' ) ; } if ( empty ( $ oldValue ) ) { return ; } if ( ! is_string ( $ newValue ) && null !== $ newValue ) { throw new UnexpectedTypeException ( $ newValue , 'string or null' , 'newValue' ) ; } $ key = array_search ( $ oldValue , $ this -> values , true ) ; if ( false !== $ key ) { if ( empty ( $ newValue ) ) { unset ( $ this -> values [ $ key ] ) ; } else { $ this -> values [ $ key ] = $ newValue ; } } }
Requests to replace one value with another value
11,605
public function copy ( $ target ) { if ( ! parent :: copy ( $ target ) ) return false ; return copy ( $ this -> fileSource , $ target ) ; }
Copies the stored file s content to the local filesystem .
11,606
public function indexSearch ( $ searchText , $ maxResults ) { $ words = SearchAnalyser :: analyse ( $ searchText ) ; if ( ! $ words ) { return [ ] ; } $ query = $ this -> _em -> createQueryBuilder ( ) -> select ( 'o' ) -> from ( $ this -> _entityName , 'o' ) -> setMaxResults ( $ maxResults ) ; $ parameters = [ ] ; foreach ( $ words as $ k => $ word ) { $ subquery = $ this -> _em -> createQueryBuilder ( ) -> select ( "i$k.keyword" ) -> from ( $ this -> getSearchIndexClass ( ) , "i$k" ) -> where ( "i$k.object = o" ) -> andWhere ( "i$k.keyword ILIKE :search$k" ) ; $ query -> andWhere ( $ query -> expr ( ) -> exists ( $ subquery -> getDql ( ) ) ) ; $ parameters [ "search$k" ] = '%' . $ word . '%' ; } $ query -> setParameters ( $ parameters ) ; $ results = $ query -> getQuery ( ) -> execute ( ) ; return $ results ; }
Find the entities that have the appropriate keywords in their searchIndex .
11,607
public function truncateTable ( ) { $ connection = $ this -> _em -> getConnection ( ) ; $ dbPlatform = $ connection -> getDatabasePlatform ( ) ; $ connection -> beginTransaction ( ) ; try { $ q = $ dbPlatform -> getTruncateTableSql ( $ this -> getSearchIndexTable ( ) ) ; $ connection -> executeUpdate ( $ q ) ; $ connection -> commit ( ) ; return true ; } catch ( \ Exception $ e ) { $ connection -> rollback ( ) ; return false ; } }
Truncates the search index table .
11,608
public function setAttribute ( $ key , $ value ) { if ( $ value instanceof BaseModel || $ value instanceof Collection ) $ this -> setRelationship ( $ value , $ key ) ; elseif ( ! is_array ( $ value ) ) $ this -> attributes [ $ key ] = $ value ; else $ this -> setRelationship ( $ value , $ key ) ; }
Sets the attributes for this model
11,609
public function setRelationship ( $ value , $ key = '' ) { if ( is_array ( $ value ) ) { $ class = __NAMESPACE__ . '\\' . str_singular ( $ key ) ; if ( class_exists ( $ class ) ) { if ( str_singular ( $ key ) == $ key ) { $ this -> addRelationship ( new $ class ( $ value ) ) ; } else { $ collection = $ class :: newCollection ( $ value ) ; $ this -> addRelationship ( $ collection ) ; } } } elseif ( $ value instanceof Collection ) { $ this -> addRelationship ( $ value ) ; } elseif ( $ value instanceof BaseModel ) { $ this -> addRelationship ( $ value ) ; } }
Sets the relationships on this model which in fact are collections of other models
11,610
public function setAttributes ( array $ data ) { $ data = $ this -> stripResponseData ( $ data ) ; foreach ( $ data as $ key => $ value ) { $ this -> setAttribute ( $ key , $ value ) ; } return $ this -> getAttributes ( ) ; }
Set all the attributes from an array .
11,611
public static function getSingularEntityName ( ) { if ( isset ( self :: $ entity_singular ) && ! empty ( self :: $ entity_singular ) ) return self :: $ entity_singular ; return str_singular ( self :: getEntityName ( ) ) ; }
Retrieves the singular name of the entity we are querying .
11,612
public function request ( $ method , $ url , $ params = array ( ) , $ xml = "" , $ format = "" ) { if ( ! $ format ) $ format = $ this -> format ; $ response = $ this -> api -> request ( $ method , $ url , $ params , $ xml , $ format ) ; return $ this -> parseResponse ( $ response ) ; }
A high level request method used from static methods .
11,613
public static function get ( $ params = array ( ) ) { $ object = new static ; $ data = $ object -> request ( 'GET' , $ object -> getUrl ( ) , $ params ) ; $ data = $ object -> stripResponseData ( $ data ) ; $ collection = self :: newCollection ( ) ; if ( isset ( $ data [ 0 ] ) && is_array ( $ data [ 0 ] ) ) { $ collection -> setItems ( $ data ) ; } return $ collection ; }
Get a collection of items
11,614
public static function find ( $ id ) { $ object = new static ; $ response = $ object -> request ( 'GET' , sprintf ( '%s/%s' , $ object -> getUrl ( ) , $ id ) ) ; return $ response ? $ object : false ; }
Find a single element by its ID
11,615
public function create ( $ params = array ( ) ) { $ response = $ this -> api -> request ( 'PUT' , $ this -> getUrl ( ) , $ params , $ this -> toXML ( ) , $ this -> format ) ; return $ this -> parseResponse ( $ response ) ? true : false ; }
Creates a new entity in Xero
11,616
public function save ( $ params = array ( ) ) { if ( isset ( $ this -> attributes [ $ this -> primary_column ] ) ) { return $ this -> update ( $ params ) ; } else { return $ this -> create ( $ params ) ; } }
Save an entity . If it doesn t have the primary key set then it will create it otherwise it will update it .
11,617
public static function array_to_xml ( $ array , & $ xml ) { foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { if ( ! is_numeric ( $ key ) ) { $ subnode = $ xml -> addChild ( "$key" ) ; self :: array_to_xml ( $ value , $ subnode ) ; } elseif ( $ key == 0 ) { self :: array_to_xml ( $ value , $ xml ) ; } else { $ name = $ xml -> getName ( ) ; $ subnode = $ xml -> xpath ( ".." ) [ 0 ] -> addChild ( "$name" ) ; self :: array_to_xml ( $ value , $ subnode ) ; } } else { $ xml -> addChild ( "$key" , "$value" ) ; } } }
Helper function to convert an array to XML
11,618
public function stripResponseData ( array $ data ) { if ( isset ( $ data [ self :: getEntityName ( ) ] ) && is_array ( $ data [ self :: getEntityName ( ) ] ) ) $ data = $ data [ self :: getEntityName ( ) ] ; if ( isset ( $ data [ self :: getSingularEntityName ( ) ] ) && is_array ( $ data [ self :: getSingularEntityName ( ) ] ) ) $ data = $ data [ self :: getSingularEntityName ( ) ] ; return $ data ; }
This function removes all the unecessary data from a response and leaves us with what we need when trying to populate objects or collections with data
11,619
protected function parseResponse ( $ response , $ setAttributes = true ) { if ( $ response [ 'code' ] == 200 ) { $ data = $ this -> api -> parseResponse ( $ response [ 'response' ] , $ response [ 'format' ] ) ; if ( $ response [ 'format' ] == 'xml' ) { $ data = json_encode ( $ data ) ; $ data = json_decode ( $ data , true ) ; } if ( $ setAttributes && is_array ( $ data ) ) $ this -> setAttributes ( $ data ) ; return $ data ; } elseif ( $ response [ 'code' ] == 404 ) { return false ; } else { throw new XeroGeneralException ( 'Error from Xero: ' . $ response [ 'response' ] ) ; } }
Parses the response retrieved from Xero or throws an exception if it fails .
11,620
public function handleNotice ( UserEvent $ event , Queue $ queue ) { if ( strcasecmp ( $ event -> getNick ( ) , $ this -> botNick ) !== 0 ) { return ; } $ connection = $ event -> getConnection ( ) ; $ params = $ event -> getParams ( ) ; $ message = $ params [ 'text' ] ; if ( preg_match ( $ this -> identifyPattern , $ message ) ) { return $ queue -> ircPrivmsg ( $ this -> botNick , 'IDENTIFY ' . $ this -> password ) ; } if ( preg_match ( $ this -> loginPattern , $ message ) ) { return $ this -> getEventEmitter ( ) -> emit ( 'nickserv.identified' , [ $ connection , $ queue ] ) ; } if ( $ this -> ghostNick !== null && preg_match ( $ this -> ghostPattern , $ message ) ) { $ queue -> ircNick ( $ this -> ghostNick ) ; $ this -> ghostNick = null ; return ; } }
Responds to authentication requests and notifications of ghost connections being killed from NickServ .
11,621
public function handleNick ( UserEvent $ event , Queue $ queue ) { $ connection = $ event -> getConnection ( ) ; if ( strcasecmp ( $ event -> getNick ( ) , $ connection -> getNickname ( ) ) === 0 ) { $ params = $ event -> getParams ( ) ; $ connection -> setNickname ( $ params [ 'nickname' ] ) ; } }
Changes the nick associated with the bot in local memory when a change to it is successfully registered with the server .
11,622
public function handleNicknameInUse ( ServerEvent $ event , Queue $ queue ) { if ( ! $ this -> ghostEnabled || $ this -> ghostNick !== null ) { return ; } $ params = $ event -> getParams ( ) ; $ this -> ghostNick = $ params [ 1 ] ; }
Kick - starts the ghost process .
11,623
public function handleGhost ( ServerEvent $ event , Queue $ queue ) { if ( $ this -> ghostNick === null ) { return ; } $ queue -> ircPrivmsg ( $ this -> botNick , 'GHOST ' . $ this -> ghostNick . ' ' . $ this -> password ) ; }
Completes the ghost process .
11,624
protected function getConfigOption ( array $ config , $ key ) { if ( empty ( $ config [ $ key ] ) || ! is_string ( $ config [ $ key ] ) ) { throw new \ DomainException ( "$key must be a non-empty string" ) ; } return $ config [ $ key ] ; }
Extracts a string from the config options map .
11,625
protected function message ( $ message , $ title = '' , $ type = 'info' ) { $ this -> message = $ message ; $ this -> title = $ title ; $ this -> type = $ type ; $ this -> session -> flash ( $ this -> namespace , ( array ) $ this ) ; }
Setup the flash messsage data .
11,626
public function actionDelete ( $ id ) { $ date = new DateTime ( 'now' ) ; $ model = $ this -> findModel ( $ id ) ; $ model -> deleted_at = $ date -> format ( "U" ) ; $ model -> save ( ) ; return $ this -> redirect ( [ 'index' ] ) ; }
Deletes an existing Address model . If deletion is successful the browser will be redirected to the index page .
11,627
public function lookup ( $ context , $ path , $ require = false ) { if ( empty ( $ path ) ) { throw new \ InvalidArgumentException ( "Passed lookup path is empty." ) ; } if ( empty ( $ context ) ) { throw new \ InvalidArgumentException ( "Specified context is empty while resolving path " . json_encode ( $ path ) ) ; } return PropertyAccessor :: getByPath ( $ context , $ this -> path ( $ path ) , $ require ) ; }
Looks up a path in the specified context
11,628
public function resolve ( $ id , $ required = false ) { $ id = $ this -> path ( $ id ) ; try { if ( in_array ( $ id , $ this -> resolutionStack ) ) { $ path = array_map ( function ( $ a ) { return join ( '.' , $ a ) ; } , $ this -> resolutionStack ) ; throw new CircularReferenceException ( sprintf ( "Circular reference detected: %s -> %s" , implode ( ' -> ' , $ path ) , join ( '.' , $ id ) ) ) ; } array_push ( $ this -> resolutionStack , $ id ) ; $ ret = $ this -> value ( $ this -> lookup ( $ this -> values , $ id , $ required ) ) ; array_pop ( $ this -> resolutionStack ) ; return $ ret ; } catch ( \ Exception $ e ) { if ( $ e instanceof CircularReferenceException ) { throw $ e ; } throw new \ RuntimeException ( "While resolving value " . join ( "." , $ id ) , 0 , $ e ) ; } }
Resolve the specified path . If the resulting value is a Closure it s assumed a declaration and therefore executed
11,629
public function set ( $ path , $ value ) { PropertyAccessor :: setByPath ( $ this -> values , $ this -> path ( $ path ) , $ value ) ; }
Set the value at the specified path
11,630
public function helperExec ( $ cmd ) { if ( $ this -> resolve ( 'EXPLAIN' ) ) { $ this -> output -> writeln ( "# Task needs the following helper command:" ) ; $ this -> output -> writeln ( "# " . str_replace ( "\n" , "\\n" , $ cmd ) ) ; } $ ret = '' ; $ this -> executor -> execute ( $ cmd , $ ret ) ; return $ ret ; }
This is useful for commands that need the shell regardless of the explain value setting .
11,631
public function fn ( $ id , $ callable = null , $ needsContainer = false ) { if ( $ callable === null ) { $ callable = $ id ; } if ( ! is_callable ( $ callable ) ) { throw new \ InvalidArgumentException ( "Not callable" ) ; } $ this -> set ( $ id , array ( $ callable , $ needsContainer ) ) ; }
Set a function at the specified path .
11,632
public function decl ( $ id , $ callable ) { if ( ! is_callable ( $ callable ) ) { throw new \ InvalidArgumentException ( "Passed declaration is not callable" ) ; } $ this -> set ( $ id , function ( Container $ c ) use ( $ callable , $ id ) { Debug :: enterScope ( join ( '.' , ( array ) $ id ) ) ; if ( null !== ( $ value = call_user_func ( $ callable , $ c ) ) ) { $ c -> set ( $ id , $ value ) ; } Debug :: exitScope ( join ( '.' , ( array ) $ id ) ) ; return $ value ; } ) ; }
Does a declaration i . e . the first time the declaration is called it s resulting value overwrites the declaration .
11,633
public function has ( $ id ) { try { $ existing = $ this -> get ( $ id ) ; } catch ( \ OutOfBoundsException $ e ) { return false ; } return Util :: typeOf ( $ existing ) ; }
Checks for existence of the specified path .
11,634
public function isEmpty ( $ path ) { try { $ value = $ this -> get ( $ path ) ; } catch ( \ OutOfBoundsException $ e ) { return true ; } return '' === $ value || null === $ value ; }
Checks if a value is empty .
11,635
public function call ( ) { $ args = func_get_args ( ) ; $ service = array_shift ( $ args ) ; if ( ! is_array ( $ service ) ) { throw new \ RuntimeException ( "Expected an array" ) ; } if ( ! is_callable ( $ service [ 0 ] ) ) { throw new \ InvalidArgumentException ( "Can not use service '{$service[0]}' as a function, it is not callable" ) ; } if ( $ service [ 1 ] ) { array_unshift ( $ args , $ this ) ; } return call_user_func_array ( $ service [ 0 ] , $ args ) ; }
Separate helper for calling a service as a function .
11,636
private function setOutputPrefix ( $ prefix ) { if ( ! ( $ this -> output -> getFormatter ( ) instanceof PrefixFormatter ) ) { return ; } $ this -> output -> getFormatter ( ) -> prefix = $ prefix ; }
Helper to set prefix if the output if PrefixFormatter
11,637
public function exec ( $ cmd ) { if ( trim ( $ cmd ) ) { $ this -> setOutputPrefix ( '' ) ; if ( $ this -> resolve ( 'DEBUG' ) ) { $ this -> output -> writeln ( '<comment># ' . join ( '::' , Debug :: $ scope ) . "</comment>" ) ; } if ( $ this -> resolve ( 'EXPLAIN' ) ) { if ( $ this -> resolve ( 'INTERACTIVE' ) ) { $ this -> notice ( 'interactive shell:' ) ; $ line = '( /bin/bash -c \'' . trim ( $ cmd ) . '\' )' ; } else { $ line = 'echo ' . escapeshellarg ( trim ( $ cmd ) ) . ' | ' . $ this -> resolve ( array ( 'SHELL' ) ) ; } $ this -> output -> writeln ( $ line ) ; } else { $ this -> executor -> execute ( $ cmd ) ; } } }
Executes a script snippet using the executor service .
11,638
public function str ( $ value ) { if ( is_array ( $ value ) ) { $ allScalar = function ( $ a , $ b ) { return $ a && is_scalar ( $ b ) ; } ; if ( ! array_reduce ( $ value , $ allScalar , true ) ) { throw new UnexpectedValueException ( "Unexpected complex type " . Util :: toPhp ( $ value ) ) ; } return join ( ' ' , $ value ) ; } return ( string ) $ value ; }
Convert the value to a string .
11,639
public function push ( $ varName , $ tail ) { if ( false === $ this -> has ( $ varName ) ) { $ this -> set ( $ varName , null ) ; } if ( ! isset ( $ this -> varStack [ json_encode ( $ varName ) ] ) ) { $ this -> varStack [ json_encode ( $ varName ) ] = array ( ) ; } array_push ( $ this -> varStack [ json_encode ( $ varName ) ] , $ this -> get ( $ varName ) ) ; $ this -> set ( $ varName , $ tail ) ; }
Push a var on a local stack by it s name .
11,640
public function pop ( $ varName ) { $ this -> set ( $ varName , array_pop ( $ this -> varStack [ json_encode ( $ varName ) ] ) ) ; }
Pop a var from a local var stack .
11,641
public function argumentsForCallback ( callable $ callback ) : array { $ definition = new ReflectionFunction ( $ callback ) ; $ arguments = [ ] ; foreach ( $ definition -> getParameters ( ) as $ parameter ) { if ( $ type = $ parameter -> getType ( ) ) { $ arguments [ ] = Phony :: emptyValue ( $ type ) ; } else { $ arguments [ ] = null ; } } return $ arguments ; }
Returns an argument list of test doubles for the supplied callback .
11,642
protected function qualifyClass ( $ name ) { $ rootNamespace = $ this -> rootNamespace ( ) ; if ( Str :: startsWith ( $ name , $ rootNamespace . '\\' ) ) { return $ name ; } $ name = str_replace ( '/' , '\\' , $ name ) ; return $ this -> qualifyClass ( $ this -> getDefaultNamespace ( trim ( $ rootNamespace , '\\' ) ) . '\\' . $ name ) ; }
Parse the class name and format according to the root namespace .
11,643
public function get ( $ name = null ) { if ( count ( $ this -> connectors ) > 0 ) { if ( ! is_null ( $ name ) ) { if ( ! isset ( $ this -> connectors [ $ name ] ) ) throw new \ Exception ( "unknown Connector: $name" ) ; return $ this -> connectors [ $ name ] ; } return current ( $ this -> connectors ) ; } throw new \ Exception ( 'No Connectors found' ) ; }
get an Connector by its name or it will return the default Connector
11,644
protected function registerFractal ( ) { $ this -> app -> bind ( SerializerAbstract :: class , function ( $ app ) { $ serializer = $ app -> config -> get ( 'responder.serializer' ) ; return new $ serializer ; } ) ; $ this -> app -> bind ( Manager :: class , function ( $ app ) { return ( new Manager ( ) ) -> setSerializer ( $ app [ SerializerAbstract :: class ] ) ; } ) ; $ this -> app -> bind ( ResourceFactory :: class , function ( ) { return new ResourceFactory ( ) ; } ) ; }
Register Fractal serializer manager and a factory to generate Fractal resource instances .
11,645
protected function registerResponseBuilders ( ) { $ this -> app -> bind ( SuccessResponseBuilder :: class , function ( $ app ) { $ builder = new SuccessResponseBuilder ( response ( ) , $ app [ ResourceFactory :: class ] , $ app [ Manager :: class ] ) ; if ( $ parameter = $ app -> config -> get ( 'responder.load_relations_from_parameter' ) ) { $ builder -> include ( $ this -> app [ Request :: class ] -> input ( $ parameter , [ ] ) ) ; } $ builder -> setIncludeSuccessFlag ( $ app -> config -> get ( 'responder.include_success_flag' ) ) ; return $ builder -> setIncludeStatusCode ( $ app -> config -> get ( 'responder.include_status_code' ) ) ; } ) ; $ this -> app -> bind ( ErrorResponseBuilder :: class , function ( $ app ) { $ builder = new ErrorResponseBuilder ( response ( ) , $ app [ 'translator' ] ) ; $ builder -> setIncludeSuccessFlag ( $ app -> config -> get ( 'responder.include_success_flag' ) ) ; return $ builder -> setIncludeStatusCode ( $ app -> config -> get ( 'responder.include_status_code' ) ) ; } ) ; }
Register success and error response builders .
11,646
protected function registerAliases ( ) { $ this -> app -> alias ( Responder :: class , 'responder' ) ; $ this -> app -> alias ( SuccessResponseBuilder :: class , 'responder.success' ) ; $ this -> app -> alias ( ErrorResponseBuilder :: class , 'responder.error' ) ; $ this -> app -> alias ( Manager :: class , 'responder.manager' ) ; $ this -> app -> alias ( Manager :: class , 'responder.serializer' ) ; }
Set aliases for the provided services .
11,647
public function run ( array $ notification , array $ variables = null , array $ recipients = null ) { $ typeName = Arr :: get ( $ notification , 'type.name' ) ; switch ( $ typeName ) { case 'email' : $ instance = app ( EmailNotification :: class ) ; break ; case 'sms' : $ instance = app ( SmsNotification :: class ) ; break ; default : $ instance = app ( CustomNotification :: class ) ; break ; } $ instance -> setPredefinedVariables ( $ variables ) ; $ instance -> setModel ( $ notification ) ; if ( $ instance instanceof SendableNotification ) { $ instance -> setRecipients ( $ recipients ) ; if ( ! $ this -> validate ( $ instance ) ) { return false ; } $ type = $ instance -> getType ( ) ; $ job = $ instance -> onConnection ( 'database' ) -> onQueue ( $ type ) ; $ this -> dispatch ( $ job ) ; } else { return $ instance -> handle ( ) ; } }
Sends notification .
11,648
public function getDownloaderForInstalledPackage ( PackageInterface $ package ) { $ installationSource = $ package -> getInstallationSource ( ) ; if ( 'metapackage' === $ package -> getType ( ) ) { return ; } if ( 'dist' === $ installationSource ) { $ downloader = $ this -> getDownloader ( $ package -> getDistType ( ) ) ; } elseif ( 'source' === $ installationSource ) { $ downloader = $ this -> getDownloader ( $ package -> getSourceType ( ) ) ; } else { throw new \ InvalidArgumentException ( 'Package ' . $ package . ' seems not been installed properly' ) ; } if ( $ installationSource !== $ downloader -> getInstallationSource ( ) ) { throw new \ LogicException ( sprintf ( 'Downloader "%s" is a %s type downloader and can not be used to download %s' , get_class ( $ downloader ) , $ downloader -> getInstallationSource ( ) , $ installationSource ) ) ; } return $ downloader ; }
Returns downloader for already installed package .
11,649
public function update ( PackageInterface $ initial , PackageInterface $ target , $ targetDir ) { $ downloader = $ this -> getDownloaderForInstalledPackage ( $ initial ) ; if ( ! $ downloader ) { return ; } $ installationSource = $ initial -> getInstallationSource ( ) ; if ( 'dist' === $ installationSource ) { $ initialType = $ initial -> getDistType ( ) ; $ targetType = $ target -> getDistType ( ) ; } else { $ initialType = $ initial -> getSourceType ( ) ; $ targetType = $ target -> getSourceType ( ) ; } if ( $ target -> isDev ( ) && 'dist' === $ installationSource ) { $ downloader -> remove ( $ initial , $ targetDir ) ; $ this -> download ( $ target , $ targetDir ) ; return ; } if ( $ initialType === $ targetType ) { $ target -> setInstallationSource ( $ installationSource ) ; $ downloader -> update ( $ initial , $ target , $ targetDir ) ; } else { $ downloader -> remove ( $ initial , $ targetDir ) ; $ this -> download ( $ target , $ targetDir , 'source' === $ installationSource ) ; } }
Updates package from initial to target version .
11,650
public function isQueued ( $ alias ) { $ query = $ this -> createQueryBuilder ( 'c' ) -> where ( 'c.alias = :alias' ) -> andWhere ( 'c.ended is NULL' ) -> setParameter ( 'alias' , $ alias ) -> getQuery ( ) ; $ result = $ query -> setMaxResults ( 1 ) -> getOneOrNullResult ( ) ; if ( $ result ) return true ; return false ; }
Identify of cron command is queued
11,651
public function addQueued ( $ alias ) { $ query = $ this -> createQueryBuilder ( 'c' ) -> where ( 'c.alias = :alias' ) -> setParameter ( 'alias' , $ alias ) -> getQuery ( ) ; $ smileCron = $ query -> setMaxResults ( 1 ) -> getOneOrNullResult ( ) ; if ( ! $ smileCron ) { $ smileCron = new SmileCron ( ) ; $ smileCron -> setAlias ( $ alias ) ; } $ now = new \ DateTime ( 'now' ) ; $ smileCron -> setQueued ( $ now ) ; $ smileCron -> setStarted ( null ) ; $ smileCron -> setEnded ( null ) ; $ smileCron -> setStatus ( 0 ) ; $ this -> getEntityManager ( ) -> persist ( $ smileCron ) ; $ this -> getEntityManager ( ) -> flush ( ) ; }
Add cron to queued
11,652
public function run ( SmileCron $ smileCron ) { $ now = new \ DateTime ( 'now' ) ; $ smileCron -> setStarted ( $ now ) ; $ this -> getEntityManager ( ) -> persist ( $ smileCron ) ; $ this -> getEntityManager ( ) -> flush ( ) ; }
Run cron command
11,653
public function end ( SmileCron $ smileCron , $ status = 0 ) { $ now = new \ DateTime ( 'now' ) ; $ smileCron -> setEnded ( $ now ) ; $ smileCron -> setStatus ( $ status ) ; $ this -> getEntityManager ( ) -> persist ( $ smileCron ) ; $ this -> getEntityManager ( ) -> flush ( ) ; }
End cron command
11,654
private function isSuccessful ( Response $ response ) : bool { if ( $ response -> statusCode ( ) -> value ( ) !== 200 ) { return false ; } $ json = Json :: decode ( ( string ) $ response -> body ( ) ) ; return count ( $ json [ 'errors' ] ) === 0 ; }
Check if the response is successful
11,655
public function download ( string $ projectKey , string $ localeId , string $ ext , array $ params = [ ] ) { $ params [ 'file_format' ] = $ ext ; $ response = $ this -> httpGet ( sprintf ( '/api/v2/projects/%s/locales/%s/download' , $ projectKey , $ localeId ) , $ params ) ; if ( ! $ this -> hydrator ) { return $ response ; } if ( $ response -> getStatusCode ( ) !== 200 ) { $ this -> handleErrors ( $ response ) ; } return ( string ) $ response -> getBody ( ) ; }
Download a locale .
11,656
protected function processFileSpecification ( $ artifact , $ fileSpecification ) { $ this -> files [ ] = fphp \ File \ StoredFile :: fromSpecification ( $ fileSpecification ) ; $ this -> tracingLinks [ ] = new fphp \ Artifact \ TracingLink ( "file" , $ artifact , $ fileSpecification -> getSourcePlace ( ) , $ fileSpecification -> getTargetPlace ( ) ) ; $ this -> logFile -> log ( $ artifact , "added file \"{$fileSpecification->getTarget()}\"" ) ; }
Adds a stored file from a specification . Considers globally excluded files . Only exact file names are supported .
11,657
public function addExtension ( ExtensionInterface $ extension , $ priority = 0 ) { $ this -> extensions [ $ priority ] [ ] = $ extension ; $ this -> sorted = null ; $ this -> typeExtensions = [ ] ; }
Registers an layout extension .
11,658
protected function getExtensions ( ) { if ( null === $ this -> sorted ) { ksort ( $ this -> extensions ) ; $ this -> sorted = ! empty ( $ this -> extensions ) ? call_user_func_array ( 'array_merge' , $ this -> extensions ) : [ ] ; } return $ this -> sorted ; }
Returns all registered extensions sorted by priority .
11,659
public static function getMaxLength ( $ array , $ key ) { $ maxLen = 0 ; foreach ( $ array as $ element ) { $ str = call_user_func ( array ( $ element , $ key ) ) ; $ maxLen = strlen ( $ str ) > $ maxLen ? strlen ( $ str ) : $ maxLen ; } return $ maxLen ; }
Returns the maximum member length of an array of objects .
11,660
public function aliases ( array $ aliases = null ) { if ( is_null ( $ aliases ) ) { return $ this -> aliases ; } else { $ this -> aliases = array_merge ( $ this -> aliases , $ aliases ) ; } }
Set or get config aliases
11,661
public function alias ( $ alias , $ path = null ) { if ( is_null ( $ path ) ) { return $ this -> aliases [ $ alias ] ? : null ; } else { $ this -> aliases [ $ alias ] = $ path ; } }
Set or get a config alias
11,662
protected function loadConfig ( $ alias , $ configName ) { if ( isset ( $ this -> aliases [ $ alias ] ) ) { $ aliasPath = $ this -> aliases [ $ alias ] ; } else { throw new ClearException ( "Config Alias [$alias] Not Found." , 4 ) ; } $ file = $ aliasPath . $ configName . '.php' ; if ( is_file ( $ file ) ) { return $ this -> configs [ $ alias ] [ $ configName ] = require $ file ; } throw new ClearException ( "The Config File [$file] Not Found." , 4 ) ; }
Open and load configs from a file
11,663
public function set ( $ mixedKey , $ value ) { list ( $ alias , $ configName , $ key ) = $ this -> parseKey ( $ mixedKey ) ; if ( is_null ( $ key ) ) { $ this -> configs [ $ alias ] [ $ configName ] = $ value ; } $ this -> configs [ $ alias ] [ $ configName ] [ $ key ] = $ value ; }
Set a config
11,664
protected function parseKey ( $ mixedKey ) { if ( preg_match ( '/^((?P<alias>[\w]+)::)?(?P<name>\w+)(\.(?P<key>\w+))?$/' , $ mixedKey , $ matches ) !== 1 ) { throw new ClearException ( "Invalid Config Variable Name. Name Must Be Like [alias::name.key] Or [name.key]." , 4 ) ; } $ alias = $ matches [ 'alias' ] ; $ name = $ matches [ 'name' ] ; $ key = $ matches [ 'key' ] ? : null ; return [ $ alias ? : 'default' , $ name , $ key ] ; }
Parse requested mixed - key and split alias name and key
11,665
public function db ( $ database = null ) { if ( empty ( $ database ) ) { $ database = $ this -> database ; } return $ this -> silex [ 'dbs' ] [ $ database ] ; }
Gets dbal engine .
11,666
public function getCurrentUser ( ) { if ( Towel :: isCli ( ) ) { return false ; } $ userRecord = $ this -> session ( ) -> get ( 'user' , false ) ; if ( ! $ userRecord ) { return false ; } $ userModel = $ this -> getInstance ( 'user_model' ) ; $ userModel -> setRecord ( $ userRecord ) ; return $ userModel ; }
Gets the current user or false if is not authenticated .
11,667
public function sendMail ( $ to , $ subject = '' , $ message = '' , $ headers = '' ) { if ( empty ( $ headers ) ) { $ headers = 'From: ' . APP_SYS_EMAIL ; } mail ( $ to , $ subject , $ message , $ headers ) ; }
Sends an Email .
11,668
public function url ( $ route , $ parameters = array ( ) ) { return $ this -> silex [ 'url_generator' ] -> generate ( $ route , $ parameters , \ Symfony \ Component \ Routing \ Generator \ UrlGeneratorInterface :: ABSOLUTE_URL ) ; }
Generates an absolute URL from the given parameters .
11,669
public function getCache ( ) { if ( null === self :: $ cache ) { if ( ! empty ( $ this -> appConfig [ 'cache' ] [ 'driver' ] ) ) { if ( empty ( $ this -> appConfig [ 'cache' ] [ 'options' ] ) ) { $ options = array ( ) ; } else { $ options = $ this -> appConfig [ 'cache' ] [ 'options' ] ; } if ( 'memcached' !== $ this -> appConfig [ 'cache' ] [ 'driver' ] ) { $ className = $ this -> appConfig [ 'cache' ] [ 'driver' ] ; } else { $ className = '\Towel\Cache\TowelMemcached' ; } $ cacheDriver = new $ className ( ) ; $ cacheDriver -> setOptions ( $ options ) ; } self :: $ cache = new TowelCache ( $ cacheDriver ) ; } return self :: $ cache ; }
Instantiate Cache driver
11,670
protected function createErrorEntry ( $ error , $ parse_errors ) { $ marker_obj = new \ DOMElement ( strtolower ( $ error -> getSeverity ( ) ) ) ; $ parse_errors -> appendChild ( $ marker_obj ) ; $ message = ( $ this -> getTranslator ( ) ) ? vsprintf ( $ this -> getTranslator ( ) -> translate ( $ error -> getCode ( ) ) , $ error -> getContext ( ) ) : $ error -> getCode ( ) ; $ marker_obj -> appendChild ( new \ DOMText ( $ message ) ) ; $ marker_obj -> setAttribute ( 'line' , $ error -> getLine ( ) ) ; $ marker_obj -> setAttribute ( 'code' , $ error -> getCode ( ) ) ; }
Creates an entry in the ParseErrors collection of a file for a given error .
11,671
public function buildFunction ( \ DOMElement $ parent , FunctionDescriptor $ function , \ DOMElement $ child = null ) { if ( ! $ child ) { $ child = new \ DOMElement ( 'function' ) ; $ parent -> appendChild ( $ child ) ; } $ namespace = $ function -> getNamespace ( ) ? $ function -> getNamespace ( ) : $ parent -> getAttribute ( 'namespace' ) ; $ child -> setAttribute ( 'namespace' , ltrim ( $ namespace , '\\' ) ) ; $ child -> setAttribute ( 'line' , $ function -> getLine ( ) ) ; $ child -> appendChild ( new \ DOMElement ( 'name' , $ function -> getName ( ) ) ) ; $ child -> appendChild ( new \ DOMElement ( 'full_name' , $ function -> getFullyQualifiedStructuralElementName ( ) ) ) ; $ this -> docBlockConverter -> convert ( $ child , $ function ) ; foreach ( $ function -> getArguments ( ) as $ argument ) { $ this -> argumentConverter -> convert ( $ child , $ argument ) ; } }
Export this function definition to the given parent DOMElement .
11,672
protected function buildPackageTree ( \ DOMDocument $ dom ) { $ xpath = new \ DOMXPath ( $ dom ) ; $ packages = array ( 'global' => true ) ; $ qry = $ xpath -> query ( '//@package' ) ; for ( $ i = 0 ; $ i < $ qry -> length ; $ i ++ ) { if ( isset ( $ packages [ $ qry -> item ( $ i ) -> nodeValue ] ) ) { continue ; } $ packages [ $ qry -> item ( $ i ) -> nodeValue ] = true ; } $ packages = $ this -> generateNamespaceTree ( array_keys ( $ packages ) ) ; $ this -> generateNamespaceElements ( $ packages , $ dom -> documentElement , 'package' ) ; }
Collects all packages and subpackages and adds a new section in the DOM to provide an overview .
11,673
protected function buildNamespaceTree ( \ DOMDocument $ dom ) { $ xpath = new \ DOMXPath ( $ dom ) ; $ namespaces = array ( ) ; $ qry = $ xpath -> query ( '//@namespace' ) ; for ( $ i = 0 ; $ i < $ qry -> length ; $ i ++ ) { if ( isset ( $ namespaces [ $ qry -> item ( $ i ) -> nodeValue ] ) ) { continue ; } $ namespaces [ $ qry -> item ( $ i ) -> nodeValue ] = true ; } $ namespaces = $ this -> generateNamespaceTree ( array_keys ( $ namespaces ) ) ; $ this -> generateNamespaceElements ( $ namespaces , $ dom -> documentElement ) ; }
Collects all namespaces and sub - namespaces and adds a new section in the DOM to provide an overview .
11,674
protected function generateNamespaceTree ( $ namespaces ) { sort ( $ namespaces ) ; $ result = array ( ) ; foreach ( $ namespaces as $ namespace ) { if ( ! $ namespace ) { $ namespace = 'global' ; } $ namespace_list = explode ( '\\' , $ namespace ) ; $ node = & $ result ; foreach ( $ namespace_list as $ singular ) { if ( ! isset ( $ node [ $ singular ] ) ) { $ node [ $ singular ] = array ( ) ; } $ node = & $ node [ $ singular ] ; } } return $ result ; }
Generates a hierarchical array of namespaces with their singular name from a single level list of namespaces with their full name .
11,675
protected function generateNamespaceElements ( $ namespaces , $ parent_element , $ node_name = 'namespace' ) { foreach ( $ namespaces as $ name => $ sub_namespaces ) { $ node = new \ DOMElement ( $ node_name ) ; $ parent_element -> appendChild ( $ node ) ; $ node -> setAttribute ( 'name' , $ name ) ; $ fullName = $ parent_element -> nodeName == $ node_name ? $ parent_element -> getAttribute ( 'full_name' ) . '\\' . $ name : $ name ; $ node -> setAttribute ( 'full_name' , $ fullName ) ; $ this -> generateNamespaceElements ( $ sub_namespaces , $ node , $ node_name ) ; } }
Recursive method to create a hierarchical set of nodes in the dom .
11,676
public function get_html ( $ theme = 'light' , $ lang = 'en' , $ type = 'image' ) { if ( $ this -> enabled ) { $ option = [ ] ; switch ( $ theme ) { case 'dark' : $ option [ 'theme' ] = $ theme ; break ; case 'red' : default : $ option [ 'theme' ] = 'light' ; break ; } switch ( $ type ) { case 'audio' : $ option [ 'type' ] = $ type ; break ; default : $ option [ 'type' ] = 'image' ; break ; } switch ( $ lang ) { case 'ar' : case 'bg' : case 'ca' : case 'zh-CN' : case 'zh-TW' : case 'hr' : case 'cs' : case 'da' : case 'nl' : case 'en-GB' : case 'en' : case 'fil' : case 'fi' : case 'fr' : case 'fr-CA' : case 'de' : case 'de-AT' : case 'de-CH' : case 'el' : case 'iw' : case 'hi' : case 'hu' : case 'id' : case 'it' : case 'ja' : case 'ko' : case 'lv' : case 'lt' : case 'no' : case 'fa' : case 'pl' : case 'pt' : case 'pt-BR' : case 'pt-PT' : case 'ro' : case 'ru' : case 'sr' : case 'sk' : case 'sl' : case 'es' : case 'es-419' : case 'sv' : case 'th' : case 'tr' : case 'uk' : case 'vi' : $ option [ 'lang' ] = $ lang ; break ; default : $ option [ 'lang' ] = 'en' ; break ; } $ option = apply_filters ( 'wpametu_recaptcha_setting' , $ option ) ; $ script = '<script src="https://www.google.com/recaptcha/api.js?hl=' . $ option [ 'lang' ] . '" async defer></script>' ; $ html = <<<HTML<div class="g-recaptcha" data-sitekey="%s" data-theme="%s" data-type="%s"></div>HTML ; return $ script . sprintf ( $ html , constant ( self :: PUBLIC_KEY ) , $ option [ 'theme' ] , $ option [ 'type' ] ) ; } else { return false ; } }
Return reCaptcha s HTML
11,677
public function isRunning ( ) { $ runningStatuses = [ self :: SUBSCRIPTION_STATUS_ACTIVE , self :: SUBSCRIPTION_STATUS_TRIAL , ] ; return in_array ( $ this -> getStatus ( ) , $ runningStatuses , true ) ; }
Check if the current subscription is running .
11,678
private function add_helpers ( $ helpers ) { foreach ( $ helpers as $ helper ) { $ helper = $ this -> validate_helper_input ( $ helper ) ; if ( is_array ( $ helper ) ) { $ this -> add_helper ( $ helper ) ; } } }
Add the helpers to the Handlebars instance if validation passes .
11,679
private function validate_helper_input ( $ helper ) { if ( ! is_array ( $ helper ) || empty ( $ helper ) ) { return false ; } if ( ! isset ( $ helper [ 'name' ] ) || ! isset ( $ helper [ 'class' ] ) ) { return false ; } if ( ! isset ( $ helper [ 'callback' ] ) ) { $ helper [ 'callback' ] = 'helper' ; } return $ helper ; }
Make sure each helper passed in is valid .
11,680
public function offsetGet ( $ offset ) { if ( $ this -> offsetExists ( $ offset ) ) { return parent :: offsetGet ( $ offset ) ; } else { if ( 'id' == $ offset || 'ID' == $ offset ) { $ _value = $ this -> pod -> id ( ) ; } else { $ _value = $ this -> pod -> field ( $ offset ) ; } if ( $ _value ) { parent :: offsetSet ( $ offset , $ _value ) ; return $ _value ; } } }
Get an offset if already set or traverse Pod and then set plus reutrn .
11,681
protected function processFileSpecification ( $ artifact , $ fileSpecification ) { $ collaboration = fphp \ Collaboration \ Collaboration :: findByArtifact ( $ this -> collaborations , $ artifact ) ; if ( ! $ collaboration ) $ this -> collaborations [ ] = $ collaboration = new fphp \ Collaboration \ Collaboration ( $ artifact ) ; $ collaboration -> addRoleFromFileSpecification ( $ fileSpecification ) ; $ this -> tracingLinks [ ] = new fphp \ Artifact \ TracingLink ( "role" , $ artifact , $ fileSpecification -> getSourcePlace ( ) , $ fileSpecification -> getTargetPlace ( ) ) ; $ this -> logFile -> log ( $ artifact , "using role at \"{$fileSpecification->getTarget()}\"" ) ; }
Adds a role from a file to a collaboration .
11,682
protected function _generateFiles ( ) { foreach ( $ this -> getRegisteredArtifacts ( ) as $ artifact ) { $ featureName = $ artifact -> getFeature ( ) -> getName ( ) ; if ( array_search ( $ featureName , $ this -> featureOrder ) === false ) throw new CollaborationGeneratorException ( "no feature order supplied for \"$featureName\"" ) ; } parent :: _generateFiles ( ) ; $ rolePartition = fphp \ Helper \ Partition :: fromObjects ( $ this -> collaborations , "getRoles" ) -> partitionBy ( "correspondsTo" ) ; foreach ( $ rolePartition as $ roleEquivalenceClass ) { $ roleEquivalenceClass = fphp \ Helper \ _Array :: schwartzianTransform ( $ roleEquivalenceClass , function ( $ role ) { return array_search ( $ role -> getCollaboration ( ) -> getArtifact ( ) -> getFeature ( ) -> getName ( ) , $ this -> featureOrder ) ; } ) ; $ fileTarget = $ roleEquivalenceClass [ 0 ] -> getFileSpecification ( ) -> getTarget ( ) ; $ this -> files [ ] = new fphp \ File \ RefinedFile ( $ fileTarget , $ roleEquivalenceClass ) ; $ this -> logFile -> log ( null , "added file \"$fileTarget\"" ) ; } }
Generates the refined files .
11,683
public function append ( $ string , $ length = null ) { $ this -> end ( ) ; return $ this -> write ( $ string , $ length ) ; }
Append data to the stream .
11,684
public function get ( $ index ) { if ( ! isset ( $ this -> _streams [ $ index ] ) ) { throw new InvalidArgumentException ( "Unexisting stream index `{$index}`." ) ; } return $ this -> _streams [ $ index ] ; }
Return a contained stream .
11,685
public function remove ( $ index ) { if ( ! isset ( $ this -> _streams [ $ index ] ) ) { throw new InvalidArgumentException ( "Unexisting stream index `{$index}`." ) ; } $ stream = $ this -> _streams [ $ index ] ; unset ( $ this -> _streams [ $ index ] ) ; $ this -> _streams = array_values ( $ this -> _streams ) ; return $ stream ; }
Remove a stream .
11,686
public function detach ( ) { $ this -> _offset = $ this -> _current = 0 ; $ this -> _seekable = true ; foreach ( $ this -> _streams as $ stream ) { $ stream -> detach ( ) ; } $ this -> _streams = [ ] ; }
Detaches each attached stream .
11,687
private function computeEndpoint ( ) : UrlInterface { if ( ! $ this -> transactions -> isOpened ( ) ) { return Url :: fromString ( '/db/data/transaction/commit' ) ; } return $ this -> transactions -> current ( ) -> endpoint ( ) ; }
Determine the appropriate endpoint based on the transactions
11,688
private function computeBody ( Query $ query ) : StringStream { $ statement = [ 'statement' => $ query -> cypher ( ) , 'resultDataContents' => [ 'graph' , 'row' ] , ] ; if ( $ query -> hasParameters ( ) ) { $ parameters = [ ] ; foreach ( $ query -> parameters ( ) as $ parameter ) { $ parameters [ $ parameter -> key ( ) ] = $ parameter -> value ( ) ; } $ statement [ 'parameters' ] = $ parameters ; } return new StringStream ( Json :: encode ( [ 'statements' => [ $ statement ] , ] ) ) ; }
Build the json payload to be sent to the server
11,689
public function isExpressionPath ( $ path , $ node ) { if ( is_scalar ( $ node ) ) { foreach ( $ this -> expressionPaths as $ callable ) { if ( call_user_func ( $ callable , $ path ) ) { return true ; } } } return false ; }
Decides if a node should be an expression .
11,690
public function build ( ) { Debug :: enterScope ( 'build' ) ; $ traverser = $ this -> createNodeCreatorTraverser ( $ this -> config ) ; $ result = $ traverser -> traverse ( ) ; $ node = new ContainerNode ( ) ; $ gatherer = $ this -> createNodeGathererTraverser ( $ result , $ node ) ; $ gatherer -> traverse ( ) ; Debug :: exitScope ( 'build' ) ; return $ node ; }
Build the container node
11,691
public function createArgNode ( $ path , $ node ) { $ v = trim ( $ node ) ; if ( substr ( $ v , 0 , 1 ) == '?' ) { $ conditional = true ; $ v = ltrim ( substr ( $ v , 1 ) ) ; } else { $ conditional = false ; } return new ArgNode ( end ( $ path ) , $ this -> exprcompiler -> parse ( $ v ) , $ conditional ) ; }
Creates a node for the args definition of the task .
11,692
public function createOptNode ( $ path , $ node ) { return new OptNode ( end ( $ path ) , $ this -> exprcompiler -> parse ( $ node ) ) ; }
Creates a node for the opts definition of the task .
11,693
public function createSetNode ( $ path , $ node ) { return new SetNode ( end ( $ path ) , $ this -> exprcompiler -> parse ( $ node ) ) ; }
Creates a node for the set definition of the task .
11,694
public function createNodeCreatorTraverser ( $ config ) { $ traverser = new Traverser ( $ config ) ; $ traverser -> addVisitor ( array ( $ this , 'createArgNode' ) , function ( $ path ) { return ( count ( $ path ) == 4 && $ path [ 0 ] == 'tasks' && $ path [ 2 ] == 'args' ) ; } , Traverser :: BEFORE ) ; $ traverser -> addVisitor ( array ( $ this , 'createOptNode' ) , function ( $ path ) { return ( count ( $ path ) == 4 && $ path [ 0 ] == 'tasks' && $ path [ 2 ] == 'opts' ) ; } , Traverser :: BEFORE ) ; $ traverser -> addVisitor ( array ( $ this , 'createSetNode' ) , function ( $ path ) { return ( count ( $ path ) == 4 && $ path [ 0 ] == 'tasks' && $ path [ 2 ] == 'set' ) ; } , Traverser :: BEFORE ) ; $ traverser -> addVisitor ( array ( $ this , 'createExpressionNode' ) , function ( $ path ) { return count ( $ path ) === 3 && $ path [ 0 ] == 'tasks' && in_array ( $ path [ 2 ] , array ( 'unless' , 'assert' , 'yield' , 'if' ) ) ; } , Traverser :: BEFORE ) ; $ traverser -> addVisitor ( array ( $ this , 'createScriptNode' ) , function ( $ path ) { return count ( $ path ) == 4 && $ path [ 0 ] == 'tasks' && in_array ( $ path [ 2 ] , array ( 'do' , 'pre' , 'post' ) ) ; } , Traverser :: BEFORE ) ; $ traverser -> addVisitor ( array ( $ this , 'createTaskNode' ) , function ( $ path ) { return count ( $ path ) == 2 && $ path [ 0 ] == 'tasks' ; } , Traverser :: AFTER ) ; $ traverser -> addVisitor ( array ( $ this , 'createDeclarationNode' ) , array ( $ this , 'isExpressionPath' ) , Traverser :: AFTER ) ; $ traverser -> addVisitor ( array ( $ this , 'createDefinitionNode' ) , function ( $ path , $ node ) { return $ path [ 0 ] !== 'tasks' && ( is_scalar ( $ node ) || ( is_array ( $ node ) && count ( $ node ) === 0 ) ) ; } , Traverser :: AFTER ) ; return $ traverser ; }
Creates the traverser that creates relevant nodes at all known paths .
11,695
public function hasParam ( $ param ) { $ param = ( string ) $ this -> params [ $ param ] ; return strlen ( $ param ) > 0 ? true : false ; }
Determine that route param exists .
11,696
public function isMatch ( $ pathInfo ) { $ this -> compile ( ) ; $ pathInfo = trim ( $ pathInfo , '/' ) ; if ( ! preg_match ( $ this -> pattern , $ pathInfo , $ paramValues ) ) { return false ; } foreach ( $ this -> paramNames as $ name ) { $ this -> params [ $ name ] = isset ( $ paramValues [ $ name ] ) ? urldecode ( $ paramValues [ $ name ] ) : null ; } return true ; }
Determine matching route by given uri .
11,697
public function compile ( ) { $ this -> params = [ ] ; $ this -> paramNames = [ ] ; $ this -> conditions = [ ] ; $ this -> compiled = true ; $ uri = $ this -> normalizeUri ( $ this -> getUri ( ) ) ; $ regex = preg_replace_callback ( '#(?:(\\/)?\\{(\\w+)(\\?)?(?::((?:\\\\\\{|\\\\\\}|[^{}]|\\{\\d(?:\\,(?:\\d)?)?\\})+))?\\})#' , [ $ this , 'createRegex' ] , $ uri ) ; $ regex .= "/?" ; $ regex = '#^' . $ regex . '$#' ; if ( $ this -> caseSensitive === false ) { $ regex .= 'i' ; } $ this -> pattern = $ regex ; return $ this ; }
Compile route uri pattern regex
11,698
protected function createRegex ( $ matched ) { $ startSlash = $ matched [ 1 ] ? true : false ; $ param = $ matched [ 2 ] ; $ optional = $ matched [ 3 ] ? true : false ; $ pattern = $ matched [ 4 ] ? : null ; $ pattern = $ this -> conditions [ $ param ] ? : $ pattern ? : '[^/]+' ; $ this -> paramNames [ ] = $ param ; if ( $ startSlash ) { $ regex = ( $ optional ? "(/" : '/' ) . '(?P<' . $ param . '>' . $ pattern . ')' . ( $ optional ? ')?' : '' ) ; } else { $ regex = '(?P<' . $ param . '>' . $ pattern . ')' . ( $ optional ? '?' : '' ) ; } return $ regex ; }
Callback for creating route param names regex
11,699
private function generateHtmlPart ( ) { $ result = false ; if ( $ this -> htmlText != '' ) { $ matches = array ( ) ; if ( $ this -> options -> automaticImageInclude === true ) { preg_match_all ( '( <img \\s+[^>]* src\\s*=\\s* (?: (?# Match quoted attribute) ([\'"])file://(?P<quoted>[^>]+)\\1 (?# Match unquoted attribute, which may not contain spaces) | file://(?P<unquoted>[^>\\s]+) ) [^>]* >)ix' , $ this -> htmlText , $ matches ) ; $ matches = array_filter ( array_unique ( array_merge ( $ matches [ 'quoted' ] , $ matches [ 'unquoted' ] ) ) ) ; } $ result = new ezcMailText ( $ this -> htmlText , $ this -> charset , $ this -> encoding ) ; $ result -> subType = "html" ; if ( count ( $ matches ) > 0 ) { $ htmlPart = $ result ; $ result = new ezcMailMultipartRelated ( $ result ) ; foreach ( $ matches as $ fileName ) { if ( is_readable ( $ fileName ) ) { $ mimeType = null ; $ contentType = null ; if ( ezcBaseFeatures :: hasExtensionSupport ( 'fileinfo' ) ) { $ filePart = new ezcMailFile ( $ fileName ) ; } elseif ( ezcMailTools :: guessContentType ( $ fileName , $ contentType , $ mimeType ) ) { $ filePart = new ezcMailFile ( $ fileName , $ contentType , $ mimeType ) ; } else { $ filePart = new ezcMailFile ( $ fileName , "application" , "octet-stream" ) ; } $ cid = $ result -> addRelatedPart ( $ filePart ) ; $ this -> htmlText = str_replace ( 'file://' . $ fileName , 'cid:' . $ cid , $ this -> htmlText ) ; } else { if ( file_exists ( $ fileName ) ) { throw new ezcBaseFilePermissionException ( $ fileName , ezcBaseFileException :: READ ) ; } else { throw new ezcBaseFileNotFoundException ( $ fileName ) ; } } } $ htmlPart -> text = $ this -> htmlText ; } } return $ result ; }
Returns an ezcMailPart based on the HTML provided .