idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
16,900
public function isValid ( $ secret ) { if ( ! extension_loaded ( 'hash' ) ) { throw new \ Exception ( 'Hash extension not loaded' ) ; } list ( $ algo , $ sig ) = explode ( "=" , $ this -> signature ) ; if ( ! in_array ( $ algo , hash_algos ( ) , true ) ) { throw new \ Exception ( "Hash algorithm '$algo' is not supporte...
Validate the signature
16,901
public function lumDiff ( $ color1 , $ color2 ) { list ( $ R1 , $ G1 , $ B1 ) = is_array ( $ color1 ) ? $ color1 : $ this -> rgb ( $ color1 ) ; list ( $ R2 , $ G2 , $ B2 ) = is_array ( $ color2 ) ? $ color2 : $ this -> rgb ( $ color2 ) ; $ L1 = 0.2126 * pow ( $ R1 / 255 , 2.2 ) + 0.7152 * pow ( $ G1 / 255 , 2.2 ) + 0.0...
Uses luminosity to calculate the difference between the given colors . The returned value should be bigger than 5 for best readability .
16,902
protected function getFormParams ( $ parameters = array ( ) ) { $ formParams = $ parameters ; if ( ! array_key_exists ( 'api_output' , $ formParams ) ) { $ formParams [ 'api_output' ] = Api :: DEFAULT_OUTPUT ; } if ( ! array_key_exists ( 'api_key' , $ formParams ) ) { $ formParams [ 'api_key' ] = $ this -> apiKey ; } r...
Get form params
16,903
protected function removeResultInformation ( $ json ) { $ object = json_decode ( $ json , false ) ; if ( property_exists ( $ object , 'result_code' ) ) { unset ( $ object -> result_code ) ; } if ( property_exists ( $ object , 'result_message' ) ) { unset ( $ object -> result_message ) ; } if ( property_exists ( $ objec...
Remove result information
16,904
private function parseEventName ( ) { $ name = basename ( strtr ( get_class ( $ this -> event ) , [ '\\' => '/' ] ) ) ; return strtolower ( preg_replace ( '#[A-Z]#' , '.$0' , lcfirst ( $ name ) ) ) ; }
Parses an event object into a readable event name .
16,905
public function processError ( $ exception , $ type = 'exception' , $ logonly = false , $ forcelogtrace = false ) { $ this -> countoferrors ++ ; if ( $ this -> countoferrors > 500 ) { return false ; } $ this -> error ( $ exception -> getMessage ( ) , array ( 'group' => 'error|' . $ type , 'exception' => $ exception , '...
The function logs an error and desides what to show to a user It can be called from outside or from internal methods in case of warning or fatal error
16,906
public function getHTMLError ( $ exception ) { $ html = '<div style="position: absolute; top:0; right:0; width:100%; height:100%; background: #ffffff;">' . "\n" . '<table align="center" style="width:65%; margin-top: 30px; background: #FFCC66;" cellpadding="10" cellspacing="1" border="0">' . "\n" . '<tr>' . "\n" . '<td ...
Build HTML to display error
16,907
protected function showHTTP ( $ exception ) { header ( "HTTP/1.1 400 Unexpected error" ) ; $ message = preg_replace ( '![^a-z 0-9_-]!' , '' , $ this -> getMessageForUser ( $ exception ) ) ; header ( "X-Error-Message: " . $ message ) ; }
Return to user only headers with an error as part of a header
16,908
protected function showXML ( $ exception ) { $ endline = "\r\n" ; $ xml = '<?xml version="1.0" encoding="UTF-8"?>' . $ endline . '<response>' . $ endline . '<status>error</status>' . $ endline . '<message>' . htmlspecialchars ( $ this -> getMessageForUser ( $ exception ) ) . '</message>' . $ endline . '</response>' ; h...
Display error in XML format
16,909
public function warningHandler ( $ errno , $ errstr , $ errfile , $ errline ) { if ( $ errno != E_WARNING && $ errno != E_USER_WARNING ) { return false ; } $ message = "WARNING! [$errno] $errstr. Line $errline in file $errfile. " ; $ this -> setCatchWarnings ( false ) ; $ exception = new \ Exception ( $ message ) ; $ t...
To catch warnings . Notices are ignored in this function . This is the callback for a function set_error_handler
16,910
protected function getRequestInformation ( ) { $ postdata = '' ; if ( $ _SERVER [ 'REQUEST_METHOD' ] == 'POST' ) { $ t = array ( ) ; foreach ( $ _POST as $ k => $ v ) { $ t [ ] = $ k . '=' . $ v ; } $ postdata = preg_replace ( '![\n\r]!' , "" , implode ( '&' , $ t ) ) ; if ( strlen ( $ postdata ) > 250 ) { $ postdata =...
Collect request information to log it . This can help to solve a problem later .
16,911
protected function matchRequest ( Request $ request , array $ parameters = [ ] ) { if ( ! isset ( $ parameters [ '_modular_path' ] ) ) { throw new \ InvalidArgumentException ( 'The routing provider expected parameter "_modular_path" but could not find it.' ) ; } $ path = $ parameters [ '_modular_path' ] ; $ position = ...
Filters the module identity from the request path .
16,912
public static function encode ( $ arg ) { $ s = base64_encode ( $ arg ) ; $ s = explode ( '=' , $ s ) [ 0 ] ; $ s = str_replace ( '+' , '-' , $ s ) ; $ s = str_replace ( '/' , '_' , $ s ) ; return $ s ; }
Encodes the specified byte array .
16,913
public static function decode ( string $ arg ) { $ s = $ arg ; $ s = str_replace ( '-' , '+' , $ s ) ; $ s = str_replace ( '_' , '/' , $ s ) ; switch ( strlen ( $ s ) % 4 ) { case 0 : break ; case 2 : $ s .= "==" ; break ; case 3 : $ s .= "=" ; break ; default : throw new \ Exception ( "Illegal base64url string!" ) ; }...
Decodes the specified string .
16,914
public function setAllHeaders ( array $ headerArray ) { foreach ( $ headerArray as $ field => $ value ) { $ this -> setHeader ( $ field , $ value ) ; } return $ this ; }
Set multiple headers from a key - value array
16,915
public function setHeader ( $ field , $ value ) { if ( ! $ field = @ trim ( $ field ) ) { throw new HTTPException ( 'Non-empty string field name required at Argument 1' ) ; } $ ucField = strtoupper ( $ field ) ; if ( $ ucField === 'SET-COOKIE' ) { $ this -> setCookieFromRawHeaderValue ( $ value ) ; return $ this ; } el...
Assign a header value
16,916
public function addHeader ( $ field , $ value ) { if ( $ this -> hasHeader ( $ field ) ) { $ existing = $ this -> getHeader ( $ field ) ; $ existing = is_array ( $ existing ) ? $ existing : [ $ existing ] ; $ value = is_scalar ( $ value ) ? [ $ value ] : $ value ; $ newHeaders = array_merge ( $ existing , $ value ) ; $...
Append a header value
16,917
public function hasHeader ( $ field ) { $ ucField = strtoupper ( $ field ) ; return isset ( $ this -> ucHeaders [ $ ucField ] ) || ( $ ucField === 'SET-COOKIE' && $ this -> cookies ) ; }
Does the response currently have a value for the specified header field?
16,918
public function removeHeader ( $ field ) { $ ucField = strtoupper ( $ field ) ; if ( $ ucField === 'SET-COOKIE' ) { $ this -> cookies = [ ] ; } elseif ( isset ( $ this -> ucHeaders [ $ ucField ] ) ) { $ field = $ this -> ucHeaders [ $ ucField ] ; unset ( $ this -> ucHeaders [ $ ucField ] , $ this -> headers [ $ field ]...
Removes assigned headers for the specified field
16,919
public function setCookie ( $ name , $ value = '' , array $ options = [ ] ) { $ value = urlencode ( $ value ) ; $ this -> assignCookieHeader ( $ name , $ value , $ options ) ; return $ this ; }
Set a cookie value to be sent with the response .
16,920
public function getHeader ( $ field ) { $ ucField = strtoupper ( $ field ) ; if ( $ ucField === 'SET-COOKIE' && $ this -> cookies ) { $ result = array_values ( $ this -> cookies ) ; } elseif ( isset ( $ this -> ucHeaders [ $ ucField ] ) ) { $ field = $ this -> ucHeaders [ $ ucField ] ; $ result = $ this -> headers [ $ ...
Retrieve assigned header values for the specified field
16,921
public function setBody ( Body $ body ) { $ this -> body = $ body ; $ this -> setAllHeaders ( $ body -> getHeaders ( ) ) ; $ this -> setStatus ( $ body -> getStatusCode ( ) ) ; return $ this ; }
Assign a response entity body
16,922
public function getAllHeaders ( ) { $ headers = $ this -> headers ; if ( $ this -> cookies ) { $ headers [ 'Set-Cookie' ] = array_values ( $ this -> cookies ) ; } return $ headers ; }
Retrieve an array mapping header field names to their assigned values
16,923
public function getAllHeaderLines ( ) { $ headers = [ ] ; foreach ( $ this -> getAllHeaders ( ) as $ field => $ valueArray ) { foreach ( $ valueArray as $ value ) { $ headers [ ] = "{$field}: $value" ; } } return $ headers ; }
Retrieve an array of header strings appropriate for output
16,924
public function import ( Response $ response ) { $ this -> clear ( ) ; foreach ( $ response -> toArray ( ) as $ key => $ value ) { $ this -> offsetSet ( $ key , $ value ) ; } return $ this ; }
Import values from external Response instance
16,925
public function clear ( ) { $ this -> status = 200 ; $ this -> reasonPhrase = '' ; $ this -> headers = [ ] ; $ this -> ucHeaders = [ ] ; $ this -> cookies = [ ] ; $ this -> body = null ; $ this -> asgiMap = [ ] ; return $ this ; }
Remove all assigned values and reset defaults
16,926
public function permissions_obj ( $ model = null ) { $ model = $ model ? $ model : new Permission ; $ objs = [ ] ; $ permissions = $ this -> resource -> permissions ; if ( ! empty ( $ permissions ) ) { foreach ( $ permissions as $ permission => $ status ) { $ objs [ ] = ( ! $ model :: wherePermission ( $ permission ) -...
Obtains the permission obj associated to the model
16,927
public function addProductAction ( Product $ product , $ quantity , Request $ request ) { $ orderCollection = $ this -> getCurrentCart ( ) ; $ quantity = array_key_exists ( 'quantity' , $ _POST ) ? ( int ) $ _POST [ 'quantity' ] : $ quantity ; try { if ( '-' == $ request -> get ( 'remove' ) ) { $ quantity = - 1 * $ qua...
add Product to Cart
16,928
final public function set ( $ varname , $ value ) { if ( $ this -> lock ) return false ; $ previous = isset ( $ this -> data [ $ varname ] ) ? $ this -> data [ $ varname ] : null ; $ this -> data [ $ varname ] = $ value ; return $ this ; }
Adds a value to the registry
16,929
final public function get ( $ varname ) { $ previous = isset ( $ this -> data [ $ varname ] ) ? $ this -> data [ $ varname ] : null ; return $ previous ; }
Gets the value of an item in the registry
16,930
final public function lock ( ) { if ( ! isset ( $ this -> name ) || empty ( $ this -> name ) || ( $ this -> name === 'default' ) ) { return false ; } $ this -> lock = TRUE ; }
Locks the registry
16,931
public function read ( $ string ) { try { $ wasUsingErrors = libxml_use_internal_errors ( ) ; @ $ xmlObject = simplexml_load_string ( $ string ) ; libxml_use_internal_errors ( $ wasUsingErrors ) ; if ( $ xmlObject ) { return $ this -> recurseToArray ( $ xmlObject ) ; } } catch ( \ Exception $ e ) { } return null ; }
Attempt to read an XML document
16,932
protected function recurseToArray ( $ object ) { if ( is_scalar ( $ object ) ) { return $ object ; } $ array = ( array ) $ object ; foreach ( $ array as & $ value ) { if ( ! is_scalar ( ( $ value ) ) ) { $ value = $ this -> recurseToArray ( $ value ) ; continue ; } } return $ array ; }
Recurse through non scalars turning them into arrays just returns scalars as is .
16,933
public function loadUser ( User $ user ) { if ( $ user -> isGuest ( ) ) { return ; } $ this -> db -> qb ( [ 'table' => $ this -> table , 'field' => [ 'username' , 'display_name' , 'state' ] , 'filter' => 'id_user=:id_user' , 'params' => [ ':id_user' => $ user -> getId ( ) ] ] ) ; $ data = $ this -> db -> single ( ) ; i...
Loads user from DB .
16,934
protected function _extractAttributes ( $ str ) { $ str = preg_replace ( "/[\x{00a0}\x{200b}]+/u" , ' ' , $ str ) ; $ attributes = array ( ) ; $ patterns = array ( 'name-value-quotes-dble' => '(\w+)\s*=\s*"([^"]*)"' , 'name-value-quotes-sgle' => "(\w+)\s*=\s*'([^']*)'" , 'name-value-quotes-none' => '(\w+)\s*=\s*([^\s\'...
Extract attributes from string .
16,935
protected function _renderCell ( $ str , $ data ) { $ str = $ this -> _replaceData ( $ str , $ data ) ; $ str = $ this -> _replaceEval ( $ str ) ; $ str = $ this -> _replaceData ( $ str , $ data ) ; $ str = $ this -> _replaceCurrency ( $ str ) ; $ str = $ this -> _replaceTime ( $ str ) ; $ str = $ this -> _replaceTrans...
Render table s cell .
16,936
protected function _renderHeaders ( $ options , $ tag = 'thead' ) { $ th = array ( ) ; foreach ( $ options [ 'columns' ] as $ name => $ thOptions ) { $ thOptions = Hash :: merge ( $ this -> __colDefaults , array ( 'th' => $ options [ 'th' ] [ 'attrs' ] ) , $ thOptions ) ; if ( false !== $ options [ 'paginate' ] && fals...
Render table s headers row .
16,937
public function _renderPagination ( $ options ) { if ( $ this -> Paginator -> request -> params [ 'paging' ] [ $ this -> Paginator -> defaultModel ( ) ] [ 'pageCount' ] < 2 ) { return '' ; } if ( CakePlugin :: loaded ( 'TwitterBootstrap' ) ) { } $ out = array ( ) ; $ paginate = $ options [ 'paginate' ] ; $ prev = $ pag...
Render table s pagination row .
16,938
protected function _replaceCurrency ( $ str ) { if ( ! preg_match_all ( '/\[currency(.*?)\](.*)\[\/currency\]/i' , $ str , $ matches ) ) { if ( ! preg_match_all ( '/\[currency(.*?)\](.[^\[]*)\[\/currency\]/i' , $ str , $ matches ) ) { return $ str ; } } foreach ( $ matches [ 0 ] as $ i => $ find ) { $ opts = $ this -> ...
Replace by formatted currency string .
16,939
protected function _replaceTime ( $ str ) { if ( ! preg_match_all ( '/\[time(.*?)\](.*)\[\/time\]/i' , $ str , $ matches ) ) { if ( ! preg_match_all ( '/\[time(.*?)\](.[^\[]*)\[\/time\]/i' , $ str , $ matches ) ) { return $ str ; } } foreach ( $ matches [ 0 ] as $ i => $ find ) { $ opts = $ this -> _extractAttributes (...
Replace by formatted time string .
16,940
protected function _replaceTranslate ( $ str ) { if ( preg_match_all ( '/\[__\](.*?)\[\/__\]/i' , $ str , $ matches ) ) { foreach ( $ matches [ 0 ] as $ i => $ find ) { $ str = str_replace ( $ find , I18n :: translate ( $ matches [ 1 ] [ $ i ] ) , $ str ) ; } } if ( preg_match_all ( '/\[__d\|(.+?)\](.*?)\[\/__d\]/i' , ...
Replace translatable strings by their translated values .
16,941
public function redirectToPath ( $ path , $ parameters = array ( ) ) { $ route = $ this -> getRouter ( ) -> generate ( $ path , $ parameters ) ; return $ this -> redirect ( $ route ) ; }
Returns a ResponseRedirect to a given route name
16,942
public function sendFile ( $ filePath , $ fileName = null ) { if ( $ filePath instanceof File ) { $ filePath = $ filePath -> getPathname ( ) ; } $ response = new Response ( ) ; $ response -> headers -> set ( 'Cache-Control' , 'private' ) ; $ response -> headers -> set ( 'Content-Type' , mime_content_type ( $ filePath )...
Sends a Response serving a given file
16,943
public function createAndSubmitForm ( $ type , $ data = null , callable $ validCallback = null ) { $ form = $ this -> createForm ( $ type , $ data ) ; if ( $ this -> isPost ( ) ) { $ form -> handleRequest ( $ this -> getRequest ( ) ) ; if ( $ form -> isValid ( ) ) { if ( $ validCallback ) { $ response = $ validCallback...
Creates a submit a form to use in controllers
16,944
private function createCreateForm ( Agreement $ entity ) { $ form = $ this -> createForm ( new AgreementType ( ) , $ entity , array ( 'action' => $ this -> generateUrl ( 'agreement_create' ) , 'method' => 'POST' , ) ) ; $ form -> add ( 'submit' , 'submit' , array ( 'label' => 'Create' ) ) ; return $ form ; }
Creates a form to create a Agreement entity .
16,945
public function newAction ( ) { $ entity = new Agreement ( ) ; $ form = $ this -> createCreateForm ( $ entity ) ; return array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , ) ; }
Displays a form to create a new Agreement entity .
16,946
private function createEditForm ( Agreement $ entity ) { $ form = $ this -> createForm ( new AgreementType ( ) , $ entity , array ( 'action' => $ this -> generateUrl ( 'agreement_update' , array ( 'id' => $ entity -> getId ( ) ) ) , 'method' => 'PUT' , ) ) ; $ form -> add ( 'submit' , 'submit' , array ( 'label' => 'Upd...
Creates a form to edit a Agreement entity .
16,947
public static function ini ( ) { $ lang = config ( 'lang.default' ) ; self :: $ langFolder = dirname ( dirname ( __DIR__ ) ) . '/app/lang/' . $ lang ; self :: $ langFile = self :: $ langFolder . '/validator.php' ; if ( is_file ( self :: $ langFile ) ) { V :: langDir ( self :: $ langFolder ) ; V :: lang ( 'validator' ) ...
Initiate validator .
16,948
public static function make ( array $ data , array $ rules ) { self :: $ validator = new V ( [ ] ) ; self :: $ validator -> labels ( $ data ) ; foreach ( $ rules as $ rule => $ columns ) { if ( is_string ( $ columns ) ) { $ columns = self :: separte ( $ columns ) ; } else { $ columns = $ columns ; } $ value = self :: g...
Make new validation procces .
16,949
protected static function getValue ( $ param ) { $ data = explode ( ':' , $ param ) ; $ result = [ 'rule' => trim ( $ data [ 0 ] ) ] ; $ result [ 'value' ] = count ( $ data ) > 1 ? $ data [ 1 ] : null ; return $ result ; }
Get value of the rule .
16,950
public static function fromLocale ( string $ locale ) : LocaleFormatter { $ formatter = new NumberFormatter ( ( string ) $ locale , NumberFormatter :: CURRENCY ) ; return new self ( $ formatter ) ; }
Creates instance from a locale string
16,951
protected function validatePrototypeNode ( PrototypedArrayNode $ node ) { $ path = $ node -> getPath ( ) ; if ( $ this -> addDefaults ) { throw new InvalidDefinitionException ( sprintf ( '->addDefaultsIfNotSet() is not applicable to prototype nodes at path "%s"' , $ path ) ) ; } if ( false !== $ this -> addDefaultChild...
Validate the configuration of a prototype node .
16,952
public function setAction ( $ action ) { $ this -> setVariable ( self :: ACTION , $ this -> assembleAssignmentString ( self :: DATA_HREF , $ action ) ) ; $ this -> setEventType ( self :: CLICK_EVENT ) ; $ this -> addClass ( self :: AJAX_ELEMENT_CLASS ) ; if ( ! $ this -> getId ( ) ) { $ this -> setId ( "button_" . floo...
Sets the route to a controller action .
16,953
public function setEventType ( $ eventType ) { $ this -> setVariable ( self :: EVENT_TYPE , $ this -> assembleAssignmentString ( self :: DATA_EVENT , $ eventType ) ) ; }
Sets the event type of the button . Default is click .
16,954
public function setParam ( $ paramJsonString ) { $ this -> setVariable ( self :: PARAM , $ this -> assembleAssignmentString ( self :: DATA_JSON , $ paramJsonString ) ) ; }
Sets an optional parameter which is send to the server if the by the event type specified event occurred .
16,955
public static function of ( ? string $ keyType = null , ? string $ valueType = null ) : HashTable { return new static ( $ keyType , $ valueType ) ; }
Creates collection with specific key and value types
16,956
private function parseChain ( $ chain = [ ] ) : void { if ( ! \ is_array ( $ chain ) ) { throw new InvalidArgumentException ( 'Validators chain must be an array' ) ; } foreach ( $ chain as $ k => $ v ) { if ( $ v instanceof AbstractSpecific ) { $ reflection = new \ ReflectionClass ( $ v ) ; $ name = \ str_replace ( $ r...
Parses chain array
16,957
public function remove ( $ validator = '' ) : Chain { if ( ! \ is_string ( $ validator ) ) { throw new InvalidArgumentException ( 'Validator name must be a string' ) ; } if ( isset ( $ this -> chain [ $ validator ] ) ) { unset ( $ this -> chain [ $ validator ] ) ; } return $ this ; }
Removes validator from chain
16,958
private function parseOptionValue ( $ value = null ) { if ( \ is_bool ( $ value ) ) { $ value = $ value === true ? 'true' : 'false' ; } elseif ( \ is_null ( $ value ) ) { $ value = 'null' ; } elseif ( \ is_string ( $ value ) ) { $ value = '\'' . $ value . '\'' ; } return $ value ; }
Parses option value for getChain method
16,959
public function getChain ( bool $ includeOptions = true ) : string { $ chain = [ ] ; foreach ( $ this -> chain as $ validatorName => $ validatorObj ) { if ( $ includeOptions === true ) { $ options = [ ] ; $ tmpOptions = $ validatorObj -> getOptions ( ) ; foreach ( $ tmpOptions as $ optionName => $ optionVal ) { $ optio...
Returns validation chain
16,960
public function lastModified ( $ row , $ column ) : ? \ DateTime { $ file = $ this -> getData ( $ row , $ column ) ; if ( $ file == null ) { return null ; } $ file = rtrim ( $ file , DIRECTORY_SEPARATOR ) ; $ file = $ this -> rootPath . DIRECTORY_SEPARATOR . $ file ; $ format = "YmdHis" ; $ dateTime = \ DateTime :: cre...
Returns the date and time when index was last modified .
16,961
private function _getInstance ( $ pFileStr ) { $ filePath = $ this -> _configPath ; $ file = $ filePath . str_replace ( '-' , DS , $ pFileStr ) . self :: EXT ; if ( $ this -> _envPrefix ) { $ file = preg_replace ( '/([a-z0-9]+\.)/i' , $ this -> _envPrefix . '$1' , $ file ) ; } if ( ! isset ( $ this -> _instance [ $ fil...
Load configuration file content if not already loaded .
16,962
private function _getEventsConfig ( ) { $ content = array ( self :: MAIN_EVENTS_FILE => array ( ) ) ; $ configPath = $ this -> _configPath ; if ( ! is_dir ( $ configPath ) ) { return $ content ; } $ files = DirData :: listFilesRecursive ( $ configPath , self :: MAIN_EVENTS_FILE . self :: EXT ) ; foreach ( $ files as $ ...
Search all events config files and get config value .
16,963
private function _getConfigValues ( $ pPath , $ pForceGlobalArray ) { $ pathArr = explode ( DS , $ pPath , 2 ) ; if ( ! isset ( $ pathArr [ 1 ] ) ) { return NULL ; } $ path = rtrim ( $ pathArr [ 1 ] , '/' ) ; if ( $ pPath === self :: CONFIG_EVENTS_PATH ) { $ content = $ this -> _getEventsConfig ( ) ; } else { $ content...
Return NULL the config value or an array of values corresponding to the requested path .
16,964
public function getConfig ( $ pPath , $ pForceGlobalArray = false ) { if ( array_key_exists ( $ pPath , $ this -> _cache ) ) { return $ this -> _cache [ $ pPath ] ; } if ( $ this -> _cacheEnabled and $ pPath != static :: CONFIG_CACHE_TYPE_KEY ) { if ( $ this -> _cacheInstance === NULL ) { $ this -> _cacheInstance = Agl...
Retrieve a value in the configuration files .
16,965
public function seoFriendlyUrl ( string $ str ) : string { $ str = preg_replace ( '/[^a-z0-9_\s-]/' , '' , strtolower ( $ str ) ) ; $ str = preg_replace ( '/[\s-]+/' , ' ' , $ str ) ; $ str = preg_replace ( '/[\s_]/' , '-' , $ str ) ; return $ str ; }
Check for SEO Friendly Url .
16,966
public function isValidIP4 ( string $ ipAddress ) : bool { return ( bool ) filter_var ( $ ipAddress , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 | FILTER_FLAG_NO_RES_RANGE ) ; }
Basic IP4 validation private and reserved ranges .
16,967
public function isValidStringLength ( $ str , $ min = null , $ max = null ) : bool { $ len = mb_strlen ( $ str , 'UTF-8' ) ; return ( ( $ min !== null ) && ( $ len >= $ min ) ) || ( ( $ max !== null ) && ( $ len <= $ max ) ) ; }
Checking string length max and minimum .
16,968
public function isValidIP4NoPrivate ( string $ ipAddress ) : bool { return ( bool ) filter_var ( $ ipAddress , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ; }
Basic IP4 validation ; exclude private range .
16,969
public function isValidIP6NoPrivate ( string $ ipAddress ) : bool { return ( bool ) filter_var ( $ ipAddress , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ; }
Basic IP6 validation private and reserved ranges .
16,970
public function isPostalState ( string $ value ) : bool { return ( bool ) ( in_array ( strtoupper ( trim ( $ value ) ) , array_keys ( $ this -> postalStates ) ) !== false ) ; }
Validation Postal State Address .
16,971
public function isValidDate ( $ datetime , string $ format = 'Y-m-d H:i:s' ) : bool { $ dateType = DateTime :: createFromFormat ( $ format , $ datetime ) ; return ( bool ) ( $ dateType && $ dateType -> format ( $ format ) === $ datetime ) ; }
Check the format and the validity of a date .
16,972
public function createHashFileName ( string $ filename , string $ extension = '.php' ) : string { return sprintf ( '%s%s' , hash ( 'sha256' , $ filename , false ) , $ extension ) ; }
Generate a hash file name .
16,973
public function sets ( array $ properties ) { foreach ( $ properties as $ k => $ v ) { $ this -> set ( $ k , $ v ) ; } return $ this ; }
Set some object properties
16,974
public function getErrorsAsString ( string $ separator = '<br />' ) : string { $ errors = $ this -> errors ; foreach ( $ errors as & $ error ) { $ error = $ error -> getMessage ( ) ; } return implode ( $ separator , $ errors ) ; }
Return all errors if any as a unique string
16,975
public function getError ( ? int $ i = null ) : string { if ( null === $ i ) { $ error = end ( $ this -> errors ) ; } else { if ( ! array_key_exists ( $ i , $ this -> errors ) ) { return false ; } $ error = $ this -> errors [ $ i ] ; } if ( $ error instanceof Exception ) { return $ error -> getMessage ( ) ; } return $ ...
Get an error message
16,976
public function parse ( $ data ) { $ parsedData = null ; switch ( $ this -> type ) { case 'application/json' : $ parsedData = json_decode ( $ data , true ) ; break ; case 'application/xml' : case 'text/xml' : $ backup = libxml_disable_entity_loader ( true ) ; $ parsedData = simplexml_load_string ( $ data ) ; libxml_dis...
Parse data according their type .
16,977
protected function registerGroups ( ) { $ this -> app -> singleton ( 'jlourenco.group' , function ( $ app ) { $ config = $ app [ 'config' ] -> get ( 'jlourenco.base' ) ; $ model = array_get ( $ config , 'base.models.Group' ) ; return new IlluminateRoleRepository ( $ model ) ; } ) ; }
Registers the groups .
16,978
protected function registerSettings ( ) { $ this -> app -> singleton ( 'jlourenco.settings' , function ( $ app ) { $ config = $ app [ 'config' ] -> get ( 'jlourenco.base' ) ; $ model = array_get ( $ config , 'models.Settings' ) ; return new SettingsRepository ( $ model ) ; } ) ; }
Registers the settings .
16,979
protected function registerLog ( ) { $ this -> app -> singleton ( 'jlourenco.log' , function ( $ app ) { $ config = $ app [ 'config' ] -> get ( 'jlourenco.base' ) ; $ model = array_get ( $ config , 'models.Logs' ) ; return new LogRepository ( $ model ) ; } ) ; }
Registers the logger .
16,980
protected function registerBase ( ) { $ this -> app -> singleton ( 'base' , function ( $ app ) { $ base = new Base ( $ app [ 'jlourenco.settings' ] , $ app [ 'jlourenco.user' ] , $ app [ 'jlourenco.log' ] , $ app [ 'jlourenco.visits' ] , $ app [ 'jlourenco.jobs' ] ) ; return $ base ; } ) ; $ this -> app -> alias ( 'bas...
Registers base .
16,981
protected function registerToAppConfig ( ) { $ this -> app -> register ( \ Cartalyst \ Sentinel \ Laravel \ SentinelServiceProvider :: class ) ; $ this -> app -> register ( \ TomLingham \ Searchy \ SearchyServiceProvider :: class ) ; $ this -> app -> register ( \ Jenssegers \ Agent \ AgentServiceProvider :: class ) ; $...
Registers this module to the services providers and aliases .
16,982
protected function fixRelations ( array $ data ) : array { $ links = [ ] ; if ( array_key_exists ( 'relations' , $ data ) ) { $ links = array_merge ( $ links , $ data [ 'relations' ] ) ; unset ( $ data [ 'relations' ] ) ; } if ( array_key_exists ( 'actions' , $ data ) ) { $ links = array_merge ( $ links , $ data [ 'act...
Fix relations after normalization
16,983
public function addPath ( $ namespace , $ path , $ prepend = false , $ psr0 = false ) { if ( $ path != '' ) { $ path = rtrim ( str_replace ( '\\' , '/' , $ path ) , '/' ) . '/' ; } if ( $ psr0 ) { $ this -> psr0 = true ; if ( ! isset ( $ this -> psr0Paths [ $ namespace ] ) ) { $ this -> psr0Paths [ $ namespace ] = arra...
Add an autload directory for a namespace .
16,984
public function load ( $ class ) { if ( $ this -> psr0 and $ this -> loadPsr0 ( $ class ) ) { return true ; } $ namespace = '\\' ; $ classPath = str_replace ( '\\' , '/' , $ class ) . '.php' ; while ( true ) { if ( $ this -> loadFrom ( $ classPath , $ namespace ) ) { return true ; } $ pos = strpos ( $ classPath , '/' )...
Attempt to load a class .
16,985
private function hydrateClassObject ( $ obj , $ data ) { foreach ( $ data as $ property => $ value ) { $ this -> hydrate ( $ obj , $ property , $ value ) ; } return $ obj ; }
Hydrate class object .
16,986
protected function onAfterWrite ( ) { parent :: onAfterWrite ( ) ; $ expiredTokens = KapostPreviewToken :: get ( ) -> filter ( 'Created:LessThan' , date ( 'Y-m-d H:i:s' , strtotime ( '-' . KapostService :: config ( ) -> preview_token_expiry . ' minutes' ) ) ) ; if ( $ expiredTokens -> count ( ) > 0 ) { foreach ( $ expi...
Cleans up the expired tokens after writing
16,987
public function getReference ( $ repository , $ attr , $ key = 'id' ) { if ( isset ( $ this -> $ attr ) ) { return ( $ repository -> find ( $ key , $ this -> $ attr ) ? : null ) ; } return null ; }
Retrieve a reference by foreign key .
16,988
public static function createFromPath ( $ path ) { if ( ! file_exists ( $ path ) ) { throw new Exception \ FactoryException ( sprintf ( 'Unable to open file %s' , $ path ) ) ; } $ file = new \ SplFileInfo ( $ path ) ; return static :: createFromSplFileInfo ( $ file ) ; }
Creates an Asset from a file path
16,989
public static function createFromSplFileInfo ( \ SplFileInfo $ file ) { $ asset = new Asset ( ) ; $ guesser = MimeTypeGuesser :: getInstance ( ) ; return $ asset -> setFilename ( $ file -> getFilename ( ) ) -> setExtension ( $ file -> getExtension ( ) ) -> setPathname ( $ file -> getPathname ( ) ) -> setMimeType ( $ gu...
Creates an Asset from a \ SplFileInfo wrapper
16,990
public static function createFromUploadedFile ( UploadedFile $ file ) { $ asset = new Asset ( ) ; $ guesser = MimeTypeGuesser :: getInstance ( ) ; return $ asset -> setFilename ( $ file -> getFilename ( ) ) -> setExtension ( $ file -> getExtension ( ) ) -> setPathname ( $ file -> getPathname ( ) ) -> setMimeType ( $ gu...
Creates an Asset from an UploadedFile instance
16,991
public static function createFromUri ( $ uri ) { $ name = substr ( $ uri , strrpos ( $ uri , '/' ) ) ; $ path = sprintf ( '%s/%s' , sys_get_temp_dir ( ) , $ name ) ; copy ( $ uri , $ path ) ; return static :: createFromPath ( $ path ) ; }
Creates an Asset from a URI
16,992
public function hasType ( Node $ node = null , $ type ) { if ( ! isset ( $ node ) ) return false ; $ type = $ this -> expand ( $ type ) ; $ typesFromNode = $ node -> getType ( ) ; if ( ! isset ( $ typesFromNode ) ) return false ; if ( is_array ( $ typesFromNode ) ) { foreach ( $ typesFromNode as $ t ) if ( is_a ( $ t ,...
Checks whether a node has a certain type .
16,993
public function getFirstValueString ( Node $ node = null , $ property , $ default = null ) { $ valueFromNode = $ this -> getFirstValue ( $ node , $ property , $ default ) ; if ( $ valueFromNode == $ default ) return $ default ; if ( is_a ( $ valueFromNode , 'ML\JsonLD\Node' ) ) return $ valueFromNode -> getId ( ) ; els...
Reads a property from a node and converts it into a string . If the property has multiple values only the first is returned . If no value is found or the node is null the default is returned .
16,994
public function getFirstValueIRI ( Node $ node = null , $ property , IRI $ default = null ) { $ valueFromNode = $ this -> getFirstValue ( $ node , $ property , $ default ) ; if ( $ valueFromNode == $ default ) return $ default ; if ( is_a ( $ valueFromNode , 'ML\JsonLD\Node' ) ) return new IRI ( $ valueFromNode -> getI...
Reads a property from a node and converts it into a IRI . If the property has multiple values only the first is returned . If no value is found value is a literal or the node is null the default is returned .
16,995
public function getFirstValueNode ( Node $ node = null , $ property , Node $ default = null ) { $ valueFromNode = $ this -> getFirstValue ( $ node , $ property , $ default ) ; if ( $ valueFromNode == $ default ) return $ default ; if ( is_a ( $ valueFromNode , 'ML\JsonLD\Node' ) ) return $ valueFromNode ; else return $...
Reads a property from a node and returns it as a Node . If the property has multiple values only the first is returned . If no value is found value is a literal or the node is null the default is returned .
16,996
public function hasPropertyValue ( Node $ node = null , $ property , $ value ) { if ( ! isset ( $ node ) ) return false ; $ valuesFromNode = $ node -> getProperty ( $ this -> expand ( $ property ) ) ; if ( ! isset ( $ valuesFromNode ) ) return false ; if ( ! is_array ( $ valuesFromNode ) ) $ valuesFromNode = array ( $ ...
Checks whether a node has a specific value for a property .
16,997
public function hasProperty ( Node $ node = null , $ property ) { if ( ! isset ( $ node ) ) return false ; return ( $ node -> getProperty ( $ this -> expand ( $ property ) ) != null ) ; }
Checks whether the node has at least one value for a property .
16,998
public function getAllValuesString ( Node $ node = null , $ property ) { $ allValues = $ this -> getAllValues ( $ node , $ property ) ; $ output = [ ] ; foreach ( $ allValues as $ a ) if ( is_a ( $ a , 'ML\JsonLD\Node' ) ) $ output [ ] = $ a -> getId ( ) ; else $ output [ ] = $ a -> getValue ( ) ; return $ output ; }
Reads all values from a node and returns them as a string array .
16,999
public function getAllValuesIRI ( Node $ node = null , $ property ) { $ allValues = $ this -> getAllValues ( $ node , $ property ) ; $ output = [ ] ; foreach ( $ allValues as $ a ) if ( is_a ( $ a , 'ML\JsonLD\Node' ) ) $ output [ ] = new IRI ( $ a -> getId ( ) ) ; return $ output ; }
Reads all values from a node and returns them as a IRI array . Only converts the Node IDs of nodes into IRI literal values are skipped .