idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
51,800
|
public function get ( $ path , array $ sourceConfig = null ) { $ config = Yaml :: parse ( $ this -> getFileContent ( $ path ) ) ; if ( false === empty ( $ sourceConfig ) ) { return array_replace_recursive ( $ sourceConfig , $ config ) ; } return $ config ; }
|
Returns the config as an array .
|
51,801
|
protected function getFileContent ( $ path ) { if ( false === file_exists ( $ path ) ) { throw new \ InvalidArgumentException ( sprintf ( 'File "%s" does not exist.' , $ path ) ) ; } return file_get_contents ( $ path ) ; }
|
Returns the file s contents .
|
51,802
|
protected function setUriParts ( array $ parts ) { foreach ( $ parts as $ key => $ value ) { if ( ! method_exists ( $ this , "set$key" ) ) { continue ; } $ this -> { "set$key" } ( $ value ) ; } }
|
Set the URI parts
|
51,803
|
protected function buildUri ( array $ parts ) { $ uri = ( $ parts [ 'scheme' ] ? "{$parts['scheme']}:" : '' ) . ( $ parts [ 'user' ] || $ parts [ 'host' ] ? '//' : '' ) . ( $ parts [ 'user' ] ? "{$parts['user']}" : '' ) . ( $ parts [ 'user' ] && $ parts [ 'pass' ] ? ":{$parts['pass']}" : '' ) . ( $ parts [ 'user' ] ? '@' : '' ) . ( $ parts [ 'host' ] ? "{$parts['host']}" : '' ) . ( $ parts [ 'port' ] ? ":{$parts['port']}" : '' ) ; $ uri .= ( $ uri && $ parts [ 'path' ] && $ parts [ 'path' ] [ 0 ] !== '/' ? '/' : '' ) . ( $ parts [ 'path' ] ? "{$parts['path']}" : '' ) . ( $ parts [ 'query' ] ? "?{$parts['query']}" : '' ) . ( $ parts [ 'fragment' ] ? "#{$parts['fragment']}" : '' ) ; return $ uri ; }
|
Build a uri from all the parts
|
51,804
|
protected function determineRequestTarget ( ) { $ params = $ this -> getServerParams ( ) ; return isset ( $ params [ 'REQUEST_URI' ] ) ? $ params [ 'REQUEST_URI' ] : ( isset ( $ params [ 'REQUEST_METHOD' ] ) && $ params [ 'REQUEST_METHOD' ] === 'OPTIONS' ? '*' : '/' ) ; }
|
Determine the request target based on the server params
|
51,805
|
protected function assertRequestTarget ( $ requestTarget ) { if ( ! is_string ( $ requestTarget ) ) { $ type = ( is_object ( $ requestTarget ) ? get_class ( $ requestTarget ) . ' ' : '' ) . gettype ( $ requestTarget ) ; throw new \ InvalidArgumentException ( "Request target should be a string, not a $type" ) ; } }
|
Assert that the request target is a string
|
51,806
|
protected function extractForFromForwardedHeader ( $ forwarded ) { $ ips = [ ] ; $ parts = array_map ( 'trim' , explode ( ',' , $ forwarded ) ) ; foreach ( $ parts as $ part ) { list ( $ key , $ value ) = explode ( '=' , $ part , 2 ) + [ 1 => null ] ; if ( $ key === 'for' ) { $ ips [ ] = trim ( $ value , '[]' ) ; } } return $ ips ; }
|
Extract the for part from the Forwarded header
|
51,807
|
protected function getForwardedIp ( ServerRequestInterface $ request , $ ip ) { $ ips = [ $ ip ] ; $ forwardedFor = $ this -> splitIps ( $ request -> getHeaderLine ( 'X-Forwarded-For' ) ) ; $ forwarded = $ this -> extractForFromForwardedHeader ( $ request -> getHeaderLine ( 'Forwarded' ) ) ; $ clientIp = $ this -> splitIps ( $ request -> getHeaderLine ( 'Client-Ip' ) ) ; if ( ! $ this -> areAllTheSame ( $ forwardedFor , $ forwarded , $ clientIp ) ) { $ msg = 'Only one of `X-Forwarded-For`, `Forwarded` or `Client-Ip` headers should be set' ; throw new \ RuntimeException ( $ msg ) ; } $ fwd = $ forwardedFor ? : $ forwarded ? : $ clientIp ; if ( $ fwd ) { $ ips = array_merge ( $ ips , $ fwd ) ; } return $ this -> getTrustedForwardedIp ( $ ips ) ; }
|
Get the forwarded ip
|
51,808
|
protected function getTrustedForwardedIp ( array $ ips ) { if ( is_string ( $ this -> trustedProxy ) ) { foreach ( $ ips as $ ip ) { if ( \ Jasny \ ip_in_cidr ( $ ip , $ this -> trustedProxy ) ) { continue ; } return $ ip ; } } return end ( $ ips ) ; }
|
Select an IP which is within the list of trusted ips
|
51,809
|
protected static function _cache ( $ type , $ key , $ value = false ) { $ key = '_' . $ key ; $ type = '_' . $ type ; if ( $ value !== false ) { self :: $ _cache [ $ type ] [ $ key ] = $ value ; return $ value ; } if ( ! isset ( self :: $ _cache [ $ type ] [ $ key ] ) ) { return false ; } return self :: $ _cache [ $ type ] [ $ key ] ; }
|
Cache inflected values and return if already available
|
51,810
|
public static function camelize ( $ lowerCaseAndUnderscoredWord ) { if ( ! ( $ result = self :: _cache ( __FUNCTION__ , $ lowerCaseAndUnderscoredWord ) ) ) { $ result = str_replace ( ' ' , '' , Inflector :: humanize ( $ lowerCaseAndUnderscoredWord ) ) ; self :: _cache ( __FUNCTION__ , $ lowerCaseAndUnderscoredWord , $ result ) ; } return $ result ; }
|
Returns the given lower_case_and_underscored_word as a CamelCased word .
|
51,811
|
protected function isValidDomain ( $ hostname ) { return preg_match ( "/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i" , $ hostname ) && preg_match ( "/^.{1,253}$/" , $ hostname ) && preg_match ( "/^[^\.]{1,63}(\.[^\.]{1,63})*$/" , $ hostname ) && ! preg_match ( "/^\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}$/" , $ hostname ) ; }
|
Check if the hostname is valid a valid domain name according to RFC 3986 and RFC 1123
|
51,812
|
protected function setHost ( $ host ) { $ host = strtolower ( $ host ) ; if ( $ host !== '' && ! $ this -> isValidDomain ( $ host ) && ! $ this -> isValidIpv4 ( $ host ) && ! $ this -> isValidIpv6 ( $ host ) ) { throw new \ InvalidArgumentException ( "Invalid hostname '$host'" ) ; } $ this -> host = $ host ; }
|
Set the host
|
51,813
|
public function executeAjaxActions ( $ arrData ) { \ Input :: setGet ( 'no_ajax' , 1 ) ; switch ( \ Input :: post ( 'action' ) ) { case 'fineuploader_upload' : $ arrData [ 'name' ] = \ Input :: post ( 'name' ) ; $ objWidget = new $ GLOBALS [ 'TL_FFL' ] [ 'fineUploader' ] ( $ arrData ) ; $ strFile = $ objWidget -> validateUpload ( ) ; if ( $ objWidget -> hasErrors ( ) ) { $ arrResponse = array ( 'success' => false , 'error' => $ objWidget -> getErrorAsString ( ) , 'preventRetry' => true ) ; } else { $ arrResponse = array ( 'success' => true , 'file' => $ strFile ) ; } $ response = new \ Haste \ Http \ Response \ JsonResponse ( $ arrResponse ) ; $ response -> send ( false ) ; exit ; break ; } }
|
Execute AJAX actions in front end
|
51,814
|
public function withProtocolVersion ( $ version ) { if ( ! is_string ( $ version ) ) { throw new \ InvalidArgumentException ( "Expected protocol version to be a string" ) ; } $ this -> protocolVersion = $ version ; $ this -> sendStatusHeader ( ) ; return $ this ; }
|
Set the protocol version
|
51,815
|
public function checkPermission ( $ model , $ member = null , $ httpMethod ) { if ( is_string ( $ model ) ) { $ model = singleton ( $ model ) ; } switch ( strtoupper ( $ httpMethod ) ) { case 'GET' : return $ model -> canView ( $ member ) ; break ; case 'POST' : return $ model -> canCreate ( $ member ) ; break ; case 'PUT' : return $ model -> canEdit ( $ member ) ; break ; case 'DELETE' : return $ model -> canDelete ( $ member ) ; break ; default : return true ; break ; } }
|
Checks if a given DataObject or Class can be accessed with a given API request by a Member
|
51,816
|
public function only ( $ method ) { if ( ! is_array ( $ method ) ) { $ method = [ $ method ] ; } $ this -> only += $ method ; return $ this ; }
|
Specify the methods that the middleware applies to
|
51,817
|
public function except ( $ method ) { if ( ! is_array ( $ method ) ) { $ method = [ $ method ] ; } $ this -> except += $ method ; return $ this ; }
|
Specify the methods that the middleware does not apply to
|
51,818
|
public function excludedForMethod ( $ method ) : bool { if ( empty ( $ this -> only ) && empty ( $ this -> except ) ) { return false ; } return ( ! empty ( $ this -> only ) && ! in_array ( $ method , $ this -> only ) ) || ( ! empty ( $ this -> except ) && in_array ( $ method , $ this -> except ) ) ; }
|
Is a specific method excluded by the options set on this object
|
51,819
|
protected function assertHeaderValue ( $ value ) { if ( ! is_string ( $ value ) && ( ! is_array ( $ value ) || array_product ( array_map ( 'is_string' , $ value ) ) === 0 ) ) { throw new \ InvalidArgumentException ( "Header value should be a string or an array of strings" ) ; } }
|
Assert that the header value is a string
|
51,820
|
public function init ( ) { parent :: init ( ) ; if ( $ this -> request -> httpMethod ( ) === 'OPTIONS' ) { $ answer = $ this -> answer ( null , true ) ; $ answer -> output ( ) ; exit ; } }
|
Controller inititalisation Catches CORS preflight request marked with HTTPMethod OPTIONS
|
51,821
|
public function index ( HTTPRequest $ request ) { if ( $ this -> authenticator ) { $ policy = $ this -> config ( ) -> authentication_policy ; $ authALL = $ policy === true ; $ authMethod = is_array ( $ policy ) && in_array ( $ request -> httpMethod ( ) , $ policy ) ; if ( $ authALL || $ authMethod ) { $ authResult = $ this -> authenticator -> authenticate ( $ request ) ; if ( $ authResult instanceof RESTfulAPIError ) { return $ this -> error ( $ authResult ) ; } } } $ data = $ this -> queryHandler -> handleQuery ( $ request ) ; if ( $ data instanceof RESTfulAPIError ) { return $ this -> error ( $ data ) ; } $ json = $ this -> serializer -> serialize ( $ data ) ; if ( $ json instanceof RESTfulAPIError ) { return $ this -> error ( $ json ) ; } return $ this -> answer ( $ json ) ; }
|
Main API hub switch All requests pass through here and are redirected depending on HTTP verb and params
|
51,822
|
public function answer ( $ json = null , $ corsPreflight = false ) { $ answer = new HTTPResponse ( ) ; if ( ! $ corsPreflight ) { $ answer -> setBody ( $ json ) ; } $ answer = $ this -> setAnswerCORS ( $ answer ) ; $ answer -> addHeader ( 'Content-Type' , $ this -> serializer -> getcontentType ( ) ) ; $ this -> response = $ answer ; return $ answer ; }
|
Output the API response to client then exit .
|
51,823
|
public function error ( RESTfulAPIError $ error ) { $ answer = new HTTPResponse ( ) ; $ body = $ this -> serializer -> serialize ( $ error -> body ) ; $ answer -> setBody ( $ body ) ; $ answer -> setStatusCode ( $ error -> code , $ error -> message ) ; $ answer -> addHeader ( 'Content-Type' , $ this -> serializer -> getcontentType ( ) ) ; $ answer = $ this -> setAnswerCORS ( $ answer ) ; $ this -> response = $ answer ; return $ answer ; }
|
Handles formatting and output error message then exit .
|
51,824
|
private function setAnswerCORS ( HTTPResponse $ answer ) { $ cors = Config :: inst ( ) -> get ( self :: class , 'cors' ) ; if ( ! $ cors [ 'Enabled' ] ) { return $ answer ; } $ allowedOrigin = $ cors [ 'Allow-Origin' ] ; $ requestOrigin = $ this -> request -> getHeader ( 'Origin' ) ; if ( $ requestOrigin ) { if ( $ cors [ 'Allow-Origin' ] === '*' ) { $ allowedOrigin = $ requestOrigin ; } elseif ( is_array ( $ cors [ 'Allow-Origin' ] ) ) { if ( in_array ( $ requestOrigin , $ cors [ 'Allow-Origin' ] ) ) { $ allowedOrigin = $ requestOrigin ; } } } $ answer -> addHeader ( 'Access-Control-Allow-Origin' , $ allowedOrigin ) ; $ allowedHeaders = '' ; $ requestHeaders = $ this -> request -> getHeader ( 'Access-Control-Request-Headers' ) ; if ( $ cors [ 'Allow-Headers' ] === '*' ) { $ allowedHeaders = $ requestHeaders ; } else { $ allowedHeaders = $ cors [ 'Allow-Headers' ] ; } $ answer -> addHeader ( 'Access-Control-Allow-Headers' , $ allowedHeaders ) ; $ answer -> addHeader ( 'Access-Control-Allow-Methods' , $ cors [ 'Allow-Methods' ] ) ; $ answer -> addHeader ( 'Access-Control-Max-Age' , $ cors [ 'Max-Age' ] ) ; return $ answer ; }
|
Apply the proper CORS response heardes to an HTTPResponse
|
51,825
|
public static function api_access_control ( $ model , $ httpMethod = 'GET' ) { $ policy = self :: config ( ) -> access_control_policy ; if ( $ policy === false ) { return true ; } else { $ policy = constant ( 'self::' . $ policy ) ; } if ( $ policy === self :: ACL_CHECK_MODEL_ONLY ) { $ access = true ; } else { $ access = false ; } if ( $ policy === self :: ACL_CHECK_CONFIG_ONLY || $ policy === self :: ACL_CHECK_CONFIG_AND_MODEL ) { if ( ! is_string ( $ model ) ) { $ className = get_class ( $ model ) ; } else { $ className = $ model ; } $ access = self :: api_access_config_check ( $ className , $ httpMethod ) ; } if ( $ policy === self :: ACL_CHECK_MODEL_ONLY || $ policy === self :: ACL_CHECK_CONFIG_AND_MODEL ) { if ( $ access ) { $ access = self :: model_permission_check ( $ model , $ httpMethod ) ; } } return $ access ; }
|
Checks a class or model api access depending on access_control_policy and the provided model . - 1st config check - 2nd permission check if config access passes
|
51,826
|
private static function model_permission_check ( $ model , $ httpMethod = 'GET' ) { $ access = true ; $ apiInstance = self :: $ instance ; if ( $ apiInstance -> authenticator && $ apiInstance -> authority ) { $ request = $ apiInstance -> request ; $ member = $ apiInstance -> authenticator -> getOwner ( $ request ) ; if ( ! $ member instanceof Member ) { $ member = null ; } $ access = $ apiInstance -> authority -> checkPermission ( $ model , $ member , $ httpMethod ) ; if ( ! is_bool ( $ access ) ) { $ access = true ; } } return $ access ; }
|
Checks a Model s permission for the currently authenticated user via the Permission Manager dependency .
|
51,827
|
public function write ( ) { $ this -> makeFile ( $ this -> formatter -> getFileName ( ) ) ; $ fileContent = file_get_contents ( $ this -> formatter -> getFileName ( ) ) ; $ log = join ( "\n" , ( array ) $ this -> formatter -> generate ( ) ) . "\n" ; if ( false === empty ( $ this -> break ) && 1 === preg_match ( "/^{$this->break}/m" , $ fileContent ) ) { $ splitFileContent = preg_split ( "/^{$this->break}/m" , $ fileContent ) ; file_put_contents ( $ this -> formatter -> getFileName ( ) , $ splitFileContent [ 0 ] . $ this -> break . "\n" . $ log . $ splitFileContent [ 1 ] ) ; return true ; } file_put_contents ( $ this -> formatter -> getFileName ( ) , $ log . $ fileContent ) ; return true ; }
|
Writes the output to a file .
|
51,828
|
public function setInput ( $ input ) { $ inputArray = explode ( ' ' , $ input ) ; array_shift ( $ inputArray ) ; $ this -> input = join ( ' ' , $ inputArray ) ; }
|
Set the input .
|
51,829
|
public function parse ( ) { $ this -> handler -> parse ( $ this -> input ) ; $ output = $ this -> handler -> getOptions ( ) ; if ( false === isset ( $ output [ 'from' ] ) ) { throw new \ BadMethodCallException ( 'The --from argument is required.' ) ; } if ( false === isset ( $ output [ 'release' ] ) ) { throw new \ BadMethodCallException ( 'The --release argument is required.' ) ; } return $ this -> handler ; }
|
Parses the input and returns the Getopt handler .
|
51,830
|
protected function assertUploadedFilesStructure ( array $ uploadedFiles , $ groupKey = null ) { foreach ( $ uploadedFiles as $ key => $ item ) { $ parameterKey = isset ( $ groupKey ) ? "{$groupKey}[{$key}]" : $ key ; if ( is_array ( $ item ) ) { $ this -> assertUploadedFilesStructure ( $ item , $ parameterKey ) ; } elseif ( ! $ item instanceof UploadedFileInterface ) { throw new \ InvalidArgumentException ( "'$parameterKey' is not an UploadedFileInterface object, but a " . ( is_object ( $ item ) ? get_class ( $ item ) . ' ' : '' ) . gettype ( $ item ) ) ; } } }
|
Assert that each leaf is an UploadedFileInterface
|
51,831
|
public function initHeaders ( ) { if ( ! isset ( $ this -> headers ) ) { $ this -> headers = new HeadersObject ( $ this -> determineHeaders ( ) ) ; } return $ this -> headers ; }
|
Public function to create header object
|
51,832
|
protected function setUser ( $ user ) { if ( ! $ this -> isValidUsername ( $ user ) ) { throw new \ InvalidArgumentException ( "Invalid username '$user': double colon not allowed" ) ; } $ this -> user = ( string ) $ user ; }
|
Set the username
|
51,833
|
public function run ( array $ options ) { $ this -> generator = new ReadmeGen ( new ConfigLoader ( ) ) ; $ this -> setupParser ( $ options ) ; $ logGrouped = $ this -> generator -> setExtractor ( new Extractor ( ) ) -> extractMessages ( $ this -> getLog ( ) ) ; $ config = $ this -> generator -> getConfig ( ) ; $ formatterClassName = '\ReadmeGen\Output\Format\\' . ucfirst ( $ config [ 'format' ] ) ; $ formatter = new $ formatterClassName ; $ formatter -> setRelease ( $ options [ 'release' ] ) -> setFileName ( $ config [ 'output_file_name' ] ) -> setDate ( $ this -> getToDate ( ) ) ; $ this -> generator -> setDecorator ( new Decorator ( $ formatter ) ) -> getDecoratedMessages ( $ logGrouped ) ; $ writer = new Writer ( $ formatter ) ; $ break = $ this -> getBreak ( $ options , $ config ) ; if ( false === empty ( $ break ) ) { $ writer -> setBreak ( $ break ) ; } $ this -> generator -> setOutputWriter ( $ writer ) -> writeOutput ( ) ; }
|
Generates the output file .
|
51,834
|
protected function getBreak ( array $ options , array $ config ) { if ( true === isset ( $ options [ 'break' ] ) ) { return $ options [ 'break' ] ; } if ( true === isset ( $ config [ 'break' ] ) ) { return $ config [ 'break' ] ; } return null ; }
|
Returns the breakpoint if set null otherwise .
|
51,835
|
public function withServerParams ( array $ params ) { $ request = $ this -> copy ( ) ; $ request -> serverParams = $ params ; $ request -> reset ( ) ; return $ request ; }
|
Return an instance with the specified server params .
|
51,836
|
public function setMessageGroups ( array $ messageGroups ) { $ this -> messageGroups = $ messageGroups ; foreach ( $ this -> messageGroups as $ header => $ keywords ) { $ this -> messageGroupsJoined [ $ header ] = join ( '|' , $ keywords ) ; } return $ this ; }
|
Message groups setter .
|
51,837
|
public function extract ( ) { foreach ( $ this -> log as $ line ) { foreach ( $ this -> messageGroupsJoined as $ header => $ keywords ) { $ pattern = $ this -> getPattern ( $ keywords ) ; if ( preg_match ( $ pattern , $ line ) ) { $ this -> appendToGroup ( $ header , $ line , $ pattern ) ; } } } foreach ( array_keys ( $ this -> messageGroups ) as $ groupKey ) { if ( true === empty ( $ this -> groups [ $ groupKey ] ) ) { unset ( $ this -> messageGroups [ $ groupKey ] ) ; } } return array_merge ( $ this -> messageGroups , $ this -> groups ) ; }
|
Groups messages and returns them .
|
51,838
|
protected function appendToGroup ( $ groupHeader , $ text , $ pattern ) { $ this -> groups [ $ groupHeader ] [ ] = trim ( preg_replace ( $ pattern , '' , $ text ) ) ; }
|
Appends a message to a group
|
51,839
|
protected function resetParsedBody ( ) { if ( $ this -> parseCondition !== false ) { $ this -> parsedBody = null ; $ this -> parseCondition = null ; } }
|
Reset the parsed body excepted if it was explicitly set
|
51,840
|
protected function shouldUsePostData ( ) { if ( ! isset ( $ this -> postData ) ) { return false ; } $ contentType = $ this -> getContentType ( ) ; return in_array ( $ contentType , [ 'application/x-www-form-urlencoded' , 'multipart/form-data' ] ) || empty ( $ contentType ) && ! array_key_exists ( 'SERVER_PROTOCOL' , $ this -> getServerParams ( ) ) ; }
|
Check if we should use post data rather than parsing the body
|
51,841
|
protected function parseBody ( ) { $ data = null ; switch ( $ this -> getContentType ( ) ) { case 'application/x-www-form-urlencoded' : $ data = $ this -> parseUrlEncodedBody ( ) ; break ; case 'application/json' : $ data = $ this -> parseJsonBody ( ) ; break ; case 'text/xml' : case 'application/xml' : $ data = $ this -> parseXmlBody ( ) ; break ; case 'multipart/form-data' : throw new \ RuntimeException ( "Parsing multipart/form-data isn't supported" ) ; } return $ data ; }
|
Parse the body based on the content type .
|
51,842
|
protected function parseJsonBody ( ) { $ data = json_decode ( $ this -> getBody ( ) , true ) ; if ( ! isset ( $ data ) && json_last_error ( ) ) { trigger_error ( "Failed to parse json body: " . json_last_error_msg ( ) , E_USER_WARNING ) ; } return $ data ; }
|
Parse json body
|
51,843
|
public function emit ( EmitterInterface $ emitter = null ) { if ( $ this -> isStale ) { throw new \ BadMethodCallException ( "Unable to emit a stale response object" ) ; } if ( ! isset ( $ emitter ) ) { $ emitter = $ this -> createEmitter ( ) ; } if ( isset ( $ this -> status ) && ! $ this -> status instanceof GlobalResponseStatus ) { $ emitter -> emitStatus ( $ this ) ; } if ( isset ( $ this -> headers ) && ! $ this -> headers instanceof GlobalResponseHeaders ) { $ emitter -> emitHeaders ( $ this ) ; } if ( isset ( $ this -> body ) && $ this -> body -> getMetadata ( 'url' ) !== 'php://output' ) { $ emitter -> emitBody ( $ this ) ; } }
|
Emit the response
|
51,844
|
protected function copy ( ) { if ( $ this -> isStale ) { throw new \ BadMethodCallException ( "Unable to modify a stale response object" ) ; } $ response = clone $ this ; if ( $ this -> isStale === false ) { $ this -> status = new ResponseStatus ( $ this -> status ) ; $ this -> headers = new Headers ( $ this -> getHeaders ( ) ) ; $ this -> isStale = true ; } return $ response ; }
|
Clone the response . Turn stale if the response is bound to the global environment .
|
51,845
|
public function revive ( ) { if ( $ this -> isStale !== true ) { return $ this ; } $ response = clone $ this ; $ response -> status = $ this -> createGlobalResponseStatus ( $ this -> status ) -> withProtocolVersion ( $ this -> getProtocolVersion ( ) ) ; $ response -> headers = $ this -> createGlobalResponseHeaders ( $ this -> getHeaders ( ) ) ; if ( $ response -> body instanceof OutputBufferStream ) { $ response -> body -> useGlobally ( ) ; } $ response -> isStale = false ; return $ response ; }
|
Revive a stale response
|
51,846
|
protected function assertProtocolVersion ( $ version ) { if ( ! is_string ( $ version ) && ! is_numeric ( $ version ) ) { throw new \ InvalidArgumentException ( "HTTP version must be a string or float" ) ; } if ( $ version != '' && $ version !== "1.0" && $ version !== "1.1" && $ version !== "2" ) { throw new \ InvalidArgumentException ( "Invalid HTTP protocol version '$version'" ) ; } }
|
Set the HTTP protocol version .
|
51,847
|
public function getAttributes ( ) { $ attributes = [ ] ; foreach ( $ this -> attributes as $ name => $ attr ) { $ value = $ attr instanceof \ Closure || $ attr instanceof DerivedAttributeInterface ? $ attr ( $ this ) : $ attr ; $ attributes [ $ name ] = $ value ; } return $ attributes ; }
|
Retrieve attributes derived from the request .
|
51,848
|
protected function setBody ( StreamInterface $ body ) { if ( $ body instanceof OutputBufferStream && $ this -> isStale ( ) === false ) { $ body -> useGlobally ( ) ; } $ this -> body = $ body ; }
|
Set the body
|
51,849
|
protected function getStatusHeader ( $ protocolVersion , $ statusCode , $ reasonPhrase ) { if ( empty ( $ reasonPhrase ) ) { $ reasonPhrase = ( new ResponseStatus ( $ statusCode ) ) -> getReasonPhrase ( ) ; } return "HTTP/{$protocolVersion} {$statusCode} {$reasonPhrase}" ; }
|
Get the response header for a status code
|
51,850
|
public function emitHeaders ( ResponseInterface $ response ) { foreach ( $ response -> getHeaders ( ) as $ name => $ values ) { foreach ( array_values ( ( array ) $ values ) as $ i => $ value ) { $ this -> header ( "$name: $value" , $ i === 0 ) ; } } }
|
Emit the HTTP headers
|
51,851
|
public function emitBody ( ResponseInterface $ response ) { $ output = $ this -> createOutputStream ( ) ; if ( ! $ output ) { throw new \ RuntimeException ( "Failed to open output stream" ) ; } $ response -> getBody ( ) -> rewind ( ) ; $ handle = $ response -> getBody ( ) -> detach ( ) ; stream_copy_to_stream ( $ handle , $ output ) ; }
|
Emit the HTTP body
|
51,852
|
public function emit ( ResponseInterface $ response ) { if ( $ response instanceof \ Jasny \ HttpMessage \ Response ) { $ response -> emit ( $ this ) ; return ; } $ this -> emitStatus ( $ response ) ; $ this -> emitHeaders ( $ response ) ; $ this -> emitBody ( $ response ) ; }
|
Emit the full HTTP response
|
51,853
|
protected function determineProtocolVersion ( ) { $ params = $ this -> getServerParams ( ) ; if ( isset ( $ params [ 'SERVER_PROTOCOL' ] ) ) { list ( $ protocol , $ version ) = explode ( '/' , $ params [ 'SERVER_PROTOCOL' ] ) + [ 1 => null ] ; } return isset ( $ protocol ) && $ protocol === 'HTTP' ? $ version : "1.1" ; }
|
Determine the protocol versions based on the server params
|
51,854
|
public function run ( $ command ) { $ this -> command = escapeshellcmd ( $ command ) ; $ this -> process -> setCommandLine ( $ this -> command ) ; $ this -> process -> run ( ) ; $ this -> validateRun ( ) ; return $ this ; }
|
Run a command as a process .
|
51,855
|
protected function validateRun ( ) { $ status = $ this -> process -> getExitCode ( ) ; $ error = $ this -> process -> getErrorOutput ( ) ; if ( $ status !== 0 and $ error !== '' ) { throw new \ RuntimeException ( sprintf ( "The exit status code %s says something went wrong:\n stderr: %s\n stdout: %s\ncommand: %s." , $ status , $ error , $ this -> process -> getOutput ( ) , $ this -> command ) ) ; } }
|
Validate that a run process was successful .
|
51,856
|
public function createFromView ( $ view , $ filename , $ inline = false ) { $ this -> generateFilePaths ( ) ; $ this -> generatePdf ( $ view ) ; $ contentDisposition = $ inline ? 'inline' : 'attachment' ; return ( new BinaryFileResponse ( $ this -> pdfPath ) ) -> setContentDisposition ( $ contentDisposition , $ filename ) -> deleteFileAfterSend ( true ) ; }
|
Create a PDF from a view or string
|
51,857
|
public function saveFromView ( $ view , $ path ) { $ this -> generateFilePaths ( ) ; $ this -> generatePdf ( $ view ) ; rename ( $ this -> pdfPath , $ path ) ; }
|
Save a PDF file to the disk
|
51,858
|
protected function generateFilePaths ( ) { $ this -> validateStoragePath ( ) ; $ path = $ this -> storagePath . DIRECTORY_SEPARATOR ; $ this -> htmlPath = $ path . uniqid ( 'pdf-' , true ) . '.html' ; $ this -> pdfPath = $ path . uniqid ( 'html-' , true ) . '.pdf' ; }
|
Generate paths for the temporary files
|
51,859
|
protected function validateStoragePath ( ) { if ( is_null ( $ this -> storagePath ) ) { throw new Exception ( 'A storage path has not been set' ) ; } if ( ! is_dir ( $ this -> storagePath ) || ! is_writable ( $ this -> storagePath ) ) { throw new Exception ( 'The specified storage path is not writable' ) ; } }
|
Validate that the storage path is set and is writable
|
51,860
|
protected function generatePdf ( $ view ) { $ view = $ this -> viewToString ( $ view ) ; $ this -> saveHtml ( $ view ) ; $ command = implode ( ' ' , [ $ this -> getBinaryPath ( ) , implode ( ' ' , $ this -> commandLineOptions ) , $ this -> convertScript , $ this -> prefixHtmlPath ( $ this -> htmlPath ) , $ this -> pdfPath , implode ( ' ' , $ this -> commandLineArguments ) , ] ) ; $ process = new Process ( $ command , __DIR__ ) ; $ process -> setTimeout ( $ this -> timeout ) ; $ process -> run ( ) ; if ( $ errorOutput = $ process -> getErrorOutput ( ) ) { throw new RuntimeException ( 'PhantomJS: ' . $ errorOutput ) ; } @ unlink ( $ this -> htmlPath ) ; }
|
Run the script with PhantomJS
|
51,861
|
protected function insertBaseTag ( $ view ) { if ( is_null ( $ this -> baseUrl ) ) { return $ view ; } return str_replace ( '<head>' , '<head><base href="' . $ this -> baseUrl . '">' , $ view ) ; }
|
Insert a base tag after the head tag to allow relative references to assets
|
51,862
|
public function parse ( $ file ) { $ this -> file = $ file ; $ this -> validateSelf ( ) ; $ this -> process -> run ( "{$this->binary} {$this->file} -" ) ; return $ this ; }
|
Parse a PDF file .
|
51,863
|
protected function initConstants ( $ library_name ) { if ( ! isset ( $ this -> params [ $ library_name ] [ 'constants' ] ) ) return ; foreach ( ( array ) $ this -> params [ $ library_name ] [ 'constants' ] as $ constant_name => $ constant_value ) defined ( $ constant_name ) or define ( $ constant_name , $ constant_value ) ; }
|
Registering required constants
|
51,864
|
protected function createStepsFromConfig ( ) { $ config = $ this -> app [ 'config' ] ; $ stepClasses = $ config -> get ( 'setup_wizard.steps' ) ; if ( empty ( $ stepClasses ) ) throw new \ RuntimeException ( 'The setup wizard requires at least 1 step in configuration' ) ; $ steps = [ ] ; $ i = 0 ; foreach ( $ stepClasses as $ id => $ stepClass ) { $ s = new $ stepClass ( $ id ) ; $ steps [ $ id ] = $ s ; ++ $ i ; } return $ steps ; }
|
Get configuration and create the step objects
|
51,865
|
protected function nextStep ( Request $ request ) { $ currentStep = \ SetupWizard :: currentStep ( ) ; if ( ! $ currentStep -> apply ( $ request -> all ( ) ) ) { return view ( ) -> make ( 'setup_wizard::steps.default' , [ 'errors' => $ currentStep -> getMessageBag ( ) ] ) ; } try { $ nextStep = \ SetupWizard :: nextStep ( ) ; return redirect ( ) -> route ( 'setup_wizard.show' , [ 'slug' => $ nextStep -> getSlug ( ) ] ) ; } catch ( StepNotFoundException $ e ) { $ finalRouteName = config ( 'setup_wizard.routing.success_route' , '' ) ; if ( ! empty ( $ finalRouteName ) ) return redirect ( ) -> route ( $ finalRouteName ) ; $ finalRouteUrl = config ( 'setup_wizard.routing.success_url' , '' ) ; if ( ! empty ( $ finalRouteUrl ) ) return redirect ( ) -> to ( $ finalRouteUrl ) ; return redirect ( '/' ) ; } }
|
Apply current step and move on to next step
|
51,866
|
public function addLine ( Line $ line ) { $ this -> lines [ ] = $ line ; $ this -> end = $ line -> getIndex ( ) ; }
|
Add a new line to the hunk .
|
51,867
|
public static function createArray ( $ lines ) { $ op = Line :: UNCHANGED ; $ hunks = [ ] ; $ current = null ; foreach ( $ lines as $ line ) { switch ( $ line -> getType ( ) ) { case Line :: REMOVED : if ( $ op != Line :: REMOVED ) { $ current = new Hunk ( $ line , Hunk :: REMOVED , $ line -> getIndex ( ) ) ; } else { $ current -> addLine ( $ line ) ; } break ; case Line :: ADDED : switch ( $ op ) { case Line :: REMOVED : $ current -> setType ( Hunk :: REPLACED ) ; $ current -> addLine ( $ line ) ; break ; case Line :: ADDED : $ current -> addLine ( $ line ) ; break ; case Line :: UNCHANGED : $ current = new Hunk ( $ line , Hunk :: ADDED , $ line -> getIndex ( ) ) ; break ; } break ; case Line :: UNCHANGED : if ( $ current ) { $ hunks [ ] = $ current ; $ current = null ; } break ; } $ op = $ line -> getType ( ) ; } if ( $ current ) { $ hunks [ ] = $ current ; } return $ hunks ; }
|
Create an array of hunks out of an array of lines .
|
51,868
|
public function getRemovedLines ( ) { return array_values ( array_filter ( $ this -> lines , function ( Line $ line ) { return $ line -> getType ( ) == Line :: REMOVED ; } ) ) ; }
|
Get the removed lines .
|
51,869
|
public function getAddedLines ( ) { return array_values ( array_filter ( $ this -> lines , function ( Line $ line ) { return $ line -> getType ( ) == Line :: ADDED ; } ) ) ; }
|
Get the added lines .
|
51,870
|
public function isLineNumberAffected ( $ line ) { $ bleed = ( $ this -> type == self :: ADDED ? 1 : 0 ) ; return ( $ line >= $ this -> start && $ line <= $ this -> end + $ bleed ) ; }
|
Test whether the hunk is to be considered for a conflict resolution .
|
51,871
|
protected static function swap ( & $ a , & $ b , & $ flipped ) { $ c = $ a ; $ a = $ b ; $ b = $ c ; $ flipped = ! $ flipped ; }
|
Swaps two variables .
|
51,872
|
protected function mergeFile ( string $ file , string $ base , string $ remote , string $ local ) : string { file_put_contents ( $ file , $ base ) ; $ this -> git -> add ( $ file ) ; $ this -> git -> commit ( 'Add base.' ) ; if ( ! in_array ( 'original' , $ this -> git -> getBranches ( ) -> all ( ) ) ) { $ this -> git -> checkoutNewBranch ( 'original' ) ; } else { $ this -> git -> checkout ( 'original' ) ; $ this -> git -> rebase ( 'master' ) ; } file_put_contents ( $ file , $ remote ) ; $ this -> git -> add ( $ file ) ; $ this -> git -> commit ( 'Add remote.' ) ; $ this -> git -> checkout ( 'master' ) ; file_put_contents ( $ file , $ local ) ; $ this -> git -> add ( $ file ) ; $ this -> git -> commit ( 'Add local.' ) ; $ this -> git -> merge ( 'original' ) ; return file_get_contents ( $ file ) ; }
|
Merge three strings in a specified file .
|
51,873
|
protected function setup ( ) { if ( ! $ this -> dir ) { $ tempfile = tempnam ( sys_get_temp_dir ( ) , '' ) ; mkdir ( $ tempfile . '.git' ) ; if ( file_exists ( $ tempfile ) ) { unlink ( $ tempfile ) ; } $ this -> dir = $ tempfile . '.git' ; $ this -> git = $ this -> wrapper -> init ( $ this -> dir ) ; } if ( $ this -> git ) { $ this -> git -> config ( 'user.name' , 'GitMerge' ) ; $ this -> git -> config ( 'user.email' , 'gitmerge@php-merge.example.com' ) ; $ this -> git -> config ( 'merge.conflictStyle' , 'diff3' ) ; } }
|
Set up the git wrapper and the temporary directory .
|
51,874
|
protected function cleanup ( ) { if ( is_dir ( $ this -> dir ) ) { $ files = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ this -> dir , \ RecursiveDirectoryIterator :: SKIP_DOTS ) , \ RecursiveIteratorIterator :: CHILD_FIRST ) ; foreach ( $ files as $ fileinfo ) { if ( $ fileinfo -> isDir ( ) ) { rmdir ( $ fileinfo -> getRealPath ( ) ) ; } else { unlink ( $ fileinfo -> getRealPath ( ) ) ; } } rmdir ( $ this -> dir ) ; unset ( $ this -> git ) ; } }
|
Clean the temporary directory used for merging .
|
51,875
|
public static function removeStopWords ( $ string , $ asString = false ) { $ delimiters = preg_quote ( static :: $ delimiters , '/' ) ; $ stopWords = explode ( ',' , static :: $ stopWords ) ; $ result = array_map ( function ( $ token ) { return $ token ; } , array_filter ( array_map ( function ( $ t ) { return mb_strtolower ( $ t , 'UTF-8' ) ; } , preg_split ( "/[\\s$delimiters]+/" , $ string , - 1 , PREG_SPLIT_NO_EMPTY ) ) , function ( $ word ) use ( $ stopWords ) { return ! in_array ( $ word , $ stopWords ) ; } ) ) ; if ( $ asString ) { return implode ( ' ' , $ result ) ; } return $ result ; }
|
Remove stop words
|
51,876
|
public static function removePunctuationSymbols ( $ words , $ glue = ' ' ) { if ( is_array ( $ words ) ) { $ words = implode ( $ glue , $ words ) ; } return trim ( str_replace ( static :: $ punctuationSymbols , '' , $ words ) ) ; }
|
Remove punctuation symbols from string
|
51,877
|
protected static function simpleMerge ( string $ base , string $ remote , string $ local ) { if ( $ base == $ remote ) { return $ local ; } if ( $ base == $ local ) { return $ remote ; } if ( $ remote == $ local ) { return $ remote ; } return null ; }
|
Merge obvious cases when only one text changes ..
|
51,878
|
private function configure ( array $ config = [ ] ) : void { foreach ( $ config as $ param => $ value ) { $ property = $ this -> toCamelCase ( $ param ) ; if ( property_exists ( self :: class , $ property ) ) { $ this -> $ property = $ value ; } } }
|
Overrides default configuration settings .
|
51,879
|
public function clearImportDirectory ( ) : void { $ tmp_files = glob ( $ this -> config -> getImportDir ( ) . DIRECTORY_SEPARATOR . '*.*' ) ; if ( is_array ( $ tmp_files ) ) { foreach ( $ tmp_files as $ v ) { unlink ( $ v ) ; } } }
|
Delete all files from tmp directory .
|
51,880
|
public function nest ( ) { $ parentColumn = $ this -> parentColumn ; if ( ! $ parentColumn ) { return $ this ; } $ this -> items = $ this -> getDictionary ( ) ; $ keysToDelete = [ ] ; $ collection = $ this -> each ( function ( $ item ) { if ( ! $ item -> { $ this -> childrenName } ) { $ item -> { $ this -> childrenName } = app ( ) -> make ( 'Illuminate\Support\Collection' ) ; } } ) ; if ( $ this -> removeItemsWithMissingAncestor ) { $ collection = $ this -> reject ( function ( $ item ) use ( $ parentColumn ) { if ( $ item -> $ parentColumn ) { $ missingAncestor = $ this -> anAncestorIsMissing ( $ item ) ; return $ missingAncestor ; } } ) ; } foreach ( $ collection -> items as $ key => $ item ) { if ( $ item -> $ parentColumn && isset ( $ collection [ $ item -> $ parentColumn ] ) ) { $ collection [ $ item -> $ parentColumn ] -> { $ this -> childrenName } -> push ( $ item ) ; $ keysToDelete [ ] = $ item -> id ; } } $ this -> items = array_values ( Arr :: except ( $ collection -> items , $ keysToDelete ) ) ; return $ this ; }
|
Nest items .
|
51,881
|
public function listsFlattenedQualified ( $ column = 'title' , BaseCollection $ collection = null , $ level = 0 , array & $ flattened = [ ] , $ indentChars = null ) { return $ this -> listsFlattened ( $ column , $ collection , $ level , $ flattened , $ indentChars , true ) ; }
|
Returns a fully qualified version of listsFlattened .
|
51,882
|
public function anAncestorIsMissing ( $ item ) { $ parentColumn = $ this -> parentColumn ; if ( ! $ item -> $ parentColumn ) { return false ; } if ( ! $ this -> has ( $ item -> $ parentColumn ) ) { return true ; } $ parent = $ this [ $ item -> $ parentColumn ] ; return $ this -> anAncestorIsMissing ( $ parent ) ; }
|
Check if an ancestor is missing .
|
51,883
|
public function serialize ( $ value ) { $ this -> reset ( ) ; return $ this -> serializationStrategy -> serialize ( $ this -> serializeData ( $ value ) ) ; }
|
Serialize the value in JSON .
|
51,884
|
protected function serializeData ( $ value ) { $ this -> guardForUnsupportedValues ( $ value ) ; if ( $ this -> isInstanceOf ( $ value , 'SplFixedArray' ) ) { return SplFixedArraySerializer :: serialize ( $ this , $ value ) ; } if ( \ is_object ( $ value ) ) { return $ this -> serializeObject ( $ value ) ; } $ type = ( \ gettype ( $ value ) && $ value !== null ) ? \ gettype ( $ value ) : 'string' ; $ func = $ this -> serializationMap [ $ type ] ; return $ this -> $ func ( $ value ) ; }
|
Parse the data to be json encoded .
|
51,885
|
private function isInstanceOf ( $ value , $ classFQN ) { return is_object ( $ value ) && ( strtolower ( get_class ( $ value ) ) === strtolower ( $ classFQN ) || \ is_subclass_of ( $ value , $ classFQN , true ) ) ; }
|
Check if a class is instance or extends from the expected instance .
|
51,886
|
public function unserialize ( $ value ) { if ( \ is_array ( $ value ) && isset ( $ value [ self :: SCALAR_TYPE ] ) ) { return $ this -> unserializeData ( $ value ) ; } $ this -> reset ( ) ; return $ this -> unserializeData ( $ this -> serializationStrategy -> unserialize ( $ value ) ) ; }
|
Unserialize the value from string .
|
51,887
|
protected function unserializeData ( $ value ) { if ( $ value === null || ! is_array ( $ value ) ) { return $ value ; } if ( isset ( $ value [ self :: MAP_TYPE ] ) && ! isset ( $ value [ self :: CLASS_IDENTIFIER_KEY ] ) ) { $ value = $ value [ self :: SCALAR_VALUE ] ; return $ this -> unserializeData ( $ value ) ; } if ( isset ( $ value [ self :: SCALAR_TYPE ] ) ) { return $ this -> getScalarValue ( $ value ) ; } if ( isset ( $ value [ self :: CLASS_PARENT_KEY ] ) && 0 === strcmp ( $ value [ self :: CLASS_PARENT_KEY ] , 'SplFixedArray' ) ) { return SplFixedArraySerializer :: unserialize ( $ this , $ value [ self :: CLASS_IDENTIFIER_KEY ] , $ value ) ; } if ( isset ( $ value [ self :: CLASS_IDENTIFIER_KEY ] ) ) { return $ this -> unserializeObject ( $ value ) ; } return \ array_map ( [ $ this , __FUNCTION__ ] , $ value ) ; }
|
Parse the json decode to convert to objects again .
|
51,888
|
protected function unserializeObject ( array $ value ) { $ className = $ value [ self :: CLASS_IDENTIFIER_KEY ] ; unset ( $ value [ self :: CLASS_IDENTIFIER_KEY ] ) ; if ( isset ( $ value [ self :: MAP_TYPE ] ) ) { unset ( $ value [ self :: MAP_TYPE ] ) ; unset ( $ value [ self :: SCALAR_VALUE ] ) ; } if ( $ className [ 0 ] === '@' ) { return self :: $ objectMapping [ substr ( $ className , 1 ) ] ; } if ( ! class_exists ( $ className ) ) { throw new SerializerException ( 'Unable to find class ' . $ className ) ; } return ( null === ( $ obj = $ this -> unserializeDateTimeFamilyObject ( $ value , $ className ) ) ) ? $ this -> unserializeUserDefinedObject ( $ value , $ className ) : $ obj ; }
|
Convert the serialized array into an object .
|
51,889
|
protected function getObjectProperties ( ReflectionClass $ ref , $ value ) { $ props = [ ] ; foreach ( $ ref -> getProperties ( ) as $ prop ) { $ props [ ] = $ prop -> getName ( ) ; } return \ array_unique ( \ array_merge ( $ props , \ array_keys ( \ get_object_vars ( $ value ) ) ) ) ; }
|
Return the list of properties to be serialized .
|
51,890
|
protected function extractObjectData ( $ value , ReflectionClass $ rc , array $ properties ) { $ data = [ ] ; $ this -> extractCurrentObjectProperties ( $ value , $ rc , $ properties , $ data ) ; $ this -> extractAllInhertitedProperties ( $ value , $ rc , $ data ) ; return $ data ; }
|
Extract the object data .
|
51,891
|
public function getImapStream ( $ forceConnection = true ) { static $ imapStream ; if ( $ forceConnection ) { if ( $ imapStream && ( ! is_resource ( $ imapStream ) || ! imap_ping ( $ imapStream ) ) ) { $ this -> disconnect ( ) ; $ imapStream = null ; } if ( ! $ imapStream ) { $ imapStream = $ this -> initImapStream ( ) ; } } return $ imapStream ; }
|
Get IMAP mailbox connection stream
|
51,892
|
public function getListingFolders ( ) { $ folders = imap_list ( $ this -> getImapStream ( ) , $ this -> imapPath , "*" ) ; foreach ( $ folders as $ key => $ folder ) { $ folder = str_replace ( $ this -> imapPath , "" , imap_utf7_decode ( $ folder ) ) ; $ folders [ $ key ] = $ folder ; } return $ folders ; }
|
Gets listing the folders
|
51,893
|
public function setFlag ( array $ mailsIds , $ flag ) { return imap_setflag_full ( $ this -> getImapStream ( ) , implode ( ',' , $ mailsIds ) , $ flag , ST_UID ) ; }
|
Causes a store to add the specified flag to the flags set for the mails in the specified sequence .
|
51,894
|
public function clearFlag ( array $ mailsIds , $ flag ) { return imap_clearflag_full ( $ this -> getImapStream ( ) , implode ( ',' , $ mailsIds ) , $ flag , ST_UID ) ; }
|
Cause a store to delete the specified flag to the flags set for the mails in the specified sequence .
|
51,895
|
public function getMailsInfo ( array $ mailsIds ) { $ mails = imap_fetch_overview ( $ this -> getImapStream ( ) , implode ( ',' , $ mailsIds ) , FT_UID ) ; if ( is_array ( $ mails ) && count ( $ mails ) ) { foreach ( $ mails as & $ mail ) { if ( isset ( $ mail -> subject ) ) { $ mail -> subject = $ this -> decodeMimeStr ( $ mail -> subject , $ this -> serverEncoding ) ; } if ( isset ( $ mail -> from ) ) { $ mail -> from = $ this -> decodeMimeStr ( $ mail -> from , $ this -> serverEncoding ) ; } if ( isset ( $ mail -> to ) ) { $ mail -> to = $ this -> decodeMimeStr ( $ mail -> to , $ this -> serverEncoding ) ; } } } return $ mails ; }
|
Fetch mail headers for listed mails ids
|
51,896
|
public function sortMails ( $ criteria = SORTARRIVAL , $ reverse = true ) { return imap_sort ( $ this -> getImapStream ( ) , $ criteria , $ reverse , SE_UID ) ; }
|
Gets mails ids sorted by some criteria
|
51,897
|
protected function convertStringEncoding ( $ string , $ fromEncoding , $ toEncoding ) { $ convertedString = null ; if ( $ string && $ fromEncoding != $ toEncoding ) { $ convertedString = @ iconv ( $ fromEncoding , $ toEncoding . '//IGNORE' , $ string ) ; if ( ! $ convertedString && extension_loaded ( 'mbstring' ) ) { $ convertedString = @ mb_convert_encoding ( $ string , $ toEncoding , $ fromEncoding ) ; } } return $ convertedString ? : $ string ; }
|
Converts a string from one encoding to another .
|
51,898
|
public static function getDateTime ( $ date ) { $ _date = time ( ) ; if ( isset ( $ date ) && self :: isValidDate ( $ date ) ) { $ _date = strtotime ( preg_replace ( '/\(.*?\)/' , '' , $ date ) ) ; } return date ( 'Y-m-d H:i:s' , $ _date ) ; }
|
Get date time
|
51,899
|
public static function isValidDate ( $ date , $ format = 'Y-m-d H:i:s' ) { $ d = DateTime :: createFromFormat ( $ format , $ date ) ; return $ d && $ d -> format ( $ format ) === $ date ; }
|
Check valid date time format
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.