idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
12,300
public function transform ( $ dateTime ) { if ( $ dateTime === null || trim ( $ dateTime ) == '' ) { return '' ; } if ( ! $ dateTime instanceof \ DateTime ) { throw new TransformationFailedException ( 'Expected a \DateTime.' ) ; } $ dateTime = clone $ dateTime ; if ( $ this -> inputTimezone !== $ this -> outputTimezone ) { try { $ dateTime -> setTimezone ( new \ DateTimeZone ( $ this -> outputTimezone ) ) ; } catch ( \ Exception $ e ) { throw new TransformationFailedException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } } return $ dateTime -> format ( 'Y-m-d H:i:s' ) ; }
Transforms a normalized date into a the concrete5 datetime widget format .
12,301
public function setPreMessageTemplate ( $ template = null ) { if ( null !== $ template ) { $ template = ( string ) $ template ; } $ this -> abstractOptions [ 'messageTemplates' ] [ self :: PRE_MESSAGE_TEMPLATE_KEY ] = $ template ; return $ this ; }
Sets template of validation failure message to be inserted at beginning of validation failure message map .
12,302
public function setPostMessageTemplate ( $ postMessage = null ) { if ( null !== $ postMessage ) { $ postMessage = ( string ) $ postMessage ; } $ this -> abstractOptions [ 'messageTemplates' ] [ self :: POST_MESSAGE_TEMPLATE_KEY ] = $ postMessage ; return $ this ; }
Sets template of validation failure message to be inserted at end of validation failure message map .
12,303
public function attach ( ValidatorInterface $ validator , $ showMessages = true , $ leadingTemplate = null , $ trailingTemplate = null , $ priority = self :: DEFAULT_PRIORITY ) { $ this -> validators -> insert ( array ( 'instance' => $ validator , 'show_messages' => ( bool ) $ showMessages , 'leading_message_template' => $ leadingTemplate , 'trailing_message_template' => $ trailingTemplate , ) , $ priority ) ; return $ this ; }
Attaches validator to end of chain .
12,304
public function prependValidator ( ValidatorInterface $ validator , $ showMessages = true , $ leadingTemplate = null , $ trailingTemplate = null ) { $ priority = self :: DEFAULT_PRIORITY ; if ( ! $ this -> validators -> isEmpty ( ) ) { $ queue = $ this -> validators -> getIterator ( ) ; $ queue -> setExtractFlags ( PriorityQueue :: EXTR_PRIORITY ) ; $ extractedNode = $ queue -> extract ( ) ; $ priority = $ extractedNode [ 0 ] + 1 ; } $ this -> validators -> insert ( array ( 'instance' => $ validator , 'show_messages' => ( bool ) $ showMessages , 'leading_message_template' => $ leadingTemplate , 'trailing_message_template' => $ trailingTemplate , ) , $ priority ) ; return $ this ; }
Adds validator to beginning of chain .
12,305
protected function createMessageFromTemplate ( $ messageTemplate , $ value ) { $ message = $ this -> translateMessage ( 'dummyValue' , ( string ) $ messageTemplate ) ; if ( is_object ( $ value ) && ! in_array ( '__toString' , get_class_methods ( $ value ) ) ) { $ value = get_class ( $ value ) . ' object' ; } elseif ( is_array ( $ value ) ) { $ value = var_export ( $ value , 1 ) ; } else { $ value = ( string ) $ value ; } if ( $ this -> isValueObscured ( ) ) { $ value = str_repeat ( '*' , strlen ( $ value ) ) ; } $ message = str_replace ( '%value%' , ( string ) $ value , $ message ) ; $ message = str_replace ( '%count%' , ( string ) $ this -> count ( ) , $ message ) ; $ length = self :: getMessageLength ( ) ; if ( ( $ length > - 1 ) && ( strlen ( $ message ) > $ length ) ) { $ message = substr ( $ message , 0 , ( $ length - 3 ) ) . '...' ; } return $ message ; }
Constructs and returns validation failure message for specified message template and value .
12,306
public function merge ( VerboseOrChain $ validatorChain ) { foreach ( $ validatorChain -> validators -> toArray ( PriorityQueue :: EXTR_BOTH ) as $ item ) { $ this -> attach ( $ item [ 'data' ] [ 'instance' ] , $ item [ 'data' ] [ 'show_messages' ] , $ item [ 'data' ] [ 'leading_message_template' ] , $ item [ 'data' ] [ 'trailing_message_template' ] , $ item [ 'priority' ] ) ; } return $ this ; }
Merges in logical or validator chain provided as argument .
12,307
private function getRawType ( \ ReflectionProperty $ property ) { $ matches = [ ] ; if ( preg_match ( '/@var\s+([^\s]+)/' , $ property -> getDocComment ( ) , $ matches ) ) { list ( , $ rawType ) = $ matches ; } else { $ rawType = 'mixed' ; } return $ rawType ; }
Returns raw string type format from the var annotation
12,308
public static function random ( $ length = 6 , $ pool = self :: RANDOM_POOL ) { return substr ( str_shuffle ( str_repeat ( $ pool , 5 ) ) , 0 , $ length ) ; }
Make a random string .
12,309
protected function locateTemplate ( FileLocatorInterface $ locator , TemplateReference $ template , array & $ templates ) { $ templates [ $ template -> getLogicalName ( ) ] = $ locator -> locate ( $ template -> getPath ( ) ) ; }
Locates and appends template to an array
12,310
public function validate ( $ element ) { $ docBlock = $ element -> getDocBlock ( ) ; if ( null === $ docBlock ) { throw new \ UnexpectedValueException ( 'A DocBlock should be present (and validated) before this validator can be applied' ) ; } if ( $ docBlock -> hasTag ( 'return' ) ) { $ returnTag = current ( $ docBlock -> getTagsByName ( 'return' ) ) ; if ( $ returnTag -> getType ( ) == 'type' ) { return new Error ( LogLevel :: WARNING , 'PPC:ERR-50017' , $ element -> getLinenumber ( ) ) ; } } return null ; }
Validates whether the given Reflector s arguments match the business rules of phpDocumentor .
12,311
protected function validateArguments ( $ element ) { $ params = $ element -> getDocBlock ( ) -> getTagsByName ( 'param' ) ; $ arguments = $ element -> getArguments ( ) ; foreach ( array_values ( $ arguments ) as $ key => $ argument ) { if ( ! $ this -> isArgumentInDocBlock ( $ key , $ argument , $ element , $ params ) ) { continue ; } $ result = $ this -> doesArgumentNameMatchParam ( $ params [ $ key ] , $ argument , $ element ) ; if ( $ result ) { return $ result ; } $ result = $ this -> doesArgumentTypehintMatchParam ( $ params [ $ key ] , $ argument , $ element ) ; if ( $ result ) { return $ result ; } } foreach ( $ params as $ param ) { $ param_name = $ param -> getVariableName ( ) ; if ( isset ( $ arguments [ $ param_name ] ) ) { continue ; } return new Error ( LogLevel :: NOTICE , 'PPC:ERR-50013' , $ element -> getLinenumber ( ) , array ( $ param_name , $ element -> getName ( ) ) ) ; } return null ; }
Returns an error if the given Reflector s arguments do not match expectations .
12,312
protected function isArgumentInDocBlock ( $ index , ArgumentReflector $ argument , BaseReflector $ element , array $ params ) { if ( isset ( $ params [ $ index ] ) ) { return null ; } return new Error ( LogLevel :: ERROR , 'PPC:ERR-50015' , $ argument -> getLinenumber ( ) , array ( $ argument -> getName ( ) , $ element -> getName ( ) ) ) ; }
Validates whether an argument is mentioned in the docblock .
12,313
protected function doesArgumentNameMatchParam ( ParamTag $ param , ArgumentReflector $ argument , BaseReflector $ element ) { $ param_name = $ param -> getVariableName ( ) ; if ( $ param_name == $ argument -> getName ( ) ) { return null ; } if ( $ param_name == '' ) { $ param -> setVariableName ( $ argument -> getName ( ) ) ; return null ; } return new Error ( LogLevel :: ERROR , 'PPC:ERR-50014' , $ argument -> getLinenumber ( ) , array ( $ argument -> getName ( ) , $ param_name , $ element -> getName ( ) ) ) ; }
Validates whether the name of the argument is the same as that of the param tag .
12,314
private function check_path ( ) { $ ar = \ func_get_args ( ) ; foreach ( $ ar as $ a ) { $ b = bbn \ str :: parse_path ( $ a , true ) ; if ( empty ( $ b ) && ! empty ( $ a ) ) { $ this -> error ( "The path $a is not an acceptable value" ) ; return false ; } } return 1 ; }
This checks whether an argument used for getting controller view or model - which are files - doesn t contain malicious content .
12,315
static function fetchByEmail ( $ email ) { $ cond = array ( 'email' => $ email ) ; $ return = eZPersistentObject :: fetchObject ( self :: definition ( ) , null , $ cond ) ; return $ return ; }
Fetch ezcomSubscriber by given email
12,316
public function getWsdl ( $ urlservice ) { $ aURL = explode ( '?' , $ urlservice ) ; if ( count ( $ aURL ) == 1 ) { $ urlservice .= '?wsdl' ; } $ resposta = $ this -> zCommCurl ( $ urlservice ) ; $ nPos = strpos ( $ resposta , '<wsdl:def' ) ; if ( $ nPos === false ) { $ nPos = strpos ( $ resposta , '<definit' ) ; } if ( $ nPos === false ) { return false ; } $ wsdl = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" . trim ( substr ( $ resposta , $ nPos ) ) ; return $ wsdl ; }
getWsdl Baixa o arquivo wsdl do webservice .
12,317
public function post ( $ url , $ body , array $ headers = array ( ) ) { if ( is_array ( $ body ) ) { $ body = http_build_query ( $ body ) ; } $ response = $ this -> getClient ( ) -> post ( $ url , $ body , $ headers ) ; if ( ! $ response instanceof Response ) { throw new InvalidType ( 'HttpInterface post method must return an instance of \Borla\Chikka\Support\Http\Response' ) ; } return $ response ; }
Create post request
12,318
public function findByUsername ( $ username ) { $ qb = $ this -> createQueryBuilder ( "u" ) ; $ qb -> where ( "(u.username = :username OR u.email = :email)" ) -> setParameter ( "username" , $ username ) -> setParameter ( "email" , $ username ) ; $ qb -> andWhere ( "u.status = :status" ) -> setParameter ( "status" , 1 ) ; $ qb -> setMaxResults ( 1 ) ; return $ qb -> getQuery ( ) -> getOneOrNullResult ( ) ; }
Find by username .
12,319
public function getPrefixString ( $ array , $ prefix ) { $ items = array ( ) ; if ( ! empty ( $ array ) ) { foreach ( $ array as $ item ) { preg_match ( '/' . $ prefix . '(.*)/' , $ item , $ results ) ; if ( isset ( $ results [ 1 ] ) ) { $ items [ ] = $ results [ 1 ] ; } } } return $ items ; }
Get array of string using prefix
12,320
public function read ( $ file ) { $ this -> file = $ file ; if ( $ this -> fs -> exists ( $ this -> file ) ) { $ this -> data = file_get_contents ( $ this -> file ) ; return $ this ; } throw new Exceptions \ FileNotExists ( $ this -> file ) ; }
Read from the file
12,321
public static function fromString ( $ json , $ directory = "." ) { $ json = json_decode ( $ json , true ) ; if ( is_null ( $ json ) ) throw new SettingsException ( "invalid json" ) ; return new static ( $ json , $ directory ) ; }
Creates settings from a JSON - encoded string .
12,322
public static function fromFile ( $ fileName ) { if ( ! file_exists ( $ fileName ) ) throw new SettingsException ( "file $fileName does not exist" ) ; return static :: fromString ( file_get_contents ( $ fileName ) , dirname ( $ fileName ) ) ; }
Creates settings from a JSON - encoded file .
12,323
protected function has ( $ key , $ cfg = null ) { if ( ! $ cfg ) $ cfg = $ this -> cfg ; return array_key_exists ( $ key , $ cfg ) ; }
Returns whether a plain settings array has a key . If no settings array is given the internal settings array is assumed .
12,324
private function _get ( $ cfg ) { $ args = array_slice ( func_get_args ( ) , 1 ) ; if ( count ( $ args ) === 0 ) return $ cfg ; else { if ( ! is_array ( $ cfg ) || ! $ this -> has ( $ args [ 0 ] , $ cfg ) ) throw new NotFoundSettingsException ( $ args [ 0 ] ) ; $ args [ 0 ] = $ cfg [ $ args [ 0 ] ] ; return call_user_func_array ( array ( $ this , "_get" ) , $ args ) ; } }
Returns a setting in a plain settings array . A setting path can be supplied variadically .
12,325
public function get ( ) { $ args = func_get_args ( ) ; array_unshift ( $ args , $ this -> cfg ) ; return call_user_func_array ( array ( $ this , "_get" ) , $ args ) ; }
Returns a setting . A setting path can be supplied variadically .
12,326
public function getOptional ( $ defaultValue ) { $ args = func_get_args ( ) ; try { return call_user_func_array ( array ( $ this , "get" ) , array_slice ( $ args , 0 , - 1 ) ) ; } catch ( fphp \ NotFoundSettingsException $ e ) { return $ args [ count ( $ args ) - 1 ] ; } }
Returns an optional setting defaulting to a value . A setting path can be supplied variadically .
12,327
private function _set ( & $ cfg , $ args ) { if ( count ( $ args ) === 2 ) { $ key = $ args [ count ( $ args ) - 2 ] ; $ value = $ args [ count ( $ args ) - 1 ] ; $ cfg [ $ key ] = $ value ; } else { if ( ! is_array ( $ cfg ) || ! $ this -> has ( $ args [ 0 ] , $ cfg ) ) throw new NotFoundSettingsException ( $ args [ 0 ] ) ; eval ( '$this->_set($cfg[$args[0]], array_slice($args, 1));' ) ; } }
Sets a setting in a plain settings array .
12,328
protected function setOptional ( $ key , $ value ) { if ( ! $ this -> has ( $ key ) ) $ this -> set ( $ key , $ value ) ; }
Sets a setting if it is not already set .
12,329
public function current ( ) { if ( ! isset ( $ this -> tokenList [ $ this -> ptr ] ) ) { throw new \ UnexpectedValueException ( "Unexpected input at offset {$this->ptr}, unexpected end of stream" ) ; } return $ this -> tokenList [ $ this -> ptr ] ; }
Returns the current token
12,330
public function to ( $ unit , $ precision = null ) { $ fromUnit = UnitResolver :: resolve ( $ this -> from ) ; $ toUnit = UnitResolver :: resolve ( $ unit ) ; $ this -> setBase ( $ unit ) ; $ base = $ this -> getBase ( ) == 2 ? 1024 : 1000 ; if ( $ toUnit > $ fromUnit ) return $ this -> div ( $ this -> start , pow ( $ base , $ toUnit - $ fromUnit ) , $ precision ) ; return $ this -> mul ( $ this -> start , pow ( $ base , $ fromUnit - $ toUnit ) , $ precision ) ; }
Convert the start value to the given unit . Accepts an optional precision for how many significant digits to retain
12,331
public function toBest ( $ precision = null ) { $ fromUnit = UnitResolver :: resolve ( $ this -> from ) ; $ base = $ this -> getBase ( ) == 2 ? 1024 : 1000 ; $ converted = $ this -> start ; while ( $ converted >= 1 ) { $ fromUnit ++ ; $ result = $ this -> div ( $ this -> start , pow ( $ base , $ fromUnit ) , $ precision ) ; if ( $ result <= 1 ) return $ converted ; $ converted = $ result ; } return $ converted ; }
Convert the start value to it s highest whole unit . Accespts an optional precision for how many significant digits to retain
12,332
protected function div ( $ left , $ right , $ precision ) { if ( is_null ( $ precision ) ) return $ left / $ right ; return floatval ( \ bcdiv ( $ left , $ right , $ precision ) ) ; }
Use bcdiv if precision is specified otherwise use native division operator
12,333
protected function mul ( $ left , $ right , $ precision ) { if ( is_null ( $ precision ) ) return $ left * $ right ; return floatval ( \ bcmul ( $ left , $ right , $ precision ) ) ; }
Use bcmul if precision is specified otherwise use native multiplication operator
12,334
protected function shouldSetBaseTen ( $ unit ) { $ unitMatchesIec = preg_match ( UnitResolver :: IEC_PATTERN , $ unit ) ; return ( $ this -> from == 'B' && ! $ unitMatchesIec ) || ( preg_match ( UnitResolver :: SI_PATTERN , $ this -> from ) && ! $ unitMatchesIec ) ; }
Match from against the unit to see if the base should be set to 10
12,335
public function isValid ( $ json = null ) { if ( empty ( $ json ) || ctype_space ( $ json ) ) return false ; json_decode ( $ json ) ; return ( json_last_error ( ) === JSON_ERROR_NONE ) ; }
Determine is valid json or not
12,336
public function locate ( $ name , $ dir = null , $ first = true ) { if ( '@' === $ name [ 0 ] ) { return $ this -> themeLocator -> locateTemplate ( $ name ) ; } return parent :: locate ( $ name , $ dir , $ first ) ; }
Returns a full path for a given template
12,337
private function buildRightJoins ( ) { $ resultArray = array ( ) ; foreach ( $ this -> rightJoins as $ rJoinPart ) { $ oneItemResult = '' ; if ( $ rJoinPart === null ) { break ; } $ reversedTables = array_reverse ( $ rJoinPart [ 'tables' ] ) ; $ reversedConditions = array_reverse ( $ rJoinPart [ 'conditions' ] ) ; list ( $ key , $ val ) = each ( $ reversedTables ) ; $ oneItemResult .= $ val ; while ( list ( $ key , $ nextCondition ) = each ( $ reversedConditions ) ) { list ( $ key2 , $ nextTable ) = each ( $ reversedTables ) ; $ oneItemResult .= " LEFT JOIN {$nextTable} ON {$nextCondition}" ; } $ resultArray [ ] = $ oneItemResult ; } return join ( ', ' , $ resultArray ) ; }
Returns SQL string with part of FROM clause that performs right join emulation .
12,338
protected function injectServices ( Container $ app ) { if ( isset ( $ app [ 'profiler' ] ) ) { $ app [ 'geocoder.logger' ] = function ( $ app ) { return new \ Geocoder \ Logger \ GeocoderLogger ( ) ; } ; $ app [ 'geocoder' ] = function ( $ app ) { $ geocoder = new \ Geocoder \ LoggableGeocoder ( ) ; $ geocoder -> setLogger ( $ app [ 'geocoder.logger' ] ) ; $ geocoder -> registerProvider ( $ app [ 'geocoder.provider' ] ) ; return $ geocoder ; } ; } else { $ app [ 'geocoder' ] = function ( $ app ) { $ geocoder = new \ Geocoder \ Geocoder ( ) ; $ geocoder -> registerProvider ( $ app [ 'geocoder.provider' ] ) ; return $ geocoder ; } ; } $ app [ 'geocoder.provider' ] = function ( $ app ) { return new \ Geocoder \ Provider \ FreeGeoIpProvider ( $ app [ 'geocoder.adapter' ] ) ; } ; $ app [ 'geocoder.adapter' ] = function ( $ app ) { return new \ Geocoder \ HttpAdapter \ CurlHttpAdapter ( ) ; } ; }
Injects Geocoder related services in the application .
12,339
protected function injectDataCollector ( Container $ app ) { $ app [ 'data_collector.templates' ] = $ app -> extend ( 'data_collector.templates' , function ( $ templates ) { $ templates [ ] = [ 'geocoder' , '@Geocoder/Collector/geocoder.html.twig' ] ; return $ templates ; } ) ; $ app [ 'data_collectors' ] = $ app -> extend ( 'data_collectors' , function ( $ dataCollectors ) { $ dataCollectors [ 'geocoder' ] = function ( $ app ) { return new GeocoderDataCollector ( $ app [ 'geocoder.logger' ] ) ; } ; return $ dataCollectors ; } ) ; $ app [ 'twig.loader.filesystem' ] = $ app -> extend ( 'twig.loader.filesystem' , function ( $ loader , $ app ) { $ loader -> addPath ( $ app [ 'geocoder.templates_path' ] , 'Geocoder' ) ; return $ loader ; } ) ; $ app [ 'geocoder.templates_path' ] = function ( ) { $ r = new \ ReflectionClass ( 'Geocoder\Provider\GeocoderServiceProvider' ) ; return dirname ( dirname ( $ r -> getFileName ( ) ) ) . '/../../views' ; } ; }
Injects Geocoder s data collector in the profiler
12,340
public static function asArray ( $ collection , $ safe = false , $ eager = false ) { $ elements = array ( ) ; foreach ( $ collection as $ key => $ element ) $ elements [ ] = $ element -> asArray ( $ safe , $ eager ) ; return $ elements ; }
Retrieve all the Collections s data in an array
12,341
public function canCreateServiceWithName ( ServiceLocatorInterface $ serviceLocator , $ name , $ requestedName ) { $ config = $ serviceLocator -> get ( 'config' ) ; $ class = $ this -> getClass ( $ config , $ requestedName ) ; return $ class && class_exists ( $ class ) ; }
Test if configuration exists and has class field
12,342
public function createServiceWithName ( ServiceLocatorInterface $ serviceLocator , $ name , $ requestedName ) { $ config = $ serviceLocator -> get ( 'config' ) ; $ class = $ this -> getClass ( $ config , $ requestedName ) ; return new $ class ( $ config [ $ requestedName ] ) ; }
Create and configure class by creating new instance of class from configuration
12,343
protected function getClass ( $ config , $ name ) { if ( array_key_exists ( $ name , $ config ) && is_array ( $ config [ $ name ] ) && array_key_exists ( 'class' , $ config [ $ name ] ) && is_scalar ( $ config [ $ name ] [ 'class' ] ) ) { return $ config [ $ name ] [ 'class' ] ; } return false ; }
Look for class name in configuration
12,344
public function connect ( ) { if ( ! class_exists ( 'SQLite3' ) ) { throw new Exceptions \ UnableToConnectException ( 'SQLite3 PHP extension is not available. It probably has not ' . 'been installed. Please install and configure it in order to use ' . 'SQLite3.' ) ; } $ filename = $ this -> config [ 'SQLite3' ] [ 'filename' ] ; $ busyTimeout = $ this -> config [ 'SQLite3' ] [ 'busy_timeout' ] ; $ openFlags = $ this -> config [ 'SQLite3' ] [ 'open_flags' ] ; $ encryptionKey = $ this -> config [ 'SQLite3' ] [ 'encryption_key' ] ; if ( ! $ this -> connected ) { $ this -> link = new SQLite3 ( $ filename , $ openFlags , $ encryptionKey ) ; if ( $ this -> link ) { $ this -> connected = true ; $ this -> link -> busyTimeout ( $ busyTimeout ) ; $ this -> link -> exec ( "PRAGMA encoding = \"UTF-8\";" ) ; $ this -> link -> exec ( "PRAGMA foreign_keys = 1;" ) ; $ this -> link -> exec ( "PRAGMA case_sensitive_like = 1;" ) ; $ this -> link -> createFunction ( 'preg_match' , 'preg_match' , 2 , SQLITE3_DETERMINISTIC ) ; $ this -> link -> createFunction ( 'regexp' , function ( $ pattern , $ subject ) { return ! ! $ this -> posixRegexMatch ( $ pattern , $ subject ) ; } , 2 , SQLITE3_DETERMINISTIC ) ; } else { $ this -> connected = false ; if ( $ filename === ':memory:' ) { throw new Exceptions \ NotConfiguredException ( ) ; } else { throw new Exceptions \ UnableToConnectException ( 'Could not connect.' ) ; } } } return $ this -> connected ; }
Connect to the SQLite3 database .
12,345
public function disconnect ( ) { if ( $ this -> connected ) { if ( is_a ( $ this -> link , 'SQLite3' ) ) { $ this -> link -> exec ( "PRAGMA optimize;" ) ; $ this -> link -> close ( ) ; } $ this -> connected = false ; } return $ this -> connected ; }
Disconnect from the SQLite3 database .
12,346
public function log ( $ message ) { if ( ! empty ( $ this -> log_file ) ) { \ file_put_contents ( $ this -> log_file , "\n" . $ message , \ FILE_APPEND ) ; } }
Logs messages to a log file if it is set
12,347
public function open ( ) { $ host = "{" . $ this -> host . ":" . $ this -> port . "/" . $ this -> protocol . "/notls}INBOX" ; $ this -> inbox = \ imap_open ( $ host , $ this -> address , $ this -> pass ) ; if ( ! $ this -> inbox ) { $ this -> connected = 0 ; } else { $ this -> connected = 1 ; } return $ this -> connected ; }
Opens the inbox and returns the connection status
12,348
public function close ( $ expunge ) { if ( $ expunge ) { \ imap_close ( $ this -> inbox , CL_EXPUNGE ) ; } else { \ imap_close ( $ this -> inbox ) ; } }
Closes the inbox and expunges deleted messages if expunge is true
12,349
public function parseHeaderInfo ( Email & $ email , $ header ) { $ email -> all_headers = $ header ; $ email -> subject = $ header -> subject ; $ email -> to = $ header -> to [ 0 ] -> mailbox . '@' . $ header -> to [ 0 ] -> host ; $ email -> from = $ header -> from [ 0 ] -> mailbox . '@' . $ header -> from [ 0 ] -> host ; $ email -> reply_to = $ header -> reply_to [ 0 ] -> mailbox . '@' . $ header -> reply_to [ 0 ] -> host ; $ email -> sender = $ header -> sender [ 0 ] -> mailbox . '@' . $ header -> sender [ 0 ] -> host ; $ email -> size = $ header -> Size ; $ email -> date = $ header -> date ; $ email -> timestamp = $ header -> udate ; $ email -> message_id = $ header -> message_id ; if ( $ header -> Deleted == 'D' ) { $ email -> deleted = 1 ; } $ this -> headers = $ header ; }
Parses header information from an email and returns it to as properties of the email object
12,350
private function examinePart ( & $ email , $ part ) { $ subtype = \ strtolower ( $ part -> subtype ) ; $ encoding = $ part -> encoding ; switch ( $ subtype ) { case 'plain' : if ( empty ( $ email -> body ) ) { $ email -> body_encoding = $ encoding ; $ email -> body = imap_fetchbody ( $ this -> inbox , $ email -> index , $ part -> part_id ) ; } break ; case 'html' : $ email -> body_HTML = imap_fetchbody ( $ this -> inbox , $ email -> index , $ part -> part_id ) ; break ; case 'applefile' : case 'gif' : case 'png' : case 'jpg' : case 'jpeg' : case 'wav' : case 'mp3' : case 'mp4' : case 'flv' : if ( $ part -> type == 5 ) { $ attachment = new Email_Attachment ( ) ; $ attachment -> sizeK = $ part -> bytes / 1000 ; $ attachment -> subtype = $ subtype ; $ attachment -> type = $ part -> type ; $ attachment -> name = $ part -> dparameters [ 0 ] -> value ; $ attachment -> name = \ str_ireplace ( 'jpeg' , 'jpg' , $ attachment -> name ) ; $ attachment -> extension = \ strtolower ( end ( explode ( "." , $ attachment -> name ) ) ) ; $ attachment -> contents = \ imap_fetchbody ( $ this -> inbox , $ email -> index , $ part -> part_id ) ; if ( $ part -> encoding == 3 ) { $ attachment -> contents = \ imap_base64 ( $ attachment -> contents ) ; } $ attachment -> encoding = $ part -> encoding ; $ email -> attachments [ ] = $ attachment ; } } }
Check in an email part for attachments and data
12,351
public function fetchMessages ( ) { $ this -> countMessages ( ) ; if ( $ this -> email_count == 0 ) { $ this -> log ( 'There are no emails to process!' ) ; return false ; } $ this -> log ( $ this -> email_count . ' ' . \ Strings :: pluralize ( $ this -> email_count , 'email' ) . ' to process.' ) ; for ( $ i = 1 ; $ i < $ this -> email_count + 1 ; $ i ++ ) { $ email = new Email ; $ email -> index = $ i ; $ this -> parseHeaderInfo ( $ email , imap_headerinfo ( $ this -> inbox , $ i ) ) ; $ structure = \ imap_fetchstructure ( $ this -> inbox , $ i ) ; $ email -> subtype = \ strtolower ( $ structure -> subtype ) ; $ email -> structure = $ structure ; if ( isset ( $ structure -> parts ) ) { $ part_id = 1 ; foreach ( $ structure -> parts as $ part ) { $ type = $ part -> type ; $ sub_id = 1 ; if ( $ type == 1 && isset ( $ part -> parts ) ) { foreach ( $ part -> parts as $ part ) { $ part -> part_id = $ part_id . '.' . $ sub_id ; $ this -> examinePart ( $ email , $ part ) ; $ sub_id ++ ; } } else { $ part -> part_id = $ part_id ; $ this -> examinePart ( $ email , $ part , $ part_id ) ; } $ part_id ++ ; } } else { $ email -> body = \ imap_fetchbody ( $ this -> inbox , $ i , 1 ) ; $ email -> body_encoding = $ structure -> encoding ; } if ( $ email -> body_encoding == 3 ) { $ email -> body = \ base64_decode ( $ email -> body ) ; } $ this -> log ( print_r ( $ email , 1 ) ) ; $ this -> emails [ ] = $ email ; } }
Fetches all the messages in an inbox and put them in the emails array
12,352
public function index ( TeamRequest $ request ) { $ view = $ this -> response -> theme -> listView ( ) ; if ( $ this -> response -> typeIs ( 'json' ) ) { $ function = camel_case ( 'get-' . $ view ) ; return $ this -> repository -> setPresenter ( \ Litecms \ Team \ Repositories \ Presenter \ TeamPresenter :: class ) -> $ function ( ) ; } $ teams = $ this -> repository -> paginate ( ) ; return $ this -> response -> title ( trans ( 'team::team.names' ) ) -> view ( 'team::team.index' , true ) -> data ( compact ( 'teams' ) ) -> output ( ) ; }
Display a list of team .
12,353
public function show ( TeamRequest $ request , Team $ team ) { if ( $ team -> exists ) { $ view = 'team::team.show' ; } else { $ view = 'team::team.new' ; } return $ this -> response -> title ( trans ( 'app.view' ) . ' ' . trans ( 'team::team.name' ) ) -> data ( compact ( 'team' ) ) -> view ( $ view , true ) -> output ( ) ; }
Display team .
12,354
public function edit ( TeamRequest $ request , Team $ team ) { return $ this -> response -> title ( trans ( 'app.edit' ) . ' ' . trans ( 'team::team.name' ) ) -> view ( 'team::team.edit' , true ) -> data ( compact ( 'team' ) ) -> output ( ) ; }
Show team for editing .
12,355
public function update ( TeamRequest $ request , Team $ team ) { try { $ attributes = $ request -> all ( ) ; $ team -> update ( $ attributes ) ; return $ this -> response -> message ( trans ( 'messages.success.updated' , [ 'Module' => trans ( 'team::team.name' ) ] ) ) -> code ( 204 ) -> status ( 'success' ) -> url ( guard_url ( 'team/team/' . $ team -> getRouteKey ( ) ) ) -> redirect ( ) ; } catch ( Exception $ e ) { return $ this -> response -> message ( $ e -> getMessage ( ) ) -> code ( 400 ) -> status ( 'error' ) -> url ( guard_url ( 'team/team/' . $ team -> getRouteKey ( ) ) ) -> redirect ( ) ; } }
Update the team .
12,356
public function destroy ( TeamRequest $ request , Team $ team ) { try { $ team -> delete ( ) ; return $ this -> response -> message ( trans ( 'messages.success.deleted' , [ 'Module' => trans ( 'team::team.name' ) ] ) ) -> code ( 202 ) -> status ( 'success' ) -> url ( guard_url ( 'team/team/0' ) ) -> redirect ( ) ; } catch ( Exception $ e ) { return $ this -> response -> message ( $ e -> getMessage ( ) ) -> code ( 400 ) -> status ( 'error' ) -> url ( guard_url ( 'team/team/' . $ team -> getRouteKey ( ) ) ) -> redirect ( ) ; } }
Remove the team .
12,357
public function Quality ( $ quality ) { $ variant = $ this -> owner -> variantName ( __FUNCTION__ , $ quality ) ; return $ this -> owner -> manipulateImage ( $ variant , function ( Image_Backend $ backend ) use ( $ quality ) { $ backendClone = clone $ backend ; $ backendClone -> setQuality ( $ quality ) ; return $ backendClone ; } ) ; }
This function adjusts the quality of of an image using SilverStripe 4 syntax .
12,358
protected function httpPatch ( string $ path , $ body , array $ requestHeaders = [ ] ) : ResponseInterface { $ requestHeaders [ 'Content-Type' ] = 'application/json' ; return $ response = $ this -> httpClient -> sendRequest ( $ this -> requestBuilder -> create ( 'PATCH' , $ path , $ requestHeaders , json_encode ( $ body ) ) ) ; }
Send a PATCH request with json encoded data .
12,359
protected function getCurrentNode ( ) { libxml_clear_errors ( ) ; $ node = @ $ this -> reader -> expand ( ) ; $ error = libxml_get_last_error ( ) ; if ( $ error instanceof LibXMLError ) { if ( $ error -> level > LIBXML_ERR_WARNING ) { throw new EssenceException ( sprintf ( '%s @ line #%d [%s]' , trim ( $ error -> message ) , $ error -> line , $ this -> current ) , $ error -> code ) ; } } try { return $ this -> doc -> importNode ( $ node , true ) ; } catch ( DOMException $ e ) { throw new EssenceException ( 'Node import failed' , 0 , $ e ) ; } }
Get the current node
12,360
protected function nextElement ( ) { do { if ( ! $ this -> reader -> read ( ) ) { return false ; } $ this -> stack = array_slice ( $ this -> stack , 0 , $ this -> reader -> depth , true ) ; $ this -> stack [ ] = $ this -> reader -> name ; $ this -> current = implode ( '/' , $ this -> stack ) ; $ this -> skip = ( $ this -> skip == $ this -> current ) ? null : $ this -> skip ; } while ( $ this -> skip ) ; return true ; }
Read the next Element and handle skipping
12,361
protected function getData ( $ xpath ) { $ xpath = trim ( $ xpath , '/' ) ; if ( isset ( $ this -> data [ $ xpath ] ) ) { return $ this -> data [ $ xpath ] ; } throw new EssenceException ( 'Unregistered Element XPath: "/' . $ xpath . '"' ) ; }
Get registered Element data
12,362
protected static function DOMNodeChildCount ( DOMNode $ node ) { $ count = 0 ; if ( $ node -> hasChildNodes ( ) ) { foreach ( $ node -> childNodes as $ child ) { if ( $ child -> nodeType == XML_ELEMENT_NODE ) { $ count ++ ; } } } return $ count ; }
Count the children of a DOMNode
12,363
protected static function DOMNodeAttributes ( DOMNode $ node ) { $ attributes = array ( ) ; foreach ( $ node -> attributes as $ attribute ) { $ attributes [ $ attribute -> name ] = $ attribute -> value ; } return $ attributes ; }
Get the DONNode attributes
12,364
protected static function DOMNodeValue ( DOMNode $ node , $ associative = false , $ attributes = false ) { if ( static :: DOMNodeChildCount ( $ node ) == 0 && ( $ node -> hasAttributes ( ) === false || $ attributes === false ) ) { return $ node -> nodeValue ; } $ children = array ( ) ; if ( $ node -> hasAttributes ( ) && $ attributes ) { $ children [ '@' ] = static :: DOMNodeAttributes ( $ node ) ; } foreach ( $ node -> childNodes as $ child ) { if ( $ child instanceof DOMText && $ child -> isWhitespaceInElementContent ( ) ) { continue ; } if ( static :: DOMNodeChildCount ( $ child ) > 0 ) { $ value = static :: DOMNodeValue ( $ child , $ associative ) ; } else { $ value = $ child -> nodeValue ; } if ( $ associative ) { $ children [ $ child -> nodeName ] [ ] = $ value ; } else { $ children [ ] = $ value ; } } return $ children ; }
Get the DOMNode value
12,365
public static function DOMNodeListToArray ( DOMNodeList $ nodeList , $ associative = false , $ attributes = false ) { $ nodes = array ( ) ; foreach ( $ nodeList as $ node ) { $ nodes [ ] = static :: DOMNodeValue ( $ node , $ associative , $ attributes ) ; } return $ nodes ; }
Convert a DOMNodeList into an Array
12,366
public function dump ( $ input , array $ config = array ( ) ) { $ config = array_replace_recursive ( array ( 'encoding' => 'UTF-8' , 'options' => LIBXML_PARSEHUGE , ) , $ config ) ; $ this -> prepare ( $ input , $ config ) ; $ paths = array ( ) ; while ( $ this -> nextElement ( ) ) { if ( ! $ this -> reader -> isEmptyElement && $ this -> reader -> nodeType === XMLReader :: ELEMENT ) { $ paths [ ] = $ this -> current ; } } return array_count_values ( $ paths ) ; }
Dump XPaths and all their occurrences
12,367
public function validateLicenseUrl ( $ str ) { if ( $ str ) { return ( $ this -> validateUrl ( $ str ) || $ this -> validatePackageName ( $ str ) ) ; } return true ; }
Validate License url
12,368
public function validateCompatible ( array $ data ) { if ( ! count ( $ data ) ) { return true ; } $ count = 0 ; foreach ( $ data as $ k => $ v ) { foreach ( array ( 'name' , 'channel' , 'min' , 'max' ) as $ fld ) { $ $ fld = trim ( $ v [ $ fld ] ) ; } $ count ++ ; $ res = $ this -> validateUrl ( $ channel ) && strlen ( $ channel ) ; if ( ! $ res ) { $ this -> addError ( "Invalid or empty channel in compat. #{$count}" ) ; } $ res = $ this -> validatePackageName ( $ name ) && strlen ( $ name ) ; if ( ! $ res ) { $ this -> addError ( "Invalid or empty name in compat. #{$count}" ) ; } $ res1 = $ this -> validateVersion ( $ min ) ; if ( ! $ res1 ) { $ this -> addError ( "Invalid or empty minVersion in compat. #{$count}" ) ; } $ res2 = $ this -> validateVersion ( $ max ) ; if ( ! $ res2 ) { $ this -> addError ( "Invalid or empty maxVersion in compat. #{$count}" ) ; } if ( $ res1 && $ res2 && $ this -> versionLower ( $ max , $ min ) ) { $ this -> addError ( "Max version is lower than min in compat #{$count}" ) ; } } return ! $ this -> hasErrors ( ) ; }
Validate compatible data
12,369
public function validateAuthors ( array $ authors ) { if ( ! count ( $ authors ) ) { $ this -> addError ( 'Empty authors section' ) ; return false ; } $ count = 0 ; foreach ( $ authors as $ k => $ v ) { $ count ++ ; array_map ( 'trim' , $ v ) ; $ name = $ v [ 'name' ] ; $ login = $ v [ 'user' ] ; $ email = $ v [ 'email' ] ; $ res = $ this -> validateMaxLen ( $ name , 256 ) && strlen ( $ name ) ; if ( ! $ res ) { $ this -> addError ( "Invalid or empty name for author #{$count}" ) ; } $ res = $ this -> validatePackageName ( $ login ) && strlen ( $ login ) ; if ( ! $ res ) { $ this -> addError ( "Invalid or empty login for author #{$count}" ) ; } $ res = $ this -> validateEmail ( $ email ) ; if ( ! $ res ) { $ this -> addError ( "Invalid or empty email for author #{$count}" ) ; } } return ! $ this -> hasErrors ( ) ; }
Validate authors of package
12,370
public function validateDate ( $ date ) { $ subs = null ; $ check1 = preg_match ( "/^([\d]{4})-([\d]{2})-([\d]{2})$/i" , $ date , $ subs ) ; if ( ! $ check1 ) { return false ; } return checkdate ( $ subs [ 2 ] , $ subs [ 3 ] , $ subs [ 1 ] ) ; }
Validate date format
12,371
public function input ( $ type , $ options = [ ] ) { $ options = array_merge ( $ this -> inputOptions , [ 'class' => 'hint-' . Html :: getInputId ( $ this -> model , $ this -> attribute ) ] ) ; $ this -> adjustLabelFor ( $ options ) ; $ this -> parts [ '{input}' ] = Html :: activeInput ( $ type , $ this -> model , $ this -> attribute , $ options ) ; return $ this ; }
Renders an input tag .
12,372
public function getOption ( InputInterface $ input , $ name , $ configPath = null , $ default = null , $ commaSeparated = false ) { $ value = $ input -> getOption ( $ name ) ; if ( $ this -> valueIsEmpty ( $ value ) && $ configPath !== null ) { $ value = $ this -> getConfigValueFromPath ( $ configPath ) ; } if ( $ this -> valueIsEmpty ( $ value ) ) { return ( is_array ( $ value ) && $ default === null ) ? array ( ) : $ default ; } return $ commaSeparated ? $ this -> splitCommaSeparatedValues ( $ value ) : $ value ; }
Returns the value of an option from the command - line parameters configuration or given default .
12,373
protected function splitCommaSeparatedValues ( $ value ) { if ( ! is_array ( $ value ) || ( count ( $ value ) == 1 ) && is_string ( current ( $ value ) ) ) { $ value = ( array ) $ value ; $ value = explode ( ',' , $ value [ 0 ] ) ; } return $ value ; }
Split comma separated values .
12,374
public function getConfigValueFromPath ( $ path ) { $ node = $ this -> configuration ; foreach ( explode ( '/' , $ path ) as $ nodeName ) { if ( ! is_object ( $ node ) ) { return null ; } $ node = $ node -> { 'get' . ucfirst ( $ nodeName ) } ( ) ; } return $ node ; }
Returns a value by traversing the configuration tree as if it was a file path .
12,375
public function load ( ConfigFile $ master , ConfigFile $ slave ) { $ this -> master = $ master ; $ this -> slave = $ slave ; return $ this ; }
Loads the master and slave files
12,376
public function merge ( ) { if ( $ this -> saveBackupBeforeMerge ) { $ this -> saveBackup ( ) ; } $ this -> master -> params ( ) -> merge ( $ this -> slave -> params ( ) -> all ( ) ) ; if ( $ this -> autoSaveMaster ) { $ this -> master -> save ( ) ; } if ( $ this -> deleteSlaveOnMerge ) { $ this -> slave -> delete ( ) ; } }
Performs the merge action
12,377
public function restore ( ) { $ this -> master -> params ( ) -> rollback ( ) ; $ this -> slave -> params ( ) -> rollback ( ) ; $ this -> master -> save ( ) ; $ this -> slave -> save ( ) ; }
Restores the files
12,378
public function updateCron ( SmileEzCron $ cron , $ type , $ value ) { switch ( $ type ) { case 'expression' : if ( ! CronExpression :: isValidExpression ( $ value ) ) { throw new InvalidArgumentException ( 'expression' , 'cron.invalid.type' ) ; } $ cron -> setExpression ( $ value ) ; break ; case 'arguments' : if ( preg_match_all ( '|[a-z0-9_\-]+:[a-z0-9_\-]+|' , $ value ) === 0 ) { throw new InvalidArgumentException ( 'arguments' , 'cron.invalid.type' ) ; } $ cron -> setArguments ( $ value ) ; break ; case 'priority' : if ( ! ctype_digit ( $ value ) ) { throw new InvalidArgumentException ( 'priority' , 'cron.invalid.type' ) ; } $ cron -> setPriority ( ( int ) $ value ) ; break ; case 'enabled' : if ( ! ctype_digit ( $ value ) && ( ( int ) $ value != 1 || ( int ) $ value != 0 ) ) { throw new InvalidArgumentException ( 'enabled' , 'cron.invalid.type' ) ; } $ cron -> setEnabled ( ( int ) $ value ) ; break ; } $ this -> getEntityManager ( ) -> persist ( $ cron ) ; $ this -> getEntityManager ( ) -> flush ( ) ; }
Edit cron definition
12,379
public function & SetAllowedLocalizations ( ) { $ allowedLocalizations = func_get_args ( ) ; if ( count ( $ allowedLocalizations ) === 1 && is_array ( $ allowedLocalizations [ 0 ] ) ) $ allowedLocalizations = $ allowedLocalizations [ 0 ] ; $ this -> allowedLocalizations = array_combine ( $ allowedLocalizations , $ allowedLocalizations ) ; return $ this ; }
Set allowed localizations for the routed module if there is used any variant of module router with localization .
12,380
protected function trriggerUnusedMethodError ( $ method ) { $ selfClass = version_compare ( PHP_VERSION , '5.5' , '>' ) ? self :: class : __CLASS__ ; trigger_error ( "[$selfClass] The method `$method` is not used in this extended class." , E_USER_WARNING ) ; return $ this ; }
Trigger E_USER_WARNING user error about not used method in this extended module domain route .
12,381
public function executeSending ( $ subject , $ body , $ subscriber ) { $ email = $ subscriber -> attribute ( 'email' ) ; $ parameters = array ( ) ; $ parameters [ 'content_type' ] = $ this -> emailContentType ; $ parameters [ 'from' ] = $ this -> emailFrom ; $ transport = eZNotificationTransport :: instance ( 'ezmail' ) ; $ result = $ transport -> send ( array ( $ email ) , $ subject , $ body , null , $ parameters ) ; if ( $ result === false ) { throw new Exception ( 'Send email error! Subscriber id:' . $ subscriber -> attribute ( 'id' ) ) ; } eZDebugSetting :: writeNotice ( 'extension-ezcomments' , "An email has been sent to '$email' (subject: $subject)" , __METHOD__ ) ; }
Execute sending process in Email
12,382
public function setAuthProviders ( array $ params = array ( ) ) { if ( ! isset ( $ params [ 'providers' ] ) ) { throw new MissingArgumentException ( 'providers' ) ; } if ( ! is_array ( $ params [ 'providers' ] ) ) { throw new InvalidArgumentException ( 'Invalid Argument: providers must be passed as array' ) ; } $ params [ 'providers' ] = json_encode ( array_values ( $ params [ 'providers' ] ) ) ; return $ this -> post ( 'set_auth_providers' , $ params ) ; }
Defines the list of identity providers provided by the Engage server to sign - in widgets . This is the same list that is managed by the dashboard .
12,383
public function selectDistinct ( ) { if ( $ this -> selectString == null ) { $ this -> selectString = 'SELECT DISTINCT ' ; } elseif ( strpos ( $ this -> selectString , 'DISTINCT' ) === false ) { throw new ezcQueryInvalidException ( 'SELECT' , 'You can\'t use selectDistinct() after using select() in the same query.' ) ; } $ args = func_get_args ( ) ; return call_user_func_array ( array ( $ this , 'select' ) , $ args ) ; }
Opens the query and uses a distinct select on the columns you want to return with the query .
12,384
public function getQuery ( ) { if ( $ this -> selectString == null ) { throw new ezcQueryInvalidException ( "SELECT" , "select() was not called before getQuery()." ) ; } $ query = "{$this->selectString}" ; if ( $ this -> fromString != null ) { $ query = "{$query} {$this->fromString}" ; } if ( $ this -> whereString != null ) { $ query = "{$query} {$this->whereString}" ; } if ( $ this -> groupString != null ) { $ query = "{$query} {$this->groupString}" ; } if ( $ this -> havingString != null ) { $ query = "{$query} {$this->havingString}" ; } if ( $ this -> orderString != null ) { $ query = "{$query} {$this->orderString}" ; } if ( $ this -> limitString != null ) { $ query = "{$query} {$this->limitString}" ; } return $ query ; }
Returns the complete select query string .
12,385
public function injectIdentityModel ( MvcEvent $ event ) { $ viewModel = $ event -> getViewModel ( ) ; if ( $ viewModel -> getTemplate ( ) == 'layout/layout' ) { $ servies = $ event -> getApplication ( ) -> getServiceManager ( ) ; $ appConfig = $ servies -> get ( 'config' ) ; if ( isset ( $ appConfig [ 'view_model_identity' ] ) ) { $ config = $ appConfig [ 'view_model_identity' ] ; } else { throw new \ Exception ( 'view_model_identity key not found in configuration' ) ; } if ( ! $ servies -> has ( $ config [ 'authenticationService' ] ) ) { throw new \ Exception ( 'Auththentication service not found' ) ; } if ( ! $ servies -> has ( $ config [ 'identity' ] ) ) { throw new \ Exception ( 'Identity not found' ) ; } $ childViewModel = new IdentityViewModel ( array ( 'auth' => $ servies -> get ( $ config [ 'authenticationService' ] ) , 'identity' => $ servies -> get ( $ config [ 'identity' ] ) , ) ) ; if ( isset ( $ config [ 'template' ] ) ) { $ childViewModel -> setTemplate ( $ config [ 'template' ] ) ; } if ( isset ( $ config [ 'captureTo' ] ) ) { $ childViewModel -> setCaptureTo ( $ config [ 'captureTo' ] ) ; } $ viewModel -> addChild ( $ childViewModel ) ; } }
Inject identity view model into layout
12,386
public function create ( string $ projectKey , string $ name , array $ params = [ ] ) { $ params [ 'name' ] = $ name ; $ response = $ this -> httpPost ( sprintf ( '/api/v2/projects/%s/keys' , $ projectKey ) , $ params ) ; if ( ! $ this -> hydrator ) { return $ response ; } if ( $ response -> getStatusCode ( ) !== 200 && $ response -> getStatusCode ( ) !== 201 ) { $ this -> handleErrors ( $ response ) ; } return $ this -> hydrator -> hydrate ( $ response , KeyCreated :: class ) ; }
Create a new key .
12,387
public function search ( string $ projectKey , array $ params = [ ] ) { $ q = '' ; if ( isset ( $ params [ 'tags' ] ) ) { $ q .= 'tags:' . $ params [ 'tags' ] . ' ' ; } if ( isset ( $ params [ 'name' ] ) ) { $ q .= 'name:' . $ params [ 'name' ] . ' ' ; } if ( isset ( $ params [ 'ids' ] ) ) { $ q .= 'ids:' . $ params [ 'ids' ] . ' ' ; } if ( ! empty ( $ q ) ) { $ params [ 'q' ] = $ q ; } $ response = $ this -> httpPost ( sprintf ( '/api/v2/projects/%s/keys/search' , $ projectKey ) , $ params ) ; if ( ! $ this -> hydrator ) { return $ response ; } if ( $ response -> getStatusCode ( ) !== 200 && $ response -> getStatusCode ( ) !== 201 ) { $ this -> handleErrors ( $ response ) ; } return $ this -> hydrator -> hydrate ( $ response , KeySearchResults :: class ) ; }
Search keys .
12,388
public function delete ( string $ projectKey , string $ keyId ) { $ response = $ this -> httpDelete ( sprintf ( '/api/v2/projects/%s/keys/%s' , $ projectKey , $ keyId ) ) ; if ( ! $ this -> hydrator ) { return $ response ; } if ( $ response -> getStatusCode ( ) !== 204 ) { $ this -> handleErrors ( $ response ) ; } return true ; }
Delete a key .
12,389
private function setPayloadParameter ( string $ parameter , $ value ) : void { $ this -> checkParameterType ( $ value ) ; $ this -> defaultSetPayloadParameter ( $ parameter , $ value ) ; }
Set payload parameter .
12,390
final protected function checkParameterType ( $ value ) : void { if ( \ is_array ( $ value ) ) { foreach ( $ value as $ val ) { $ this -> checkParameterType ( $ val ) ; } } elseif ( $ value !== null && ! \ is_scalar ( $ value ) ) { throw new InvalidScalarParameterException ( \ sprintf ( 'Class %s can only accept scalar payload parameters, %s given' , self :: class , \ is_object ( $ value ) ? \ get_class ( $ value ) : \ gettype ( $ value ) ) ) ; } }
Check only scalar types allowed .
12,391
public function parse ( ) { $ raw = $ this -> getRaw ( ) ; $ count = count ( $ raw ) ; for ( $ i = 7 ; $ i < $ count ; $ i ++ ) { $ line = $ raw [ $ i ] ; $ process = new Process ( $ line [ 11 ] , $ line [ 0 ] , floatval ( $ line [ 8 ] ) , floatval ( $ line [ 9 ] ) ) ; $ this -> processes [ ] = $ process ; } }
Run the parsing process
12,392
public function setItems ( $ items = array ( ) ) { $ this -> items = array ( ) ; foreach ( $ items as $ key => $ item ) { if ( ! is_numeric ( $ key ) && is_array ( $ item ) ) { if ( array_key_exists ( '1' , $ item ) ) { $ this -> setItems ( $ item ) ; return false ; } else { $ this -> push ( $ item ) ; } } elseif ( is_array ( $ item ) ) { $ this -> push ( $ item ) ; } } }
Set all the items at once
12,393
public function push ( $ item ) { $ full_class_name = $ this -> getFullClassName ( ) ; if ( is_array ( $ item ) ) { array_push ( $ this -> items , new $ full_class_name ( $ item ) ) ; } elseif ( $ item instanceof $ full_class_name ) { array_push ( $ this -> items , $ item ) ; } }
Add a new item to the collection
12,394
public static function isInt ( $ int ) { return ( is_string ( $ int ) || is_int ( $ int ) || is_float ( $ int ) ) && ctype_digit ( ( string ) $ int ) ; }
Checks to see if str float or int type and represents whole number
12,395
public function setQueryParameter ( $ name , $ value ) { $ this -> query [ ( string ) $ name ] = ( string ) $ value ; return $ this ; }
Set a query parameter .
12,396
public function getQueryParameter ( $ name ) { return isset ( $ this -> query [ $ name ] ) ? $ this -> query [ $ name ] : null ; }
Retrieve the value of a query parameter .
12,397
public function addQueryParameters ( $ queryString ) { $ queries = preg_split ( '/&(amp;)?/i' , $ queryString ) ; foreach ( $ queries as $ v ) { $ explode = explode ( '=' , $ v ) ; $ name = $ explode [ 0 ] ; $ value = isset ( $ explode [ 1 ] ) ? $ explode [ 1 ] : '' ; $ rpos = strrpos ( $ name , '?' ) ; if ( $ rpos !== false ) { $ name = substr ( $ name , ( $ rpos + 1 ) ) ; } if ( empty ( $ name ) ) { continue ; } $ this -> setQueryParameter ( $ name , $ value ) ; } return $ this ; }
Absorb the query parameters from a query string .
12,398
public function getBaseUrl ( ) { $ url = '' ; if ( isset ( $ this -> scheme ) ) { if ( '' !== $ this -> scheme ) { $ url .= $ this -> scheme . ':' ; } $ url .= '//' ; } if ( isset ( $ this -> user ) ) { $ url .= $ this -> user ; if ( isset ( $ this -> pass ) ) { $ url .= ':' . $ this -> pass ; } $ url .= '@' ; } $ url .= $ this -> host ; if ( isset ( $ this -> port ) ) { $ url .= ':' . $ this -> port ; } if ( isset ( $ this -> path ) ) { if ( $ url != '' && $ this -> path [ 0 ] !== '/' ) { $ url .= '/' ; } $ url .= $ this -> path ; } return $ url ; }
Retrieve the base url .
12,399
public function getUrl ( ) { $ url = $ this -> getBaseUrl ( ) ; if ( $ query = $ this -> getQueryString ( ) ) { if ( $ url ) { if ( ! $ this -> path ) { $ url .= '/' ; } $ url .= '?' ; } $ url .= $ query ; } if ( isset ( $ this -> fragment ) ) { $ url .= '#' . $ this -> fragment ; } return $ url ; }
Retrieve the complete generated URL .