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 supported." ) ; } $ hash = hash_hmac ( $ algo , $ this -> rawBody , $ secret ) ; return ( md5 ( $ sig ) === md5 ( $ hash ) ) ; }
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.0722 * pow ( $ B1 / 255 , 2.2 ) ; $ L2 = 0.2126 * pow ( $ R2 / 255 , 2.2 ) + 0.7152 * pow ( $ G2 / 255 , 2.2 ) + 0.0722 * pow ( $ B2 / 255 , 2.2 ) ; if ( $ L1 > $ L2 ) { return ( $ L1 + 0.05 ) / ( $ L2 + 0.05 ) ; } else { return ( $ L2 + 0.05 ) / ( $ L1 + 0.05 ) ; } }
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 ; } return $ formParams ; }
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 ( $ object , 'result_output' ) ) { unset ( $ object -> result_output ) ; } return json_encode ( $ object ) ; }
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 , 'forcelogtrace' => $ forcelogtrace , 'extrainfo' => 'Request info: ' . $ this -> getRequestInformation ( ) ) ) ; $ this -> actionOnError ( $ exception , $ type ) ; if ( $ logonly ) { return true ; } if ( ! $ this -> showwarningmessage && $ type == 'warning' ) { return true ; } if ( ! $ this -> showfatalmessage && $ type == 'fatal' ) { return true ; } $ format = $ this -> getViewFormat ( ) ; if ( $ format != 'html' && $ type == 'fatal' ) { return true ; } switch ( $ format ) { case 'json' : $ this -> showJSON ( $ exception ) ; break ; case 'xml' : $ this -> showXML ( $ exception ) ; break ; case 'http' : $ this -> showHTTP ( $ exception ) ; break ; default : $ this -> showHTML ( $ exception ) ; } die ( ) ; }
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 style="background: #FFCC99;">Unexpected error!</td>' . "\n" . '</tr>' . "\n" . '<tr>' . "\n" . '<td style="padding-top: 15px; padding-bottom: 35px; background: #FFFF99;">' . "\n" . $ this -> getMessageForUser ( $ exception ) . '.<br><br>' . "\n" . 'We are notified and will solve the problem as soon as possible.<br>' . "\n" . '</td>' . "\n" . '</tr>' . "\n" ; if ( $ this -> showtrace ) { $ html .= '<tr>' . "\n" . '<td style="padding-top: 15px; padding-bottom: 35px; background: #FFFF99; white-space: pre ;">' . "\n" . $ exception -> getTraceAsString ( ) . "\n" . '</td>' . "\n" . '</tr>' . "\n" ; } $ html .= '</table>' . "\n" . '</div>' ; return $ html ; }
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>' ; header ( 'Content-Type: application/xml; charset=utf-8' ) ; echo $ xml ; }
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 ) ; $ this -> processError ( $ exception , 'warning' ) ; $ this -> setCatchWarnings ( true ) ; }
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 = substr ( $ postdata , 0 , 250 ) ; } } $ requestinfo = ' ' . getmypid ( ) . "; " . basename ( $ _SERVER [ 'SCRIPT_FILENAME' ] ) . "; " . $ _SERVER [ 'REMOTE_ADDR' ] . "; " . $ _SERVER [ 'REQUEST_METHOD' ] . "; " . $ _SERVER [ 'QUERY_STRING' ] . "; " . $ postdata . "; " . $ _SERVER [ 'HTTP_USER_AGENT' ] . "; " . $ _SERVER [ 'HTTP_REFERER' ] ; return $ requestinfo ; }
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 = strpos ( $ path , '/' ) ; return $ position ? substr ( $ path , 0 , $ position ) : $ path ; }
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!" ) ; } return base64_decode ( $ s ) ; }
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 ; } elseif ( is_scalar ( $ value ) || is_null ( $ value ) ) { $ value = [ ( string ) $ value ] ; } elseif ( ! ( is_array ( $ value ) && $ this -> isValidArrayHeader ( $ value ) ) ) { throw new HTTPException ( 'Invalid header; scalar or one-dimensional array of scalars required' ) ; } if ( isset ( $ this -> ucHeaders [ $ ucField ] ) ) { $ field = $ this -> ucHeaders [ $ ucField ] ; } $ this -> headers [ $ field ] = $ value ; $ this -> ucHeaders [ $ ucField ] = $ field ; return $ this ; }
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 ) ; $ this -> setHeader ( $ field , $ newHeaders ) ; } else { $ this -> setHeader ( $ field , $ value ) ; } return $ this ; }
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 ] ) ; } return $ this ; }
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 [ $ field ] ; } else { throw new HTTPException ( sprintf ( 'Header field is not assigned: %s' , $ field ) ) ; } return isset ( $ result [ 1 ] ) ? $ result : $ result [ 0 ] ; }
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 ) -> get ( ) -> isEmpty ( ) ) ? $ model :: wherePermission ( $ permission ) -> first ( ) : null ; } } return $ objs ; }
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 * $ quantity ; } $ lineItem = $ orderCollection -> addProduct ( $ product , $ quantity ) ; $ em = $ this -> getDoctrine ( ) -> getEntityManager ( ) ; $ em -> persist ( $ lineItem ) ; $ em -> flush ( ) ; if ( $ quantity > 0 ) { $ notice = 'Added ' . $ quantity . ' ' . $ product -> getUnitForNumber ( $ quantity ) . ' of ' . $ product -> getName ( ) . ' to your cart' ; } else { $ quantity = abs ( $ quantity ) ; $ notice = 'Removed ' . $ quantity . ' ' . $ product -> getUnitForNumber ( $ quantity ) . ' of ' . $ product -> getName ( ) . ' from your cart' ; } $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'notice' , $ notice ) ; $ this -> getRequest ( ) -> getSession ( ) -> set ( 'cart_id' , $ orderCollection -> getId ( ) ) ; } catch ( \ Exception $ e ) { } $ last_route = $ request -> get ( 'referer' ) ; if ( in_array ( $ last_route , array ( '_welcome' ) ) ) { return $ this -> redirect ( $ this -> generateUrl ( $ last_route ) ) ; } return $ this -> redirect ( $ this -> generateUrl ( 'Profile_product_show' , array ( 'product_slug' => $ product -> getSlug ( ) , 'slug' => $ product -> getSeller ( ) -> getSlug ( ) , ) ) ) ; }
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 ( ) ; if ( ! empty ( $ data ) ) { $ user -> setUsername ( $ data [ 'username' ] ) ; $ user -> setDisplayName ( empty ( $ data [ 'display_name' ] ) ? $ data [ 'username' ] : $ data [ 'display_name' ] ) ; $ this -> db -> qb ( [ 'table' => 'core_users_groups' , 'fields' => 'id_group' , 'filter' => 'id_user=:id_user' , 'params' => [ ':id_user' => $ user -> getId ( ) ] ] ) ; $ groups = $ this -> db -> column ( ) ; if ( ! empty ( $ groups ) ) { $ user -> groups -> set ( $ groups ) ; $ prepared = $ this -> db -> prepareArrayQuery ( 'group' , $ groups ) ; $ this -> db -> qb ( [ 'table' => 'core_groups_permissions' , 'fields' => [ 'storage' , 'permission' ] , 'method' => 'SELECT DISTINCT' , 'filter' => 'id_group IN (' . $ prepared [ 'sql' ] . ')' , 'params' => $ prepared [ 'values' ] ] ) ; $ permissions = $ this -> db -> all ( ) ; foreach ( $ permissions as $ perm ) { if ( ! array_key_exists ( $ perm [ 'storage' ] , $ user -> permissions ) ) { $ user -> permissions [ $ perm [ 'storage' ] ] = new UserPermissions ( ) ; } $ user -> permissions [ $ perm [ 'storage' ] ] -> add ( $ perm [ 'permission' ] ) ; } if ( ! empty ( $ user -> permissions [ 'Core' ] -> allowedTo ( 'admin' ) ) ) { $ user -> setAdmin ( true ) ; } } } }
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\'"]+)' , 'name-quotes-dble' => '"([^"]*)"' , 'name-quotes-sgle' => "'([^']*)'" , 'name-quotes-none' => '(\w+)' ) ; $ pattern = '/' . implode ( '(?:\s|$)|' , $ patterns ) . '(?:\s|$)/' ; if ( ! preg_match_all ( $ pattern , $ str , $ matches , PREG_SET_ORDER ) ) { return $ attributes ; } foreach ( $ matches as $ match ) { if ( ! empty ( $ match [ 1 ] ) ) { $ attributes [ strtolower ( $ match [ 1 ] ) ] = stripcslashes ( $ match [ 2 ] ) ; } else if ( ! empty ( $ match [ 3 ] ) ) { $ attributes [ $ match [ 3 ] ] = stripcslashes ( $ match [ 4 ] ) ; } else if ( ! empty ( $ match [ 5 ] ) ) { $ attributes [ $ match [ 5 ] ] = stripcslashes ( $ match [ 6 ] ) ; } else if ( ! empty ( $ match [ 7 ] ) && strlen ( $ match [ 7 ] ) ) { $ attributes [ ] = stripcslashes ( $ match [ 7 ] ) ; } else if ( ! empty ( $ match [ 8 ] ) ) { $ attributes [ ] = stripcslashes ( $ match [ 8 ] ) ; } else if ( ! empty ( $ match [ 9 ] ) ) { $ attributes [ ] = stripcslashes ( $ match [ 9 ] ) ; } } return $ attributes ; }
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 -> _replaceTranslate ( $ str ) ; $ str = $ this -> _replaceUrl ( $ str ) ; $ str = $ this -> _replaceImage ( $ str ) ; $ str = $ this -> _replaceLink ( $ str ) ; $ str = $ this -> _replaceTruncate ( $ str ) ; return $ str ; }
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' ] && false !== $ thOptions [ 'sort' ] ) { if ( is_bool ( $ thOptions [ 'sort' ] ) ) { $ thOptions [ 'sort' ] = $ name ; } if ( is_string ( $ thOptions [ 'sort' ] ) ) { $ thOptions [ 'sort' ] = array ( 'key' => $ thOptions [ 'sort' ] ) ; } $ thOptions [ 'sort' ] = array_merge ( array ( 'options' => array ( ) ) , $ thOptions [ 'sort' ] ) ; $ name = $ this -> Paginator -> sort ( $ thOptions [ 'sort' ] [ 'key' ] , $ name , $ thOptions [ 'sort' ] [ 'options' ] ) ; } $ th [ ] = $ this -> Html -> useTag ( 'tableheader' , $ this -> _parseAttributes ( $ thOptions [ 'th' ] ) , $ name ) ; } return sprintf ( "\t<%s>\n\t\t%s\n\t</%s>" , $ tag , $ this -> Html -> useTag ( 'tablerow' , null , "\n\t\t\t" . implode ( "\n\t\t\t" , $ th ) . "\n\t\t" ) , $ tag ) ; }
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 = $ paginate [ 'prev' ] ; $ next = $ paginate [ 'next' ] ; $ this -> Paginator -> options ( $ paginate [ 'attrs' ] ) ; $ after = false !== $ paginate [ 'divOptions' ] ? "\n\t" : "\n\t\t\t" ; $ glue = false !== $ paginate [ 'divOptions' ] ? "\n\t" : "\n\t\t\t" ; $ before = '' ; if ( CakePlugin :: loaded ( 'TwitterBootstrap' ) ) { $ glue .= "\t" ; $ before .= "\n" ; $ paginate [ 'numbers' ] [ 'separator' ] = $ after . "\t" ; $ prev [ 'options' ] [ 'disabled' ] = $ prev [ 'disabledOptions' ] [ 'class' ] ; $ next [ 'options' ] [ 'disabled' ] = $ next [ 'disabledOptions' ] [ 'class' ] ; } $ out [ ] = $ this -> Paginator -> prev ( $ prev [ 'title' ] , $ prev [ 'options' ] , $ prev [ 'disabledTitle' ] , $ prev [ 'disabledOptions' ] ) ; $ out [ ] = $ this -> Paginator -> numbers ( $ paginate [ 'numbers' ] ) ; $ out [ ] = $ this -> Paginator -> next ( $ next [ 'title' ] , $ next [ 'options' ] , $ next [ 'disabledTitle' ] , $ next [ 'disabledOptions' ] ) ; $ out = $ glue . implode ( $ glue , $ out ) ; if ( CakePlugin :: loaded ( 'TwitterBootstrap' ) || CakePlugin :: loaded ( 'BoostCake' ) ) { if ( ! isset ( $ paginate [ 'ulOptions' ] ) ) { $ paginate [ 'ulOptions' ] = array ( 'class' => 'pagination' ) ; } $ out = $ this -> Html -> tag ( 'ul' , $ out . $ after , $ paginate [ 'ulOptions' ] ) ; } if ( false !== $ paginate [ 'divOptions' ] ) { return $ this -> Html -> useTag ( 'block' , $ this -> _parseAttributes ( $ paginate [ 'divOptions' ] ) , $ before . "\t" . $ out . "\n" ) ; } return "\t" . $ this -> Html -> useTag ( 'tablerow' , $ this -> _parseAttributes ( $ paginate [ 'trOptions' ] ) , "\n\t\t" . $ this -> Html -> useTag ( 'tablecell' , $ this -> _parseAttributes ( array_merge ( $ paginate [ 'tdOptions' ] , array ( 'colspan' => count ( $ options [ 'columns' ] ) ) ) ) , $ before . "\t\t\t" . $ out . "\n\t\t" ) . "\n\t" ) ; }
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 -> _extractAttributes ( trim ( $ matches [ 1 ] [ $ i ] ) ) ; $ currency = CakeNumber :: defaultCurrency ( ) ; if ( isset ( $ opts [ 'currency' ] ) ) { $ currency = $ opts [ 'currency' ] ; unset ( $ opts [ 'currency' ] ) ; } $ replace = ( empty ( $ matches [ 2 ] [ $ i ] ) || ! is_numeric ( $ matches [ 2 ] [ $ i ] ) ) ? '' : CakeNumber :: currency ( $ matches [ 2 ] [ $ i ] , $ currency , $ opts ) ; $ str = str_replace ( $ find , $ replace , $ str ) ; } return $ str ; }
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 ( trim ( $ matches [ 1 ] [ $ i ] ) ) ; foreach ( Hash :: normalize ( array ( 'method' => 'nice' , 'format' , 'timezone' ) ) as $ k => $ v ) { $ { $ k } = $ v ; if ( isset ( $ opts [ $ k ] ) ) { $ { $ k } = $ opts [ $ k ] ; unset ( $ opts [ $ k ] ) ; } } App :: uses ( 'CakeTime' , 'Utility' ) ; $ replace = ( empty ( $ matches [ 2 ] [ $ i ] ) ) ? '' : CakeTime :: $ method ( $ matches [ 2 ] [ $ i ] , $ timezone , $ format ) ; $ str = str_replace ( $ find , $ replace , $ str ) ; } return $ str ; }
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' , $ str , $ matches ) ) { foreach ( $ matches [ 0 ] as $ i => $ find ) { $ str = str_replace ( $ find , I18n :: translate ( $ matches [ 2 ] [ $ i ] , null , $ matches [ 1 ] [ $ i ] ) , $ str ) ; } } if ( preg_match_all ( '/\[__c\|(.+?)\](.*?)\[\/__c\]/i' , $ str , $ matches ) ) { foreach ( $ matches [ 0 ] as $ i => $ find ) { $ str = str_replace ( $ find , I18n :: translate ( $ matches [ 2 ] [ $ i ] , null , null , $ matches [ 1 ] [ $ i ] ) , $ str ) ; } } return $ str ; }
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 ) ) ; $ response -> headers -> set ( 'Content-Disposition' , 'attachment;filename="' . ( $ fileName ? : basename ( $ filePath ) ) . '"' ) ; $ response -> headers -> set ( 'Content-Length' , filesize ( $ filePath ) ) ; $ response -> setContent ( file_get_contents ( $ filePath ) ) ; return $ response ; }
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 ( $ form -> getData ( ) , $ form ) ; if ( $ response instanceof Response ) return $ response ; } } } return $ form -> createView ( ) ; }
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' => 'Update' ) ) ; return $ form ; }
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 :: getValue ( $ rule ) ; self :: $ validator -> rule ( $ value [ 'rule' ] , $ columns , $ value [ 'value' ] ) ; } return new ValidationResult ( self :: $ validator ) ; }
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 -> addDefaultChildren ) { if ( $ this -> default ) { throw new InvalidDefinitionException ( sprintf ( 'A default value and default children might not be used together at path "%s"' , $ path ) ) ; } if ( null !== $ this -> key && ( null === $ this -> addDefaultChildren || is_int ( $ this -> addDefaultChildren ) && $ this -> addDefaultChildren > 0 ) ) { throw new InvalidDefinitionException ( sprintf ( '->addDefaultChildrenIfNoneSet() should set default children names as ->useAttributeAsKey() is used at path "%s"' , $ path ) ) ; } if ( null === $ this -> key && ( is_string ( $ this -> addDefaultChildren ) || is_array ( $ this -> addDefaultChildren ) ) ) { throw new InvalidDefinitionException ( sprintf ( '->addDefaultChildrenIfNoneSet() might not set default children names as ->useAttributeAsKey() is not used at path "%s"' , $ path ) ) ; } } }
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_" . floor ( rand ( 0 , 1000 ) ) ) ; } }
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 ( $ reflection -> getNamespaceName ( ) . '\\' , '' , $ reflection -> getName ( ) ) ; $ this -> chain [ $ name ] = $ v ; } elseif ( \ is_string ( $ k ) && \ is_array ( $ v ) ) { $ className = '\\MS\\LightFramework\\Validator\\Specific\\' . $ k ; if ( ! \ class_exists ( $ className ) ) { throw new InvalidArgumentException ( 'Validator "' . $ k . '" not found' ) ; } $ this -> chain [ $ k ] = new $ className ( $ v ) ; } elseif ( \ is_numeric ( $ k ) && \ is_array ( $ v ) ) { $ this -> parseChain ( $ v ) ; } else { $ exMsg = 'Validator chain element must be either instance of AbstractValidator ' ; $ exMsg .= 'or array("validatorName" => array(options))' ; throw new InvalidArgumentException ( $ exMsg ) ; } } }
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 ) { $ options [ ] = \ sprintf ( '\'%s\'=>%s' , $ optionName , $ this -> parseOptionValue ( $ optionVal ) ) ; } $ chain [ ] = \ sprintf ( '%s [%s]' , $ validatorName , \ implode ( ', ' , $ options ) ) ; } else { $ chain [ ] = $ validatorName ; } } return \ implode ( ",\n" , $ chain ) ; }
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 :: createFromFormat ( $ format , date ( $ format , filemtime ( $ file ) ) ) ; return $ dateTime ; }
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 [ $ file ] ) ) { if ( is_readable ( $ file ) ) { $ this -> _instance [ $ file ] = require ( $ file ) ; } else if ( $ this -> _envPrefix and $ file = $ filePath . str_replace ( '-' , DS , $ pFileStr ) . self :: EXT and is_readable ( $ file ) ) { $ this -> _instance [ $ file ] = require ( $ file ) ; } else { $ this -> _instance [ $ file ] = array ( ) ; } } return $ this -> _instance [ $ file ] ; }
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 $ file ) { $ content [ self :: MAIN_EVENTS_FILE ] = array_merge_recursive ( require ( $ file ) , $ content [ self :: MAIN_EVENTS_FILE ] ) ; } return $ content ; }
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 = $ this -> _getInstance ( $ pathArr [ 0 ] ) ; } if ( $ path ) { $ pathArr = explode ( '/' , $ path ) ; $ nbKeys = count ( $ pathArr ) - 1 ; foreach ( $ pathArr as $ i => $ key ) { $ key = str_replace ( '#' , '/' , $ key ) ; if ( ! isset ( $ content [ $ key ] ) ) { $ this -> _cache [ $ pPath ] = NULL ; break ; } else if ( $ i < $ nbKeys ) { $ content = $ content [ $ key ] ; } else if ( $ i == $ nbKeys ) { $ this -> _cache [ $ pPath ] = $ content [ $ key ] ; } } } else { $ this -> _cache [ $ pPath ] = $ content ; } if ( $ pForceGlobalArray and ( ! is_array ( $ this -> _cache [ $ pPath ] ) or ( is_array ( $ this -> _cache [ $ pPath ] ) and ! array_key_exists ( 0 , $ this -> _cache [ $ pPath ] ) ) ) ) { $ this -> _cache [ $ pPath ] = array ( $ this -> _cache [ $ pPath ] ) ; } return $ this -> _cache [ $ pPath ] ; }
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 :: getCache ( ) ; } if ( $ this -> _cacheInstance -> has ( 'config.' . $ pPath ) ) { $ this -> _cache [ $ pPath ] = $ this -> _cacheInstance -> get ( 'config.' . $ pPath ) ; return $ this -> _cache [ $ pPath ] ; } } $ this -> _cache [ $ pPath ] = $ this -> _getConfigValues ( $ pPath , $ pForceGlobalArray ) ; if ( $ this -> _cacheInstance !== NULL ) { $ this -> _cacheInstance -> set ( 'config.' . $ pPath , $ this -> _cache [ $ pPath ] ) ; } return $ this -> _cache [ $ pPath ] ; }
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 $ error ; }
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_disable_entity_loader ( $ backup ) ; break ; case 'application/x-www-form-urlencoded' : case 'multipart/form-data' : parse_str ( $ data , $ parsedData ) ; break ; default : $ parsedData = null ; break ; } return $ parsedData ; }
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 ( 'base' , 'jlourenco\base\Base' ) ; }
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 ) ; $ this -> app -> register ( \ Torann \ GeoIP \ GeoIPServiceProvider :: class ) ; $ loader = \ Illuminate \ Foundation \ AliasLoader :: getInstance ( ) ; $ loader -> alias ( 'Schema' , 'jlourenco\support\Database\Schema' ) ; $ loader -> alias ( 'Activation' , 'Cartalyst\Sentinel\Laravel\Facades\Activation' ) ; $ loader -> alias ( 'Reminder' , 'Cartalyst\Sentinel\Laravel\Facades\Reminder' ) ; $ loader -> alias ( 'Sentinel' , 'Cartalyst\Sentinel\Laravel\Facades\Sentinel' ) ; $ loader -> alias ( 'Datatables' , 'yajra\Datatables\Datatables' ) ; $ loader -> alias ( 'SentinelUser' , 'App\Http\Middleware\SentinelUser' ) ; $ loader -> alias ( 'Base' , 'jlourenco\base\Facades\Base' ) ; $ loader -> alias ( 'Searchy' , 'TomLingham\Searchy\Facades\Searchy' ) ; $ loader -> alias ( 'Agent' , 'Jenssegers\Agent\Facades\Agent' ) ; $ loader -> alias ( 'GeoIP' , 'Torann\GeoIP\GeoIPFacade' ) ; }
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 [ 'actions' ] ) ; unset ( $ data [ 'actions' ] ) ; } if ( count ( $ links ) ) { $ data [ '_links' ] = $ links ; } return $ data ; }
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 ] = array ( ) ; } if ( $ prepend ) { array_unshift ( $ this -> psr0Paths [ $ namespace ] , $ path ) ; } else { array_push ( $ this -> psr0Paths [ $ namespace ] , $ path ) ; } } else { $ namespace = '\\' . trim ( $ namespace , '\\' ) ; if ( ! isset ( $ this -> paths [ $ namespace ] ) ) { $ this -> paths [ $ namespace ] = array ( ) ; } if ( $ prepend ) { array_unshift ( $ this -> paths [ $ namespace ] , $ path ) ; } else { array_push ( $ this -> paths [ $ namespace ] , $ path ) ; } } }
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 , '/' ) ; if ( $ pos === false ) { if ( ! $ this -> psr0 ) { break ; } $ pos = strpos ( $ classPath , '_' ) ; if ( $ pos === false ) { break ; } } $ namespace = rtrim ( $ namespace , '\\' ) . '\\' . substr ( $ classPath , 0 , $ pos ) ; $ classPath = substr ( $ classPath , $ pos + 1 ) ; } return false ; }
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 ( $ expiredTokens as $ token ) { $ token -> delete ( ) ; } } }
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 ( $ guesser -> guess ( $ file -> getPathname ( ) ) ) -> setClientOriginalName ( $ file -> getFilename ( ) ) -> setClientOriginalExtension ( $ file -> getExtension ( ) ) ; }
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 ( $ guesser -> guess ( $ file -> getPathname ( ) ) ) -> setClientOriginalName ( $ file -> getClientOriginalName ( ) ) -> setClientOriginalExtension ( $ file -> getClientOriginalExtension ( ) ) -> setClientMimeType ( $ file -> getClientMimeType ( ) ) ; }
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 , 'ML\JsonLD\Node' ) && $ t -> getId ( ) == $ type ) return true ; } else if ( is_a ( $ typesFromNode , 'ML\JsonLD\Node' ) && $ typesFromNode -> getId ( ) == $ type ) return true ; else return false ; return false ; }
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 ( ) ; else return $ valueFromNode -> getValue ( ) ; }
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 -> getId ( ) ) ; else return $ default ; }
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 $ default ; }
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 ( $ valuesFromNode ) ; foreach ( $ valuesFromNode as $ v ) { if ( is_a ( $ v , 'ML\JsonLD\Node' ) ) { if ( $ v -> getId ( ) == $ this -> expand ( $ value ) ) return true ; } else { if ( $ v -> getValue ( ) == $ value ) return true ; } } return false ; }
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 .