idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
21,900
public static function buildConditionalArray ( array $ config , string $ action = "-" ) { if ( $ action == "" ) { $ action = substr ( request ( ) -> route ( ) -> getName ( ) , stripos ( request ( ) -> route ( ) -> getName ( ) , "::" ) + 2 ) ; } $ condiciones = [ ] ; $ validadores = [ ] ; $ tabla = $ config [ 'tabla' ] ; foreach ( $ config [ 'campos' ] as $ campo => $ datos ) { if ( \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: inside_array ( $ datos , "hide" , $ action ) === false ) { if ( isset ( $ datos [ 'conditional' ] ) ) { if ( is_array ( $ datos [ 'conditional' ] ) ) { $ validadores [ "{$tabla}_{$campo}" ] = [ ] ; foreach ( $ datos [ 'conditional' ] as $ conCampo => $ conValor ) { if ( ! isset ( $ condiciones [ "{$tabla}_{$conCampo}" ] ) ) { $ condiciones [ "{$tabla}_{$conCampo}" ] = [ ] ; } $ condiciones [ "{$tabla}_{$conCampo}" ] [ ] = "{$tabla}_{$campo}" ; $ validadores [ "{$tabla}_{$campo}" ] [ "{$tabla}_{$conCampo}" ] = $ conValor ; } } } } } return [ $ condiciones , $ validadores ] ; }
Build the array for conditional fields using a configuration array
21,901
public function useKeyAsValue ( $ key , $ normalize = false ) { if ( true !== $ normalize && ! $ this -> isValidNodeName ( $ key ) ) { throw new \ InvalidArgumentException ( sprintf ( '%s is an invalid node name' , $ key ) ) ; } $ this -> nodeValueKey = $ normalize ? $ this -> normalizer -> normalize ( $ key ) : $ key ; }
Sets the key that indicates a node value .
21,902
public function useKeyAsIndex ( $ key , $ normalize = false ) { if ( null === $ key ) { $ this -> indexKey = null ; return ; } if ( true !== $ normalize && ! $ this -> isValidNodeName ( $ key ) ) { throw new \ InvalidArgumentException ( sprintf ( '%s is an invalid node name' , $ key ) ) ; } $ this -> indexKey = $ normalize ? $ this -> normalizer -> normalize ( $ key ) : $ key ; }
Sets the index key used as key - > node identifier .
21,903
public function useKeyAsIndexAttribute ( $ key , $ normalize = false ) { if ( null === $ key ) { $ this -> indexAttrKey = null ; return ; } if ( true !== $ normalize && ! $ this -> isValidNodeName ( $ key ) ) { throw new \ InvalidArgumentException ( sprintf ( '%s is an invalid attribute name' , $ key ) ) ; } $ this -> indexAttrKey = $ normalize ? $ this -> normalizer -> normalize ( $ key ) : $ key ; }
Sets the index key used in attributes .
21,904
public function dump ( $ data , $ rootName = 'root' ) { $ dom = $ this -> writeToDom ( $ data , $ rootName ) ; return $ dom -> saveXML ( ) ; }
Dump the input data to a xml string .
21,905
public function writeToDom ( $ data , $ rootName = 'root' ) { $ this -> buildXML ( $ dom = new DOMDocument ( '1.0' , $ this -> getEncoding ( ) ) , $ root = $ dom -> createElement ( $ rootName ) , $ data ) ; $ dom -> appendChild ( $ root ) ; return $ dom ; }
Write the input data to a DOMDocument
21,906
private function appendDOMNode ( \ DOMDocument $ dom , $ node , $ name , $ value = null , $ hasAttributes = false ) { $ element = $ dom -> createElement ( $ name ) ; if ( $ hasAttributes && $ this -> nodeValueKey === $ name ) { $ this -> setElementValue ( $ dom , $ node , $ value ) ; return ; } $ this -> setElementValue ( $ dom , $ element , $ value ) ; $ node -> appendChild ( $ element ) ; }
Appends a dom node to the DOM .
21,907
private function getAttributeName ( $ key ) { if ( 0 === strpos ( $ key , '@' ) && $ this -> isValidNodeName ( $ attrName = substr ( $ key , 1 ) ) ) { return $ attrName ; } return null ; }
Extracts the raw attribute indicator .
21,908
private function createText ( \ DOMDocument $ dom , \ DOMNode $ node , $ value ) { $ text = $ dom -> createTextNode ( $ value ) ; $ node -> appendChild ( $ text ) ; }
Creates a text node on a DOMNode .
21,909
private function createCDATASection ( \ DOMDocument $ dom , \ DOMNode $ node , $ value ) { $ cdata = $ dom -> createCDATASection ( $ value ) ; $ node -> appendChild ( $ cdata ) ; }
Creates a CDATA section node on a DOMNode .
21,910
private function createTextNodeWithTypeAttribute ( \ DOMDocument $ dom , \ DOMNode $ node , $ value , $ type = 'int' ) { $ text = $ dom -> createTextNode ( $ value ) ; $ attr = $ dom -> createAttribute ( 'type' ) ; $ attr -> value = $ type ; $ node -> appendChild ( $ text ) ; $ node -> appendChild ( $ attr ) ; }
Add a value and an associated type attribute to a DOMNode .
21,911
public static function invalidImplementation ( string $ className , \ Exception $ previous = null ) : self { return new self ( "invalid class name: {$className}" , self :: INVALID_IMPLEMENTATION , $ previous ) ; }
This method creates an exception if the given class name of the cache implementation to use does not implement \ Gustav \ Cache \ ACacheManager .
21,912
public static function badFileName ( string $ fileName , \ Exception $ previous = null ) : self { return new self ( "bad file name: {$fileName}" , self :: BAD_FILE_NAME , $ previous ) ; }
This method creates an exception if the given file - name contains invalid symbols .
21,913
public static function fileUnreadable ( $ fileName , \ Exception $ previous = null ) : self { return new self ( "cannot read file: {$fileName}" , self :: FILE_UNREADABLE , $ previous ) ; }
This method creates an exception if reading of this file failed .
21,914
public function byUsername ( $ username , $ with = [ ] ) { $ user = $ this -> model -> whereUsername ( $ username ) ; foreach ( $ with as $ relation ) $ user = $ user -> with ( $ relation ) ; return $ user -> first ( ) ; }
get a single user by its username
21,915
private function getWhoopsRunner ( ) { $ whoops = new Whoops ( ) ; $ whoops -> allowQuit ( false ) ; $ whoops -> writeToOutput ( false ) ; return $ whoops ; }
Get Whoops Runner .
21,916
public function toArray ( ) { $ hasChainedException = PHP_VERSION_ID >= 50300 ; $ exception = $ this -> exception ; do { $ whoops = $ this -> getWhoopsRunner ( ) ; $ whoops -> pushHandler ( new WhoopsHandler ( $ this -> config ) ) -> register ( ) ; $ exceptions [ ] = json_decode ( $ whoops -> handleException ( $ exception ) , true ) ; } while ( $ hasChainedException && $ exception = $ exception -> getPrevious ( ) ) ; $ data = [ 'title' => get_class ( $ this -> exception ) , 'message' => $ this -> exception -> getMessage ( ) , 'exception' => [ 'file' => $ this -> exception -> getFile ( ) , 'line' => $ this -> exception -> getLine ( ) , 'code' => $ this -> exception -> getCode ( ) , ] , 'platform' => 'php' , 'environment' => $ this -> config -> getEnvironment ( ) , 'events' => [ 'exceptions' => $ exceptions , 'meta_data' => $ this -> config -> getMetaData ( ) , 'user' => $ this -> config -> getUser ( ) , 'sdk' => $ this -> config -> getSdk ( ) , ] , ] ; if ( empty ( $ data [ 'level' ] ) ) { if ( method_exists ( $ exception , 'getSeverity' ) ) { $ data [ 'level' ] = $ this -> translateSeverity ( $ exception -> getSeverity ( ) ) ; } else { $ data [ 'level' ] = self :: ERROR ; } } return $ data ; }
Format exception as array .
21,917
public static function assert ( $ assertion , string $ message = '' ) { self :: $ count += 1 ; assert ( $ assertion , new AssertionError ( $ message ) ) ; }
Test if the assertion is true
21,918
public static function assertSame ( $ expected , $ actual , string $ message = '' ) { self :: $ count += 1 ; if ( $ expected === $ actual ) { return ; } if ( ! $ message ) { $ message = sprintf ( 'Failed asserting that %s matches %s' , var_export ( $ actual , true ) , var_export ( $ expected , true ) ) ; } throw new AssertionError ( $ message ) ; }
Test if the actual value matches the expected
21,919
public static function assertTrue ( $ actual , string $ message = '' ) { self :: $ count += 1 ; if ( ( bool ) $ actual ) { return ; } if ( ! $ message ) { $ message = sprintf ( 'Failed asserting that %s is truthy' , var_export ( $ actual , true ) ) ; } throw new AssertionError ( $ message ) ; }
Test if the value is truthy
21,920
public static function assertFalse ( $ actual , string $ message = '' ) { self :: $ count += 1 ; if ( false === ( bool ) $ actual ) { return ; } if ( ! $ message ) { $ message = sprintf ( 'Failed asserting that %s is falsy' , var_export ( $ actual , true ) ) ; } throw new AssertionError ( $ message ) ; }
Test if the value is falsy
21,921
public static function throws ( callable $ callback , string $ expectedException = '' , string $ message = '' ) { self :: $ count += 1 ; $ exception = null ; try { $ callback ( ) ; } catch ( \ Error $ exception ) { } catch ( \ Exception $ exception ) { } if ( $ exception === null ) { throw new AssertionError ( $ message ? : 'No exception thrown' ) ; } elseif ( $ expectedException && ! is_a ( $ exception , $ expectedException ) ) { throw new AssertionError ( $ message ? : sprintf ( 'Expected %s got %s' , $ expectedException , get_class ( $ exception ) ) ) ; } }
Test if the callback throws an exception
21,922
public static function assertInstanceOf ( string $ className , $ actual , string $ message = '' ) { self :: $ count += 1 ; if ( $ actual instanceof $ className ) { return ; } if ( ! $ message ) { $ message = sprintf ( 'Failed asserting that %s is an instance of %s' , static :: getType ( $ actual ) , $ className ) ; } throw new AssertionError ( $ message ) ; }
Test if the given object is an instance of the given class
21,923
public static function assertTypeOf ( string $ type , $ actual , string $ message = '' ) { self :: $ count += 1 ; switch ( strtolower ( $ type ) ) { case 'array' : if ( is_array ( $ actual ) ) { return ; } break ; case 'resource' : if ( is_resource ( $ actual ) ) { return ; } break ; case 'object' : if ( is_object ( $ actual ) ) { return ; } break ; case 'int' : case 'integer' : case 'long' : if ( is_int ( $ actual ) ) { return ; } break ; case 'double' : case 'float' : if ( is_float ( $ actual ) ) { return ; } break ; case 'numeric' : if ( is_numeric ( $ actual ) ) { return ; } break ; case 'bool' : case 'boolean' : if ( is_bool ( $ actual ) ) { return ; } break ; case 'callable' : if ( is_callable ( $ actual ) ) { return ; } break ; case 'null' : if ( is_null ( $ actual ) ) { return ; } break ; case 'string' : if ( is_string ( $ actual ) ) { return ; } break ; default : throw new AssertionLogicError ( sprintf ( 'No assertion defined for type %s' , $ type ) ) ; } if ( ! $ message ) { $ message = sprintf ( 'Failed asserting that %s is of type %s' , static :: getType ( $ actual ) , $ type ) ; } throw new AssertionError ( $ message ) ; }
Test if the given value is an instance of the given type
21,924
public function loadService ( $ service_name ) { $ class = 'BlenderDeluxe\Khipu\KhipuService\KhipuService' . $ service_name ; if ( class_exists ( $ class ) ) { $ services_name = self :: getAllServicesName ( ) ; if ( $ services_name [ $ service_name ] ) { if ( $ this -> receiver_id && $ this -> secret ) { $ service = new $ class ( $ this -> receiver_id , $ this -> secret ) ; } else { throw new Exception ( "Is necessary to authenticate to use the service \"$service_name\"" ) ; } } else { $ service = new $ class ( ) ; } $ service -> setAgent ( $ this -> agent ) ; return $ service ; } throw new Exception ( "The service \"$service_name\" does not exist" ) ; }
Carga el servicio y retorna el objeto en caso de no existir el servicio se invoca un excepcion .
21,925
public static function getUrlService ( $ service_name ) { $ url_khipu = 'https://khipu.com/api/' . self :: VERSION_KHIPU_SERVICE . '/' ; $ services_name = self :: getAllServicesName ( ) ; if ( array_key_exists ( $ service_name , $ services_name ) ) { $ str = $ service_name ; $ str [ 0 ] = strtolower ( $ str [ 0 ] ) ; return $ url_khipu . ( string ) $ str ; } return FALSE ; }
Funcion que retorna las URL de los servicios de Khipu .
21,926
public static function getAllServicesName ( ) { return array ( 'CreateEmail' => TRUE , 'CreatePaymentPage' => TRUE , 'CreatePaymentURL' => TRUE , 'VerifyPaymentNotification' => FALSE , 'ReceiverStatus' => TRUE , 'SetBillExpired' => TRUE , 'SetPaidByReceiver' => TRUE , 'SetRejectedByPayer' => TRUE , 'PaymentStatus' => TRUE , 'UpdatePaymentNotificationUrl' => TRUE , 'ReceiverBanks' => TRUE , 'GetPaymentNotification' => TRUE , ) ; }
Funcion que retorna los nombre de servicios que existen y si se requiere identificarse .
21,927
protected function _normalizeStringable ( $ stringable ) { if ( ! is_scalar ( $ stringable ) && ! ( $ stringable instanceof Stringable ) ) { throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Not a stringable value' ) , null , null , $ stringable ) ; } return $ stringable ; }
Normalizes a stringable value .
21,928
public static function setConnectionConfig ( ) { if ( ! static :: $ _dbConnectionConfig ) { $ config = static :: _getDbConnectionConfig ( ) ; if ( ! is_array ( $ config ) || empty ( $ config ) ) throw new \ ErrorException ( 'Not set configuration of database in file ' . APPPATH . 'config/database.php. ' . 'See example ' . __DIR__ . 'database.php.config_example' ) ; static :: _setDbConnectionConfig ( $ config ) ; static :: $ _dbConnectionConfig = $ config ; } }
Set connection settings
21,929
protected static function _setDbConnectionConfig ( array $ config ) { $ app = \ Slim \ Slim :: getInstance ( ) ; $ cfg = Config :: instance ( ) ; $ cfg -> set_connections ( $ config ) ; $ cfg -> set_default_connection ( $ app -> config ( 'mode' ) ) ; }
Sets database configs
21,930
public function toArray ( ) { if ( $ this -> timer !== null ) { $ this -> values [ 'elapsed-time' ] = $ this -> timer -> getElapsedTime ( true ) ; } return $ this -> values ; }
Return the results as an array
21,931
public function postProcess ( ProcessEvent $ e ) { $ appEvent = clone $ e -> getWorker ( ) -> getEvent ( ) ; $ appEvent -> setTarget ( $ appEvent -> getApplication ( ) ) ; $ appEvents = $ appEvent -> getApplication ( ) -> getEventManager ( ) ; $ appResponse = clone $ appEvent -> getResponse ( ) ; $ appEvent -> setResponse ( $ appResponse ) ; $ appEvent -> setResult ( $ e -> getResult ( ) ) ; $ appEvents -> trigger ( MvcEvent :: EVENT_RENDER , $ appEvent ) ; $ e -> setResult ( $ appEvent -> getResponse ( ) -> getContent ( ) ) ; if ( Console :: isConsole ( ) && is_string ( $ e -> getResult ( ) ) ) { echo $ e -> getResult ( ) ; } }
Render the processor result .
21,932
public function createSession ( ) { if ( ! $ this -> getUser ( ) ) { throw new \ Exceptions \ InternalException ( 'Will not create session where no user is set' ) ; } $ this -> destroySessions ( ) ; $ app = App :: getInstance ( ) ; $ sql = $ app [ 'safesql' ] -> query ( "INSERT INTO `login` ( session_id, session_name, ip, browser, user, logged_in, deleted ) VALUES ( '%s', '%s', '%s', '%s', '%s', 1, 0 )" , array ( $ app [ 'env' ] [ 'session' ] -> getId ( ) , SESSION_NAME , $ app [ 'env' ] [ 'RemoteIP' ] , $ app [ 'env' ] [ 'RemoteUA' ] , $ this -> getUser ( ) , ) ) ; $ app [ 'db' ] -> query ( $ sql ) ; $ app [ 'env' ] [ 'session' ] [ 'uname' ] = $ this -> getUser ( ) ; $ app [ 'env' ] [ 'session' ] [ 'loggedin' ] = true ; }
Create session for user
21,933
protected function _send ( ) { $ message = $ this -> build_message ( ) ; $ return_path = ( $ this -> config [ 'return_path' ] !== false ) ? $ this -> config [ 'return_path' ] : $ this -> config [ 'from' ] [ 'email' ] ; $ handle = @ popen ( $ this -> config [ 'sendmail_path' ] . " -oi -f " . $ return_path . " -t" , 'w' ) ; if ( ! is_resource ( $ handle ) ) { throw new \ SendmailConnectionException ( 'Could not open a sendmail connection at: ' . $ this -> config [ 'sendmail_path' ] ) ; } fputs ( $ handle , $ message [ 'header' ] ) ; fputs ( $ handle , $ message [ 'body' ] ) ; if ( pclose ( $ handle ) === - 1 ) { throw new \ SendmailFailedException ( 'Failed sending email through sendmail.' ) ; } return true ; }
Initalted all needed for Sendmail mailing .
21,934
public function addQueryData ( $ parms ) { $ this -> setUrl ( Util :: addQueryData ( $ this -> getUrl ( ) , $ parms ) ) ; return $ this ; }
Append a query string to the current URL .
21,935
public function setCredentials ( $ user , $ password , $ type = CURLAUTH_ANYSAFE ) { $ this -> addCurlOption ( CURLOPT_HTTPAUTH , $ type ) ; $ this -> addCurlOption ( CURLOPT_USERPWD , "{$user}:{$password}" ) ; return $ this ; }
Set credentials for authenticating to remote host .
21,936
public function setX509Credentials ( $ cert , $ key , $ keypass , $ type = 'PEM' ) { $ this -> addCurlOption ( CURLOPT_SSLCERTTYPE , $ type ) ; $ this -> addCurlOption ( CURLOPT_SSLCERT , $ cert ) ; $ this -> addCurlOption ( CURLOPT_SSLKEY , $ key ) ; $ this -> addCurlOption ( CURLOPT_SSLKEYPASSWD , $ keypass ) ; return $ this ; }
Set x509 credentials for authenticating to remote host .
21,937
public function setCookieJar ( $ file ) { if ( null !== $ file ) { $ this -> addCurlOption ( CURLOPT_COOKIEFILE , $ file ) ; $ this -> addCurlOption ( CURLOPT_COOKIEJAR , $ file ) ; } return $ this ; }
Read and store cookies in the provided file .
21,938
public function getResponseHeader ( $ name ) { $ this -> throwIfNotSubmitted ( ) ; if ( isset ( $ this -> responseHeaders [ $ name ] ) ) { return $ this -> responseHeaders [ $ name ] ; } else { return null ; } }
Get a particular HTTP response header sent by the server .
21,939
public function submit ( $ failIfNot200 = null ) { if ( $ this -> wasSubmitted ( ) ) { throw new Exception ( "Request be reused!" ) ; } $ ch = $ this -> createCurlRequest ( ) ; $ raw = curl_exec ( $ ch ) ; $ this -> processCurlResponse ( $ ch , curl_errno ( $ ch ) , curl_error ( $ ch ) , $ raw ) ; $ this -> validateResponse ( $ failIfNot200 ) ; return $ this ; }
Submit this request .
21,940
protected function createCurlRequest ( ) { $ curlOpts = Util :: mergeCurlOptions ( self :: $ defaultCurlOpts , $ this -> getCurlOptions ( ) ) ; $ curlOpts [ CURLOPT_RETURNTRANSFER ] = true ; $ curlOpts [ CURLOPT_HEADER ] = true ; $ curlOpts [ CURLOPT_FAILONERROR ] = false ; if ( defined ( 'CURLINFO_HEADER_OUT' ) ) { $ curlOpts [ CURLINFO_HEADER_OUT ] = true ; } if ( defined ( 'CURLOPT_TIMEOUT_MS' ) || defined ( 'CURLOPT_CONNECTTIMEOUT_MS' ) ) { if ( ( isset ( $ curlOpts [ CURLOPT_TIMEOUT_MS ] ) && $ curlOpts [ CURLOPT_TIMEOUT_MS ] < 1000 ) || ( isset ( $ curlOpts [ CURLOPT_CONNECTTIMEOUT_MS ] ) && $ curlOpts [ CURLOPT_CONNECTTIMEOUT_MS ] < 1000 ) ) { $ curlOpts [ CURLOPT_NOSIGNAL ] = true ; } } $ curlOpts [ CURLOPT_URL ] = $ this -> url ; if ( self :: METHOD_POST == $ this -> getMethod ( ) ) { $ curlOpts [ CURLOPT_POST ] = true ; } else { $ curlOpts [ CURLOPT_CUSTOMREQUEST ] = $ this -> getMethod ( ) ; } $ curlOpts [ CURLOPT_USERAGENT ] = $ this -> getUserAgent ( ) ; if ( $ this -> getPostBody ( ) ) { $ pBody = $ this -> getPostBody ( ) ; if ( ! is_array ( $ pBody ) ) { $ len = mb_strlen ( $ pBody , 'latin1' ) ; $ this -> addHeader ( "Content-Length: {$len}" ) ; } $ curlOpts [ CURLOPT_POSTFIELDS ] = $ pBody ; } if ( $ this -> getHeaders ( ) ) { $ curlOpts [ CURLOPT_HTTPHEADER ] = $ this -> getHeaders ( ) ; } $ this -> setCurlOptions ( $ curlOpts ) ; $ ch = curl_init ( ) ; curl_setopt_array ( $ ch , $ curlOpts ) ; return $ ch ; }
Prepare a cURL handle for this request .
21,941
protected function processCurlResponse ( $ ch , $ errCode , $ errMsg , $ rawResp ) { $ this -> responseCurlErr = $ errCode ; $ this -> responseCurlErrMessage = $ errMsg ; if ( CURLE_OK == $ errCode ) { $ info = curl_getinfo ( $ ch ) ; $ hdrSize = $ info [ 'header_size' ] ; $ respCode = ( int ) $ info [ 'http_code' ] ; $ rawHeaders = mb_substr ( $ rawResp , 0 , $ hdrSize , 'latin1' ) ; $ respBody = mb_substr ( $ rawResp , $ hdrSize , mb_strlen ( $ rawResp , 'latin1' ) , 'latin1' ) ; if ( $ info [ 'redirect_count' ] > 0 ) { $ headerChunks = explode ( "\r\n\r\n" , $ rawHeaders ) ; $ rawHeaders = $ headerChunks [ $ info [ 'redirect_count' ] ] ; } $ respHeaderParts = explode ( "\r\n" , $ rawHeaders ) ; $ respHeaders = array ( ) ; foreach ( $ respHeaderParts as $ header ) { if ( $ header ) { $ parts = explode ( ': ' , $ header , 2 ) ; $ name = $ parts [ 0 ] ; $ value = '' ; if ( count ( $ parts ) == 2 ) { $ value = $ parts [ 1 ] ; } if ( isset ( $ respHeaders [ $ name ] ) ) { if ( ! is_array ( $ respHeaders [ $ name ] ) ) { $ respHeaders [ $ name ] = array ( $ respHeaders [ $ name ] ) ; } $ respHeaders [ $ name ] [ ] = $ value ; } else { $ respHeaders [ $ name ] = $ value ; } } } $ this -> setResponseCurlInfo ( $ info ) ; $ this -> setResponseHttpCode ( $ respCode ) ; $ this -> setResponseHeaders ( $ respHeaders ) ; $ this -> setResponseBody ( $ respBody ) ; } curl_close ( $ ch ) ; return $ this ; }
Process an submitted cURL response .
21,942
public function validateResponse ( $ failIfNot200 = null ) { if ( null === $ failIfNot200 ) { $ failIfNot200 = $ this -> defaultFailIfNot200 ; } if ( CURLE_OK != $ this -> responseCurlErr ) { $ exClazz = 'Moar\Net\Http\Exception' ; switch ( $ this -> responseCurlErr ) { case CURLE_UNSUPPORTED_PROTOCOL : case CURLE_URL_MALFORMAT : $ exClazz = 'Moar\Net\Http\BadUrlException' ; break ; case CURLE_COULDNT_RESOLVE_HOST : $ exClazz = 'Moar\Net\Http\DnsFailureException' ; break ; case CURLE_COULDNT_CONNECT : $ exClazz = 'Moar\Net\Http\ConnectFailedException' ; break ; case CURLE_HTTP_RETURNED_ERROR : $ exClazz = 'Moar\Net\Http\StatusCodeException' ; break ; case CURLE_OPERATION_TIMEDOUT : $ exClazz = 'Moar\Net\Http\TimeoutException' ; break ; case CURLE_PEER_FAILED_VERIFICATION : case CURLE_SSL_CACERT : case CURLE_SSL_CACERT_BADFILE : case CURLE_SSL_CERTPROBLEM : case CURLE_SSL_CERTPROBLEM : case CURLE_SSL_CIPHER : case CURLE_SSL_CONNECT_ERROR : case CURLE_SSL_CRL_BADFILE : case CURLE_SSL_ENGINE_INITFAILED : case CURLE_SSL_ENGINE_NOTFOUND : case CURLE_SSL_ENGINE_SETFAILED : case CURLE_SSL_ISSUER_ERROR : case CURLE_SSL_SHUTDOWN_FAILED : case CURLE_USE_SSL_FAILED : $ exClazz = 'Moar\Net\Http\SslException' ; break ; } throw new $ exClazz ( $ this -> responseCurlErrMessage , $ this -> responseCurlErr , $ this ) ; } if ( $ failIfNot200 ) { $ code = $ this -> getResponseHttpCode ( ) ; if ( $ code < 200 || $ code > 299 ) { throw new StatusCodeException ( "HTTP Error: ({$code}) from {$this->url}" , CURLE_HTTP_RETURNED_ERROR , $ this ) ; } } }
Check the cURL response code and throw an exception if it is an error .
21,943
public static function parallelSubmit ( $ requests ) { $ handles = array ( ) ; $ mh = curl_multi_init ( ) ; foreach ( $ requests as $ req ) { $ ch = $ req -> createCurlRequest ( ) ; $ handles [ ( string ) $ ch ] = $ req ; curl_multi_add_handle ( $ mh , $ ch ) ; } $ reqsRunning = 0 ; do { $ status = curl_multi_exec ( $ mh , $ reqsRunning ) ; } while ( CURLM_CALL_MULTI_PERFORM == $ status ) ; while ( $ reqsRunning && CURLM_OK == $ status ) { $ selectReady = curl_multi_select ( $ mh ) ; if ( $ selectReady > 0 ) { while ( $ info = curl_multi_info_read ( $ mh ) ) { self :: handleMultiResponse ( $ info , $ mh , $ handles ) ; } } if ( - 1 != $ selectReady ) { do { $ status = curl_multi_exec ( $ mh , $ reqsRunning ) ; } while ( CURLM_CALL_MULTI_PERFORM == $ status ) ; } } if ( CURLM_OK != $ status ) { throw new Exception ( "Fatal error [{$status}] processing multiple requests" , $ status ) ; } while ( $ handles && ( $ info = curl_multi_info_read ( $ mh ) ) ) { self :: handleMultiResponse ( $ info , $ mh , $ handles ) ; } curl_multi_close ( $ mh ) ; return $ requests ; }
Submit a group of requests in parallel .
21,944
public static function get ( $ url , $ parms = null , $ options = null ) { $ url = Util :: addQueryData ( $ url , $ parms ) ; $ r = new Request ( $ url , self :: METHOD_GET , null , null , $ options ) ; return $ r -> submit ( ) ; }
Convenience method to perform a GET request .
21,945
public static function postContent ( $ url , $ content , $ contentType = 'text/xml' , $ options = null ) { $ headers = array ( "Content-type: {$contentType}" ) ; $ r = new Request ( $ url , self :: METHOD_POST , $ content , $ headers , $ options ) ; return $ r -> submit ( ) ; }
Convenience method to POST content in the form of a raw string to a URL .
21,946
public function getEnvironmentMessages ( ) { $ messages = array ( ) ; foreach ( $ this -> getEnvironments ( ) as $ environment ) { $ style = 'general' ; if ( false == $ this -> vagrentExists ( $ environment ) ) { $ style = 'warning' ; } $ messages [ $ environment ] = $ style ; } return $ messages ; }
This method returns an array of messages
21,947
public function prepare ( DataRequest $ dataRequest , $ paginationUrl , $ numberOfEntries , $ numberOfEntriesPerPage = 10 ) { $ this -> paginationUrl = $ paginationUrl ; $ neededPages = ceil ( $ numberOfEntries / $ numberOfEntriesPerPage ) ; $ activePage = $ dataRequest -> getPage ( ) ; $ pagination = new PaginationObject ( ) ; if ( $ activePage > 1 ) { $ button = new Button ( '&laquo;' , $ this -> buildUrl ( 1 ) ) ; $ pagination -> addEntry ( $ button ) ; $ button = new Button ( '&lsaquo;' , $ this -> buildUrl ( ( $ activePage - 1 ) ) ) ; $ pagination -> addEntry ( $ button ) ; } $ this -> addPages ( $ pagination , $ activePage , $ neededPages ) ; if ( $ activePage < $ neededPages ) { $ button = new Button ( '&rsaquo;' , $ this -> buildUrl ( ( $ activePage + 1 ) ) ) ; $ pagination -> addEntry ( $ button ) ; $ button = new Button ( '&raquo;' , $ this -> buildUrl ( $ neededPages ) ) ; $ pagination -> addEntry ( $ button ) ; } return $ pagination ; }
Prepares the Pagination object for the given DataRequest and number of entries per page
21,948
protected function addPages ( PaginationObject $ pagination , $ activePage , $ neededPages ) { for ( $ i = 1 ; $ i <= $ neededPages ; $ i ++ ) { if ( $ i == $ activePage ) { $ page = new ActivePage ( $ i , $ this -> buildUrl ( $ i ) ) ; $ pagination -> addEntry ( $ page ) ; } else if ( $ i < 4 || $ i > ( $ neededPages - 3 ) || ( $ i > ( $ activePage - 3 ) && $ i < ( $ activePage + 3 ) ) ) { $ page = new Page ( $ i , $ this -> buildUrl ( $ i ) ) ; $ pagination -> addEntry ( $ page ) ; } else if ( ! ( $ pagination -> getLatestEntry ( ) instanceof Dots ) ) { $ dots = new Dots ( ) ; $ pagination -> addEntry ( $ dots ) ; } } }
Add the pages to the pagination
21,949
public function toFile ( $ file ) { $ composer = json_decode ( file_get_contents ( $ file ) , true ) ; unset ( $ composer [ 'require' ] [ 'zendframework/zendframework' ] ) ; foreach ( array_keys ( $ this -> components ) as $ component ) { $ composer [ 'require' ] [ 'zendframework/' . $ component ] = $ this -> version ; } file_put_contents ( $ file , json_encode ( $ composer , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ) ; }
Updates the composer . json file with the new components list .
21,950
public function toConsole ( ) { $ this -> getConsole ( ) -> writeLine ( 'Replace "zendframework/zendframework" in your composer.json file with :' , Color :: YELLOW ) ; $ componentsCount = count ( $ this -> components ) ; $ count = 0 ; foreach ( array_keys ( $ this -> components ) as $ component ) { $ suffix = '' ; $ count ++ ; if ( $ count < $ componentsCount ) { $ suffix = ',' ; } $ this -> getConsole ( ) -> writeLine ( '"zendframework/' . $ component . '": "' . $ this -> version . '"' . $ suffix ) ; } }
Sends the components list to the console .
21,951
protected function getRoleFromAuth ( AuraAuth $ auth ) { if ( ! $ auth -> isValid ( ) ) { return $ this -> guestRole ; } $ data = $ auth -> getUserData ( ) ; return isset ( $ data [ $ this -> roleKey ] ) ? $ data [ $ this -> roleKey ] : $ this -> memberRole ; }
Get Role from Auth
21,952
protected function _createContainerException ( $ message = null , $ code = null , RootException $ previous = null , BaseContainerInterface $ container = null ) { return new ContainerException ( $ message , $ code , $ previous , $ container ) ; }
Creates a new container exception .
21,953
public static function getPhpValue ( $ val , $ default = null , ParserInterface $ parser = null ) { if ( $ val instanceof DOMElement ) { $ parser = $ parser ? : new static ; return $ parser -> parseDomElement ( $ val ) ; } if ( 0 === strlen ( $ val ) ) { return $ default ; } if ( 0 === strpos ( $ val , '0x' ) && preg_match ( '#^[[:xdigit:]]+$#' , substr ( $ val , 2 ) ) ) { return hexdec ( $ val ) ; } if ( is_numeric ( $ val ) ) { return ctype_digit ( $ val ) ? intval ( $ val ) : floatval ( $ val ) ; } if ( in_array ( $ lval = strtolower ( $ val ) , [ 'true' , 'false' ] ) ) { return $ lval === 'true' ? true : false ; } return $ val ; }
Get the php equivalent of an input value derived from any king of xml .
21,954
public static function getElementText ( DOMElement $ element , $ concat = true ) { $ textNodes = [ ] ; foreach ( $ element -> xpath ( './text()' ) as $ text ) { if ( $ value = static :: clearValue ( $ text -> nodeValue ) ) { $ textNodes [ ] = $ value ; } } return $ concat ? implode ( $ textNodes ) : $ textNodes ; }
Get the text of a DOMElement excluding the contents of its child elements .
21,955
protected function isListKey ( $ name , $ prefix = null ) { return $ this -> prefixKey ( $ this -> getIndexKey ( ) , $ prefix ) === $ name ; }
Check if a given string is the list identifier .
21,956
protected function normalizeKey ( $ key ) { if ( null !== $ this -> keyNormalizer ) { return call_user_func ( $ this -> keyNormalizer , $ key ) ; } return static :: fixNodeName ( $ key ) ; }
Normalize a node key
21,957
private function prepareTextValue ( DOMElement $ xml , array $ attributes = null ) { $ text = static :: getElementText ( $ xml , true ) ; return ( isset ( $ attributes [ 'type' ] ) && 'text' === $ attributes [ 'type' ] ) ? static :: clearValue ( $ text ) : static :: getPhpValue ( $ text , null , $ this ) ; }
Convert bool like and numeric values to their php equivalent values .
21,958
private function parseElementNodes ( $ children , $ parentName = null ) { $ result = [ ] ; foreach ( $ children as $ child ) { $ prefix = $ child -> prefix ? : null ; $ oname = $ this -> normalizeKey ( $ child -> nodeName ) ; $ name = $ this -> prefixKey ( $ oname , $ prefix ) ; if ( isset ( $ result [ $ name ] ) ) { $ this -> parseSetResultNodes ( $ child , $ name , $ result ) ; continue ; } $ this -> parseUnsetResultNodes ( $ child , $ name , $ oname , $ parentName , $ result , $ prefix ) ; } return $ result ; }
Parse a nodelist into a array
21,959
private function parseSetResultNodes ( DOMElement $ child , $ name , array & $ result = null ) { if ( ! ( is_array ( $ result [ $ name ] ) && $ this -> valueIsList ( $ result [ $ name ] ) ) ) { return false ; } $ value = static :: getPhpValue ( $ child , null , $ this ) ; if ( is_array ( $ value ) && $ this -> valueIsList ( $ value ) ) { return $ result [ $ name ] = array_merge ( $ result [ $ name ] , $ value ) ; } return $ result [ $ name ] [ ] = $ value ; }
Parse a DOMElement if a result key is set .
21,960
private function parseUnsetResultNodes ( DOMElement $ child , $ name , $ oname , $ pName , array & $ result , $ prefix = null ) { if ( $ this -> isListKey ( $ name , $ prefix ) || $ this -> isEqualOrPluralOf ( $ this -> normalizeKey ( $ pName ) , $ oname ) ) { if ( ( $ index = $ child -> getAttribute ( $ this -> getIndexAttributeKey ( ) ) ) && 0 !== strlen ( $ index ) ) { $ child -> removeAttribute ( $ this -> getIndexAttributeKey ( ) ) ; return $ result [ static :: getPhpValue ( $ index ) ] = static :: getPhpValue ( $ child , null , $ this ) ; } return $ result [ ] = static :: getPhpValue ( $ child , null , $ this ) ; } $ value = static :: getPhpValue ( $ child , null , $ this ) ; if ( 1 < $ this -> getEqualNodes ( $ child , $ prefix ) -> length ) { return $ result [ $ name ] [ ] = $ value ; } return $ result [ $ name ] = $ value ; }
Parse a DOMElement if a result key is unset .
21,961
private function parseElementAttributes ( DOMElement $ xml ) { $ attrs = [ ] ; $ elementAttrs = $ xml -> xpath ( './@*' ) ; if ( 0 === $ elementAttrs -> length ) { return $ attrs ; } foreach ( $ elementAttrs as $ key => $ attribute ) { $ value = static :: getPhpValue ( $ attribute -> nodeValue , null , $ this ) ; $ name = $ this -> normalizeKey ( $ attribute -> nodeName ) ; $ attrs [ $ this -> prefixKey ( $ name , $ attribute -> prefix ? : null ) ] = $ value ; } return [ $ this -> getAttributesKey ( ) => $ attrs ] ; }
Parse element attributes into an array .
21,962
private function isEqualOrPluralOf ( $ name , $ singular ) { return 0 === strnatcmp ( $ name , $ singular ) || 0 === strnatcmp ( $ name , $ this -> pluralize ( $ singular ) ) ; }
Check if the input string is a plural or equal to a given comparative string .
21,963
private function pluralize ( $ singular ) { if ( null === $ this -> pluralizer ) { return $ singular ; } return call_user_func ( $ this -> pluralizer , $ singular ) ; }
Attempt to pluralize a string .
21,964
private function getEqualNodes ( DOMElement $ node , $ prefix = null ) { $ name = $ this -> prefixKey ( $ node -> nodeName , $ prefix ) ; return $ node -> xpath ( sprintf ( ".|following-sibling::*[name() = '%s']|preceding-sibling::*[name() = '%s']" , $ name , $ name ) ) ; }
A lookahead to find sibling elements with similar names .
21,965
private function convertDocument ( \ DOMDocument $ xml ) { return $ this -> loader -> load ( $ xml -> saveXML ( ) , [ LoaderInterface :: FROM_STRING => true ] ) ; }
Converts a \ DOMDocument that is not an instance of Selene \ Module \ Dom \ DOMDocument .
21,966
public function patchIsAlreadyApplied ( Patch $ patch , $ baseDirectory , $ patchLevel ) { $ command = $ this -> buildCommand ( $ patch -> getLocalPath ( ) , $ baseDirectory , $ patchLevel , true ) ; list ( $ rc , $ stdOut , $ stdErr ) = $ this -> run ( $ command ) ; if ( $ stdErr === '' ) { $ stdErr = $ stdOut ; } if ( $ rc === 1 && strpos ( $ stdErr , 'Skipping patch.' ) !== false && preg_match ( '/^(\\d+) out of \\1 hunks? ignored/m' , $ stdErr ) ) { return true ; } return false ; }
Check if a patch is already applied .
21,967
private function initializeWindows ( ) { $ gitFolder = $ this -> findWindowsGitFolder ( ) ; if ( $ gitFolder !== '' ) { $ patchPath = "{$gitFolder}\\usr\\bin\\patch.exe" ; if ( is_file ( $ patchPath ) ) { try { $ patchPath = escapeshellarg ( $ patchPath ) ; $ this -> checkCommandExists ( $ patchPath ) ; $ this -> command = $ patchPath ; return ; } catch ( Exception \ CommandNotFound $ x ) { } } } try { $ this -> checkCommandExists ( 'patch' ) ; $ this -> command = 'patch' ; return ; } catch ( Exception \ CommandNotFound $ x ) { } throw new Exception \ CommandNotFound ( 'patch' , <<<'EOT'The patch command is currently not available.You have these options:1. Install Git for Windows, and add it to the PATH environment variable2. Find a Windows port of the "patch" GNU utility and it to a directory in the current PATHEOT ) ; }
Configure the instance for Windows .
21,968
private function findWindowsGitFolder ( ) { list ( $ rc , $ stdOut ) = $ this -> run ( 'where git.exe' ) ; if ( $ rc !== 0 ) { return '' ; } $ stdOut = str_replace ( "\r\n" , "\n" , $ stdOut ) ; foreach ( explode ( "\n" , trim ( $ stdOut ) ) as $ path ) { $ easierPath = str_replace ( '\\' , '/' , $ path ) ; $ match = null ; if ( preg_match ( '_^(.+)/(?:cmd|bin)/git\.exe$_i' , $ easierPath , $ match ) ) { return str_replace ( '/' , '\\' , $ match [ 1 ] ) ; } } return '' ; }
Search the path where git is installed on Windows .
21,969
public function getHits ( ) { if ( $ this -> hits === null ) { $ this -> hits = $ this -> stmt -> rowCount ( ) ; } return $ this -> hits ; }
Get number of results .
21,970
public function getResults ( ) { if ( empty ( $ this -> results ) ) { $ this -> results = $ this -> stmt -> fetchAll ( ) ; } return $ this -> results ; }
Get all results from the SELECT - Statement .
21,971
public function getFirstResult ( $ field = null ) { if ( empty ( $ this -> results ) ) { $ this -> results = isset ( $ field ) ? $ this -> stmt -> fetch ( ) [ $ field ] : $ this -> stmt -> fetch ( ) ; } return $ this -> results ; }
Get the first result from the SELECT - Statement .
21,972
public function licenseAgreementAction ( ) { $ this -> title ( "License Agreement" ) ; $ license = file_get_contents ( dirname ( dirname ( __DIR__ ) ) . '/COPYING' ) ; $ this -> set ( "license" , $ license ) ; return $ this -> render ( "license_agreement.phtml" ) ; }
License agreement page .
21,973
public static function findByPosition ( $ position ) { try { $ offset = $ position - 1 ; $ tableName = self :: getTableName ( ) ; $ conn = self :: getConnection ( ) ; $ stmt = $ conn -> query ( 'SELECT * FROM ' . $ tableName . ' LIMIT ' . $ offset . ', 1' ) ; if ( ! $ stmt ) { $ stmt = $ conn -> query ( 'SELECT * FROM ' . $ tableName . ' OFFSET ' . $ offset . ' LIMIT 1' ) ; } return self :: find ( $ stmt ) ; ; } catch ( PDOException $ pe ) { return $ pe -> getMessage ( ) ; } catch ( Exception $ e ) { return $ e -> getMessage ( ) ; } }
Finds a record in the database table in the position denoted by the parameter passed
21,974
public static function findById ( $ id ) { try { $ tableName = self :: getTableName ( ) ; $ conn = self :: getConnection ( ) ; $ stmt = $ conn -> query ( 'SELECT * FROM ' . $ tableName . ' WHERE id=' . $ id ) ; return self :: find ( $ stmt ) ; } catch ( PDOException $ pe ) { return $ pe -> getMessage ( ) ; } catch ( Exception $ e ) { return $ e -> getMessage ( ) ; } }
Finds a record in the database table that has the id passed in as a parameter
21,975
public static function find ( $ stmt ) { try { $ result = $ stmt -> fetch ( PDO :: FETCH_ASSOC ) ; if ( ! $ result ) { throw new Exception ( " Record not found." ) ; } $ object = new static ; $ object -> id = $ result [ 'id' ] ; $ object -> result = json_encode ( $ result ) ; return $ object ; } catch ( PDOException $ pe ) { return $ pe -> getMessage ( ) ; } catch ( Exception $ e ) { return $ e -> getMessage ( ) ; } }
Finds a record in the database using the statement object passed in
21,976
public static function getAll ( ) { try { $ tableName = self :: getTableName ( ) ; $ conn = self :: getConnection ( ) ; $ stmt = $ conn -> query ( 'SELECT * FROM ' . $ tableName ) ; return $ stmt -> fetchAll ( PDO :: FETCH_ASSOC ) ; } catch ( PDOException $ pe ) { return $ pe -> getMessage ( ) ; } catch ( Exception $ e ) { return $ e -> getMessage ( ) ; } }
This method fetches all the records in the database table and returns them in an array
21,977
public static function save ( ) { try { $ tableName = self :: getTableName ( ) ; $ affectedRows = 0 ; $ conn = self :: getConnection ( ) ; if ( array_key_exists ( "id" , self :: $ fields ) ) { $ sql = self :: makeUpdateSQL ( ) ; } else { $ tableColumns = implode ( ", " , array_keys ( self :: $ fields ) ) ; $ columnValues = "'" . implode ( "', '" , array_values ( self :: $ fields ) ) . "'" ; $ sql = "INSERT INTO " . $ tableName . "($tableColumns) VALUES($columnValues)" ; } $ affectedRows = $ conn -> exec ( $ sql ) ; return $ affectedRows ; } catch ( PDOException $ pe ) { return $ pe -> getMessage ( ) ; } catch ( Exception $ e ) { return $ e -> getMessage ( ) ; } }
This method inserts a new record into the database table or updates an already existing record
21,978
public static function makeUpdateSQL ( ) { $ tableName = self :: getTableName ( ) ; $ setClause = "" ; $ whereClause = "" ; $ keysCount = count ( self :: $ fields ) ; $ iterations = 1 ; foreach ( self :: $ fields as $ key => $ val ) { if ( $ key == "id" ) { $ whereClause = " WHERE id = " . $ val ; } else if ( $ key != "result" ) { $ setClause = $ setClause . $ key . " = '" . $ val . "'" ; if ( $ keysCount > 2 && $ iterations < $ keysCount ) { $ setClause = $ setClause . ", " ; } } $ iterations ++ ; } $ sql = "UPDATE " . $ tableName . " SET " . $ setClause . $ whereClause ; return $ sql ; }
This method generates the SQL statement used to update a record in the database
21,979
public static function destroy ( $ record ) { if ( is_string ( $ record ) ) { return $ record ; } $ id = $ record -> id ; try { $ tableName = self :: getTableName ( ) ; $ conn = self :: getConnection ( ) ; $ sql = "DELETE FROM " . $ tableName . " WHERE id = " . $ id ; $ affectedRows = $ conn -> exec ( $ sql ) ; return $ affectedRows ; } catch ( PDOException $ pe ) { return $ pe -> getMessage ( ) ; } catch ( Exception $ e ) { return $ e -> getMessage ( ) ; } }
This method deletes a record from the database table
21,980
public function verifyProtocol ( $ url , $ append = 'http://' ) { if ( strpos ( $ url , 'http://' ) === false && strpos ( $ url , 'https://' ) === false ) { $ url = $ append . $ url ; } return $ url ; }
Add protocol to an url if missing
21,981
public function setAmount ( float $ amount ) : self { $ this -> amount = ( int ) ( $ amount * self :: FACTOR_AMOUNT ) ; return $ this ; }
Sets the amount required for the recipe .
21,982
public function find ( $ re , $ filter = null ) { $ result = null ; $ this -> each ( function ( $ context ) use ( $ re , $ filter , & $ result ) { $ r = $ context -> find ( $ re , $ filter ) ; if ( ! $ r -> isEmpty ( ) ) { $ result = $ r ; return false ; } } ) ; return $ result ? : Context :: getEmptyContext ( ) ; }
Find the first matching context in the collection
21,983
public function mustFind ( $ re , $ filter = null ) { $ result = $ this -> find ( $ re , $ filter ) ; if ( $ result -> isEmpty ( ) ) { throw new QueryException ( 'No match for regexp: ' . $ re ) ; } return $ result ; }
Find with assertion
21,984
public function findAll ( $ re , $ filter = null ) { $ result = array ( ) ; $ this -> each ( function ( $ context ) use ( $ re , $ filter , & $ result ) { $ context -> findAll ( $ re , $ filter ) -> each ( function ( $ context ) use ( & $ result ) { $ result [ ] = $ context ; } ) ; } ) ; return new self ( $ result ) ; }
Find all matching contexts in the collection
21,985
public function mustFindAll ( $ re , $ filter = null ) { $ result = $ this -> findAll ( $ re , $ filter ) ; if ( $ result -> count ( ) == 0 ) { throw new QueryException ( 'No match for regexp: ' . $ re ) ; } return $ result ; }
Find all with assertion
21,986
public function extract ( $ parts = null ) { if ( $ parts === null ) { return $ this -> data ; } if ( is_array ( $ parts ) ) { $ result = array ( ) ; foreach ( $ this -> data as $ match ) { $ row = array ( ) ; foreach ( $ parts as $ key ) { if ( isset ( $ match [ $ key ] ) ) { $ row [ $ key ] = isset ( $ match [ $ key ] ) ? $ match [ $ key ] : null ; } } $ result [ ] = $ row ; } return $ result ; } $ result = array ( ) ; foreach ( $ this -> data as $ match ) { $ result [ ] = isset ( $ match [ $ parts ] ) ? $ match [ $ parts ] : null ; } return $ result ; }
Extract result parts of the collection .
21,987
public function each ( $ cb ) { foreach ( $ this -> data as $ context ) { $ context = new Context ( $ context ) ; if ( false === $ cb ( $ context ) ) { break ; } } return $ this ; }
Walk through the collection
21,988
public function size ( $ file , int $ size ) : bool { if ( empty ( $ filename = $ this -> resolveFilename ( $ file ) ) ) { return false ; } return $ this -> files -> size ( $ filename ) <= ( $ size * 1024 ) ; }
Check if file size less that specified value in KB .
21,989
public function extension ( $ file , $ extensions ) : bool { if ( ! is_array ( $ extensions ) ) { $ extensions = array_slice ( func_get_args ( ) , 1 ) ; } if ( $ file instanceof UploadedFileInterface ) { return in_array ( $ this -> files -> extension ( $ file -> getClientFilename ( ) ) , $ extensions ) ; } return in_array ( $ this -> files -> extension ( $ file ) , $ extensions ) ; }
Check if file extension in whitelist . Client name of uploaded file will be used! It is recommended to use external validation like media type based on file mimetype or ensure that resource is properly converted .
21,990
protected function addViolationToOutput ( array $ errors , ConstraintViolationInterface $ violation ) { $ path = $ this -> getPropertyPathAsArray ( $ violation ) ; $ currentPointer = & $ errors ; while ( count ( $ path ) > 0 ) { $ currentField = array_shift ( $ path ) ; if ( ! array_key_exists ( $ currentField , $ currentPointer ) or ! is_array ( $ currentPointer [ $ currentField ] ) ) { $ currentPointer [ $ currentField ] = [ ] ; } if ( is_numeric ( $ currentField ) ) { for ( $ i = 0 ; $ i < ( int ) $ currentField ; $ i ++ ) { if ( ! array_key_exists ( $ i , $ currentPointer ) ) { $ currentPointer [ ( int ) $ i ] = null ; } } ksort ( $ currentPointer ) ; } $ currentPointer = & $ currentPointer [ $ currentField ] ; } $ currentPointer [ ] = $ violation -> getMessage ( ) ; return $ errors ; }
Add a single constraint violation to a partially - built array of errors in the format described in groupViolationsByField
21,991
protected function getPropertyPathAsArray ( ConstraintViolationInterface $ violation ) { $ path = $ violation -> getPropertyPath ( ) ; $ path = substr ( $ path , 1 , strlen ( $ path ) - 2 ) ; return explode ( '][' , $ path ) ; }
Given a constraint violation return its property path as an array
21,992
protected function install ( ) { $ this -> setupCore ( ) ; $ this -> setupBackend ( ) ; $ this -> initializeDatabase ( ) ; $ this -> runCommand ( 'cache:clear' , array ( '--no-warmup' => true ) ) ; }
Install Avoo framework
21,993
private function isDatabaseExist ( ) { $ databaseName = $ this -> getContainer ( ) -> getParameter ( 'database_name' ) ; try { $ schemaManager = $ this -> getContainer ( ) -> get ( 'doctrine' ) -> getManager ( ) -> getConnection ( ) -> getSchemaManager ( ) ; } catch ( \ Exception $ exception ) { $ message = "SQLSTATE[42000] [1049] Unknown database '%s'" ; if ( false !== strpos ( $ exception -> getMessage ( ) , sprintf ( $ message , $ databaseName ) ) ) { return false ; } throw $ exception ; } try { return in_array ( $ databaseName , $ schemaManager -> listDatabases ( ) ) ; } catch ( \ PDOException $ e ) { return false ; } }
Is database exist
21,994
public function load ( $ template , $ args = [ ] , $ filter_args = [ ] , $ buffered = null ) { if ( $ buffered ) ob_start ( ) ; if ( $ filter_args ) { foreach ( $ filter_args as $ filter ) { $ args = array_map ( $ filter , $ args ) ; } } extract ( $ args , EXTR_SKIP ) ; require ( $ template ) ; if ( $ buffered ) return ob_get_clean ( ) ; }
Template loader .
21,995
public function getRelativePath ( File $ base_dir ) { return FileSystem :: getFileSystem ( ) -> makePathRelative ( $ this -> file -> getAbsoluteFile ( ) -> getParent ( ) , $ base_dir -> getAbsolutePath ( ) ) . $ this -> file -> getName ( ) ; }
Returns the relative path
21,996
public final function getParentProject ( ) { $ result = \ Chigi \ Chiji \ Util \ ProjectUtil :: searchRelativeProject ( $ this ) ; if ( count ( $ result ) < 1 ) { throw new \ Chigi \ Chiji \ Exception \ ProjectMemberNotFoundException ( "MEMBER NOT FOUND" ) ; } return $ result [ 0 ] ; }
Gets the parent project of this registered resource .
21,997
public final function getFinalCache ( ) { $ resource = $ this ; while ( true ) { $ cache_file = $ this -> getParentProject ( ) -> getCacheManager ( ) -> getCacheBuilt ( $ resource ) ; if ( \ is_null ( $ cache_file ) || \ is_null ( $ this -> getParentProject ( ) -> getResourceByFile ( $ cache_file ) ) || $ this -> getParentProject ( ) -> getResourceByFile ( $ cache_file ) -> getMemberId ( ) === $ resource -> getMemberId ( ) ) { return $ resource ; } $ resource = $ this -> getParentProject ( ) -> getResourceByFile ( $ cache_file ) ; } }
Returns the final cache resource built from this .
21,998
protected function parse ( ) { try { $ data = app ( Browscap :: class ) -> getBrowser ( $ this -> userAgent ) ; } catch ( Exception $ e ) { return ; } foreach ( $ data as $ key => $ value ) { $ key = strtolower ( $ key ) ; $ value = trim ( $ value ) ; switch ( $ key ) { case 'ismobiledevice' : $ this -> isMobile = ! empty ( $ value ) ; break ; case 'istablet' : $ this -> isTablet = ! empty ( $ value ) ; break ; case 'crawler' : $ this -> isCrawler = ! empty ( $ value ) ; break ; case 'majorver' : $ this -> majorVersion = ( int ) $ value ; break ; case 'minorver' : $ this -> minorVersion = ( int ) $ value ; break ; case 'device_type' : $ this -> device = $ value ; break ; case 'device_pointing_method' : $ this -> devicePointer = $ value ; break ; case 'browser_maker' : $ this -> publisher = $ value ; break ; case 'comment' : $ this -> browserWithVersion = $ value ; break ; case 'browser' : case 'platform' : $ this -> { $ key } = $ value ; break ; } } $ this -> setVersion ( $ data -> version ) ; $ this -> successful = true ; }
Parse user agent with the help from Browscap .
21,999
protected function setVersion ( $ version ) { $ this -> version = $ version ; if ( empty ( $ this -> majorVersion ) && strpos ( $ version , '.' ) !== false ) { $ version = explode ( '.' , $ version ) ; $ this -> majorVersion = ( int ) isset ( $ version [ 0 ] ) ? $ version [ 0 ] : 0 ; $ this -> minorVersion = ( int ) isset ( $ version [ 1 ] ) ? $ version [ 1 ] : 0 ; } else { $ this -> majorVersion = ( int ) $ version ; } return $ this ; }
Set version of browser .