idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
25,200
function ARC4 ( $ text ) { $ len = mb_strlen ( $ text , '8bit' ) ; $ a = 0 ; $ b = 0 ; $ c = $ this -> arc4 ; $ out = '' ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ a = ( $ a + 1 ) % 256 ; $ t = $ c [ $ a ] ; $ b = ( $ b + ord ( $ t ) ) % 256 ; $ c [ $ a ] = $ c [ $ b ] ; $ c [ $ b ] = $ t ; $ k = ord ( $ c [ ( ord ( ...
ARC4 encrypt a text string
25,201
function addLink ( $ url , $ x0 , $ y0 , $ x1 , $ y1 ) { $ this -> numObj ++ ; $ info = array ( 'type' => 'link' , 'url' => $ url , 'rect' => array ( $ x0 , $ y0 , $ x1 , $ y1 ) ) ; $ this -> o_annotation ( $ this -> numObj , 'new' , $ info ) ; }
add a link in the document to an external URL
25,202
function setColor ( $ color , $ force = false ) { $ new_color = array ( $ color [ 0 ] , $ color [ 1 ] , $ color [ 2 ] , isset ( $ color [ 3 ] ) ? $ color [ 3 ] : null ) ; if ( ! $ force && $ this -> currentColor == $ new_color ) { return ; } if ( isset ( $ new_color [ 3 ] ) ) { $ this -> currentColor = $ new_color ; $ ...
sets the color for fill operations
25,203
function setStrokeColor ( $ color , $ force = false ) { $ new_color = array ( $ color [ 0 ] , $ color [ 1 ] , $ color [ 2 ] , isset ( $ color [ 3 ] ) ? $ color [ 3 ] : null ) ; if ( ! $ force && $ this -> currentStrokeColor == $ new_color ) { return ; } if ( isset ( $ new_color [ 3 ] ) ) { $ this -> currentStrokeColor ...
sets the color for stroke operations
25,204
function filledRectangle ( $ x1 , $ y1 , $ width , $ height ) { $ this -> addContent ( sprintf ( "\n%.3F %.3F %.3F %.3F re f" , $ x1 , $ y1 , $ width , $ height ) ) ; }
a filled rectangle note that it is the width and height of the rectangle which are the secondary parameters not the coordinates of the upper - right corner
25,205
function clippingRectangleRounded ( $ x1 , $ y1 , $ w , $ h , $ rTL , $ rTR , $ rBR , $ rBL ) { $ this -> save ( ) ; $ this -> addContent ( sprintf ( "\n%.3F %.3F m " , $ x1 , $ y1 - $ rTL + $ h ) ) ; $ this -> addContent ( sprintf ( "\n%.3F %.3F l " , $ x1 , $ y1 + $ rBL ) ) ; $ this -> ellipse ( $ x1 + $ rBL , $ y1 +...
draw a clipping rounded rectangle all the elements added after this will be clipped
25,206
function newPage ( $ insert = 0 , $ id = 0 , $ pos = 'after' ) { if ( $ this -> nStateStack ) { for ( $ i = $ this -> nStateStack ; $ i >= 1 ; $ i -- ) { $ this -> restoreState ( $ i ) ; } } $ this -> numObj ++ ; if ( $ insert ) { $ rid = $ this -> objects [ $ id ] [ 'onPage' ] ; $ opt = array ( 'rid' => $ rid , 'pos' ...
add a new page to the document this also makes the new page the current active object
25,207
function getFontDescender ( $ size ) { if ( ! $ this -> numFonts ) { $ this -> selectFont ( $ this -> defaultFont ) ; } $ h = $ this -> fonts [ $ this -> currentFont ] [ 'Descender' ] ; return $ size * $ h / 1000 ; }
return the font descender this will normally return a negative number if you add this number to the baseline you get the level of the bottom of the font it is in the pdf user units
25,208
static public function parse ( $ text , $ builder = null ) { $ tokenizer = new HTML5_Tokenizer ( $ text , $ builder ) ; $ tokenizer -> parse ( ) ; return $ tokenizer -> save ( ) ; }
Parses a full HTML document .
25,209
static public function parseFragment ( $ text , $ context = null , $ builder = null ) { $ tokenizer = new HTML5_Tokenizer ( $ text , $ builder ) ; $ tokenizer -> parseFragment ( $ context ) ; return $ tokenizer -> save ( ) ; }
Parses an HTML fragment .
25,210
private function printStack ( ) { $ names = array ( ) ; foreach ( $ this -> stack as $ i => $ element ) { $ names [ ] = $ element -> tagName ; } echo " -> stack [" . implode ( ', ' , $ names ) . "]\n" ; }
For debugging prints the stack
25,211
private function printActiveFormattingElements ( ) { if ( ! $ this -> a_formatting ) { return ; } $ names = array ( ) ; foreach ( $ this -> a_formatting as $ node ) { if ( $ node === self :: MARKER ) { $ names [ ] = 'MARKER' ; } else { $ names [ ] = $ node -> tagName ; } } echo " -> active formatting [" . implode ( ',...
For debugging prints active formatting elements
25,212
public function setupContext ( $ context = null ) { $ this -> fragment = true ; if ( $ context ) { $ context = $ this -> dom -> createElementNS ( self :: NS_HTML , $ context ) ; switch ( $ context -> tagName ) { case 'title' : case 'textarea' : $ this -> content_model = HTML5_Tokenizer :: RCDATA ; break ; case 'style' ...
Sets up the tree constructor for building a fragment .
25,213
protected function _close ( ) { $ this -> _place_objects ( ) ; $ this -> _pdf -> suspend_page ( "" ) ; for ( $ p = 1 ; $ p <= $ this -> _page_count ; $ p ++ ) { $ this -> _pdf -> resume_page ( "pagenumber=$p" ) ; $ this -> _pdf -> end_page_ext ( "" ) ; } $ this -> _pdf -> end_document ( "" ) ; }
Close the pdf
25,214
public function _set_gstate ( $ gstate_options ) { if ( ( $ gstate = array_search ( $ gstate_options , $ this -> _gstates ) ) === false ) { $ gstate = $ this -> _pdf -> create_gstate ( $ gstate_options ) ; $ this -> _gstates [ $ gstate ] = $ gstate_options ; } return $ this -> _pdf -> set_gstate ( $ gstate ) ; }
Sets the gstate
25,215
public function page_line ( $ x1 , $ y1 , $ x2 , $ y2 , $ color , $ width , $ style = array ( ) ) { $ _t = 'line' ; $ this -> _page_text [ ] = compact ( '_t' , 'x1' , 'y1' , 'x2' , 'y2' , 'color' , 'width' , 'style' ) ; }
Draw line at the specified coordinates on every page .
25,216
public function build_tree ( ) { $ html = $ this -> _dom -> getElementsByTagName ( "html" ) -> item ( 0 ) ; if ( is_null ( $ html ) ) { $ html = $ this -> _dom -> firstChild ; } if ( is_null ( $ html ) ) { throw new Exception ( "Requested HTML document contains no data." ) ; } $ this -> fix_tables ( ) ; $ this -> _root...
Builds the tree
25,217
protected function _remove_node ( DOMNode $ node , array & $ children , $ index ) { $ child = $ children [ $ index ] ; $ previousChild = $ child -> previousSibling ; $ nextChild = $ child -> nextSibling ; $ node -> removeChild ( $ child ) ; if ( isset ( $ previousChild , $ nextChild ) ) { if ( $ previousChild -> nodeNa...
Remove a child from a node
25,218
public function charsUntil ( $ bytes , $ max = null ) { if ( $ this -> char < $ this -> EOF ) { if ( $ max === 0 || $ max ) { $ len = strcspn ( $ this -> data , $ bytes , $ this -> char , $ max ) ; } else { $ len = strcspn ( $ this -> data , $ bytes , $ this -> char ) ; } $ string = ( string ) substr ( $ this -> data ,...
Matches as far as possible until we reach a certain set of bytes and returns the matched substring .
25,219
public function charsWhile ( $ bytes , $ max = null ) { if ( $ this -> char < $ this -> EOF ) { if ( $ max === 0 || $ max ) { $ len = strspn ( $ this -> data , $ bytes , $ this -> char , $ max ) ; } else { $ len = strspn ( $ this -> data , $ bytes , $ this -> char ) ; } $ string = ( string ) substr ( $ this -> data , $...
Matches as far as possible with a certain set of bytes and returns the matched substring .
25,220
public function remove_row_group ( Frame $ group ) { $ key = $ group -> get_id ( ) ; if ( ! isset ( $ this -> _frames [ $ key ] ) ) { return ; } $ iter = $ group -> get_first_child ( ) ; while ( $ iter ) { $ this -> remove_row ( $ iter ) ; $ iter = $ iter -> get_next_sibling ( ) ; } $ this -> _frames [ $ key ] = null ;...
Remove a row group from the cellmap .
25,221
public function update_row_group ( Frame $ group , Frame $ last_row ) { $ g_key = $ group -> get_id ( ) ; $ r_key = $ last_row -> get_id ( ) ; $ r_rows = $ this -> _frames [ $ g_key ] [ "rows" ] ; $ this -> _frames [ $ g_key ] [ "rows" ] = range ( $ this -> _frames [ $ g_key ] [ "rows" ] [ 0 ] , end ( $ r_rows ) ) ; }
Update a row group after rows have been removed
25,222
public function image ( $ img_url , $ x , $ y , $ w , $ h , $ resolution = "normal" ) { $ img_type = Cache :: detect_type ( $ img_url , $ this -> get_dompdf ( ) -> getHttpContext ( ) ) ; if ( ! $ img_type ) { return ; } $ func_name = "imagecreatefrom$img_type" ; if ( ! function_exists ( $ func_name ) ) { if ( ! method_...
Add an image to the pdf . The image is placed at the specified x and y coordinates with the given width and height .
25,223
public function stream ( $ filename , $ options = array ( ) ) { if ( headers_sent ( ) ) { die ( "Unable to stream image: headers already sent" ) ; } if ( ! isset ( $ options [ "type" ] ) ) $ options [ "type" ] = "png" ; if ( ! isset ( $ options [ "Attachment" ] ) ) $ options [ "Attachment" ] = true ; $ type = strtolowe...
Streams the image to the client .
25,224
private function _output ( $ options = array ( ) ) { if ( ! isset ( $ options [ "type" ] ) ) $ options [ "type" ] = "png" ; if ( ! isset ( $ options [ "page" ] ) ) $ options [ "page" ] = 1 ; $ type = strtolower ( $ options [ "type" ] ) ; if ( isset ( $ this -> _imgs [ $ options [ "page" ] - 1 ] ) ) { $ img = $ this -> ...
Outputs the image stream directly .
25,225
public static function dec2roman ( $ num ) { static $ ones = array ( "" , "i" , "ii" , "iii" , "iv" , "v" , "vi" , "vii" , "viii" , "ix" ) ; static $ tens = array ( "" , "x" , "xx" , "xxx" , "xl" , "l" , "lx" , "lxx" , "lxxx" , "xc" ) ; static $ hund = array ( "" , "c" , "cc" , "ccc" , "cd" , "d" , "dc" , "dcc" , "dccc...
Converts decimal numbers to roman numerals
25,226
public static function dompdf_debug ( $ type , $ msg ) { global $ _DOMPDF_DEBUG_TYPES , $ _dompdf_show_warnings , $ _dompdf_debug ; if ( isset ( $ _DOMPDF_DEBUG_TYPES [ $ type ] ) && ( $ _dompdf_show_warnings || $ _dompdf_debug ) ) { $ arr = debug_backtrace ( ) ; echo basename ( $ arr [ 0 ] [ "file" ] ) . " (" . $ arr ...
Print debug messages
25,227
public static function cmyk_to_rgb ( $ c , $ m = null , $ y = null , $ k = null ) { if ( is_array ( $ c ) ) { list ( $ c , $ m , $ y , $ k ) = $ c ; } $ c *= 255 ; $ m *= 255 ; $ y *= 255 ; $ k *= 255 ; $ r = ( 1 - round ( 2.55 * ( $ c + $ k ) ) ) ; $ g = ( 1 - round ( 2.55 * ( $ m + $ k ) ) ) ; $ b = ( 1 - round ( 2.5...
Converts a CMYK color to RGB
25,228
public static function dompdf_getimagesize ( $ filename , $ context = null ) { static $ cache = array ( ) ; if ( isset ( $ cache [ $ filename ] ) ) { return $ cache [ $ filename ] ; } list ( $ width , $ height , $ type ) = getimagesize ( $ filename ) ; $ types = array ( IMAGETYPE_JPEG => "jpeg" , IMAGETYPE_GIF => "gif"...
getimagesize doesn t give a good size for 32bit BMP image v5
25,229
protected function _set_stroke_color ( $ color ) { $ this -> _pdf -> setStrokeColor ( $ color ) ; $ alpha = isset ( $ color [ "alpha" ] ) ? $ color [ "alpha" ] : 1 ; if ( $ this -> _current_opacity != 1 ) { $ alpha *= $ this -> _current_opacity ; } $ this -> _set_line_transparency ( "Normal" , $ alpha ) ; }
Sets the stroke color
25,230
protected function _convert_gif_bmp_to_png ( $ image_url , $ type ) { $ func_name = "imagecreatefrom$type" ; if ( ! function_exists ( $ func_name ) ) { if ( ! method_exists ( "Dompdf\Helpers" , $ func_name ) ) { throw new Exception ( "Function $func_name() not found. Cannot convert $type image: $image_url. Please ins...
Convert a GIF or BMP image to a PNG image
25,231
protected function _calculate_content_height ( ) { $ height = 0 ; $ lines = $ this -> _frame -> get_line_boxes ( ) ; if ( count ( $ lines ) > 0 ) { $ last_line = end ( $ lines ) ; $ content_box = $ this -> _frame -> get_content_box ( ) ; $ height = $ last_line -> y + $ last_line -> h - $ content_box [ "y" ] ; } return ...
Determine the unrestricted height of content within the block not by adding each line s height but by getting the last line s position . This because lines could have been pushed lower by a clearing element .
25,232
function lookup ( $ key ) { if ( ! isset ( $ this -> _styles [ $ key ] ) ) { return null ; } return $ this -> _styles [ $ key ] ; }
lookup a specific Style collection
25,233
function load_css ( & $ css , $ origin = self :: ORIG_AUTHOR ) { if ( $ origin ) { $ this -> _current_origin = $ origin ; } $ this -> _parse_css ( $ css ) ; }
load and parse a CSS string
25,234
function load_css_file ( $ file , $ origin = self :: ORIG_AUTHOR ) { if ( $ origin ) { $ this -> _current_origin = $ origin ; } if ( isset ( $ this -> _loaded_files [ $ file ] ) ) { return ; } $ this -> _loaded_files [ $ file ] = true ; if ( strpos ( $ file , "data:" ) === 0 ) { $ parsed = Helpers :: parse_data_uri ( $...
load and parse a CSS file
25,235
private function _parse_sections ( $ str , $ media_queries = array ( ) ) { $ patterns = array ( "/[\\s\n]+/" , "/\\s+([>.:+#])\\s+/" ) ; $ replacements = array ( " " , "\\1" ) ; $ str = preg_replace ( $ patterns , $ replacements , $ str ) ; $ DEBUGCSS = $ this -> _dompdf -> getOptions ( ) -> getDebugCss ( ) ; $ section...
parse selector + rulesets
25,236
public function get_floats_inside ( Page $ root ) { $ floating_frames = $ root -> get_floating_frames ( ) ; if ( count ( $ floating_frames ) == 0 ) { return $ floating_frames ; } $ p = $ this -> _block_frame ; while ( $ p -> get_style ( ) -> float === "none" ) { $ parent = $ p -> get_parent ( ) ; if ( ! $ parent ) { br...
Returns the floating elements inside the first floating parent
25,237
public function recalculate_width ( ) { $ width = 0 ; foreach ( $ this -> get_frames ( ) as $ frame ) { $ width += $ frame -> calculate_auto_width ( ) ; } return $ this -> w = $ width ; }
Recalculate LineBox width based on the contained frames total width .
25,238
function get_font_size ( ) { if ( $ this -> __font_size_calculated ) { return $ this -> _props [ "font_size" ] ; } if ( ! isset ( $ this -> _props [ "font_size" ] ) ) { $ fs = self :: $ _defaults [ "font_size" ] ; } else { $ fs = $ this -> _props [ "font_size" ] ; } if ( ! isset ( $ this -> _parent_font_size ) ) { $ th...
Returns the resolved font size in points
25,239
function get_background_position ( ) { $ tmp = explode ( " " , $ this -> _props [ "background_position" ] ) ; switch ( $ tmp [ 0 ] ) { case "left" : $ x = "0%" ; break ; case "right" : $ x = "100%" ; break ; case "top" : $ y = "0%" ; break ; case "bottom" : $ y = "100%" ; break ; case "center" : $ x = "50%" ; $ y = "50...
Returns the background position as an array
25,240
protected function _get_border ( $ side ) { $ color = $ this -> __get ( "border_" . $ side . "_color" ) ; return $ this -> __get ( "border_" . $ side . "_width" ) . " " . $ this -> __get ( "border_" . $ side . "_style" ) . " " . $ color [ "hex" ] ; }
Return a single border property
25,241
function get_outline_color ( ) { if ( $ this -> _props [ "outline_color" ] === "" ) { $ this -> _prop_cache [ "outline_color" ] = null ; $ this -> _props [ "outline_color" ] = $ this -> __get ( "color" ) ; } return $ this -> munge_color ( $ this -> _props [ "outline_color" ] ) ; }
Returns the outline color as an array
25,242
function get_border_spacing ( ) { $ arr = explode ( " " , $ this -> _props [ "border_spacing" ] ) ; if ( count ( $ arr ) == 1 ) { $ arr [ 1 ] = $ arr [ 0 ] ; } return $ arr ; }
Returns border spacing as an array
25,243
function set_background_color ( $ color ) { $ col = $ this -> munge_color ( $ color ) ; if ( is_null ( $ col ) ) { return ; } $ this -> _prop_cache [ "background_color" ] = null ; $ this -> _props [ "background_color" ] = is_array ( $ col ) ? $ col [ "hex" ] : $ col ; }
Sets the background color
25,244
function set_background_repeat ( $ val ) { if ( is_null ( $ val ) ) { $ val = self :: $ _defaults [ "background_repeat" ] ; } $ this -> _prop_cache [ "background_repeat" ] = null ; $ this -> _props [ "background_repeat" ] = $ val ; }
Sets the background repeat
25,245
function set_background ( $ val ) { $ val = trim ( $ val ) ; $ important = isset ( $ this -> _important_props [ "background" ] ) ; if ( $ val === "none" ) { $ this -> _set_style ( "background_image" , "none" , $ important ) ; $ this -> _set_style ( "background_color" , "transparent" , $ important ) ; } else { $ pos = a...
Sets the background - combined options
25,246
function set_font_size ( $ size ) { $ this -> __font_size_calculated = false ; $ this -> _prop_cache [ "font_size" ] = null ; $ this -> _props [ "font_size" ] = $ size ; }
Sets the font size
25,247
function set_outline ( $ val ) { $ important = isset ( $ this -> _important_props [ "outline" ] ) ; $ props = array ( "outline_style" , "outline_width" , "outline_color" , ) ; foreach ( $ props as $ prop ) { $ _val = self :: $ _defaults [ $ prop ] ; if ( ! isset ( $ this -> _important_props [ $ prop ] ) || $ important ...
Sets the outline styles
25,248
function set_border_spacing ( $ val ) { $ arr = explode ( " " , $ val ) ; if ( count ( $ arr ) == 1 ) { $ arr [ 1 ] = $ arr [ 0 ] ; } $ this -> _prop_cache [ "border_spacing" ] = null ; $ this -> _props [ "border_spacing" ] = "$arr[0] $arr[1]" ; }
Sets the border spacing
25,249
function set_list_style_image ( $ val ) { $ this -> _prop_cache [ "list_style_image" ] = null ; $ this -> _props [ "list_style_image" ] = $ this -> _image ( $ val ) ; }
Sets the list style image
25,250
function get_transform_origin ( ) { $ values = preg_split ( "/\s+/" , $ this -> _props [ 'transform_origin' ] ) ; if ( count ( $ values ) === 0 ) { $ values = preg_split ( "/\s+/" , self :: $ _defaults [ "transform_origin" ] ) ; } $ values = array_map ( function ( $ value ) { if ( in_array ( $ value , array ( "top" , "...
Gets the CSS3 transform - origin property
25,251
public function get_margin_height ( ) { $ style = $ this -> _style ; return ( float ) $ style -> length_in_pt ( array ( $ style -> height , $ style -> margin_top , $ style -> margin_bottom , $ style -> border_top_width , $ style -> border_bottom_width , $ style -> padding_top , $ style -> padding_bottom ) , $ this -> _...
Return the height of the margin box of the frame in pt . Meaningless unless the height has been calculated properly .
25,252
public function get_margin_width ( ) { $ style = $ this -> _style ; return ( float ) $ style -> length_in_pt ( array ( $ style -> width , $ style -> margin_left , $ style -> margin_right , $ style -> border_left_width , $ style -> border_right_width , $ style -> padding_left , $ style -> padding_right ) , $ this -> _co...
Return the width of the margin box of the frame in pt . Meaningless unless the width has been calculated properly .
25,253
public function is_auto_height ( ) { $ style = $ this -> _style ; return in_array ( "auto" , array ( $ style -> height , $ style -> margin_top , $ style -> margin_bottom , $ style -> border_top_width , $ style -> border_bottom_width , $ style -> padding_top , $ style -> padding_bottom , $ this -> _containing_block [ "h...
Indicates if the margin height is auto sized
25,254
public function is_auto_width ( ) { $ style = $ this -> _style ; return in_array ( "auto" , array ( $ style -> width , $ style -> margin_left , $ style -> margin_right , $ style -> border_left_width , $ style -> border_right_width , $ style -> padding_left , $ style -> padding_right , $ this -> _containing_block [ "w" ...
Indicates if the margin width is auto sized
25,255
public function prepend_child ( Frame $ child , $ update_node = true ) { if ( $ update_node ) { $ this -> _node -> insertBefore ( $ child -> _node , $ this -> _first_child ? $ this -> _first_child -> _node : null ) ; } if ( $ child -> _parent ) { $ child -> _parent -> remove_child ( $ child , false ) ; } $ child -> _pa...
Inserts a new child at the beginning of the Frame
25,256
public function saveFontFamilies ( ) { $ cacheData = sprintf ( "<?php return array (%s" , PHP_EOL ) ; foreach ( $ this -> fontLookup as $ family => $ variants ) { $ cacheData .= sprintf ( " '%s' => array(%s" , addslashes ( $ family ) , PHP_EOL ) ; foreach ( $ variants as $ variant => $ path ) { $ path = sprintf ( "'%s...
Saves the stored font family cache
25,257
public static function getRealCodepoint ( $ ref ) { if ( ! isset ( self :: $ realCodepointTable [ $ ref ] ) ) { return false ; } else { return self :: $ realCodepointTable [ $ ref ] ; } }
Returns the real Unicode codepoint of a malformed character reference .
25,258
public function read ( $ id ) { $ value = Cache :: read ( $ id , $ this -> _options [ 'config' ] ) ; if ( empty ( $ value ) ) { return '' ; } return $ value ; }
Method used to read from a cache session .
25,259
public function write ( $ id , $ data ) { if ( ! $ id ) { return false ; } return ( bool ) Cache :: write ( $ id , $ data , $ this -> _options [ 'config' ] ) ; }
Helper function called on write for cache sessions .
25,260
public function translation ( $ language ) { if ( $ language === $ this -> get ( '_locale' ) ) { return $ this ; } $ i18n = $ this -> get ( '_translations' ) ; $ created = false ; if ( empty ( $ i18n ) ) { $ i18n = [ ] ; $ created = true ; } if ( $ created || empty ( $ i18n [ $ language ] ) || ! ( $ i18n [ $ language ]...
Returns the entity containing the translated fields for this object and for the specified language . If the translation for the passed language is not present a new empty entity will be created so that values can be added to it .
25,261
protected function _setCookie ( ServerRequest $ request , Response $ response ) { $ expiry = new Time ( $ this -> _config [ 'expiry' ] ) ; $ value = hash ( 'sha512' , Security :: randomBytes ( 16 ) , false ) ; $ request = $ request -> withParam ( '_csrfToken' , $ value ) ; $ cookie = new Cookie ( $ this -> _config [ 'c...
Set the cookie in the response .
25,262
public function authCheck ( Event $ event ) { if ( $ this -> _config [ 'checkAuthIn' ] !== $ event -> getName ( ) ) { return null ; } $ controller = $ event -> getSubject ( ) ; $ action = strtolower ( $ controller -> getRequest ( ) -> getParam ( 'action' ) ) ; if ( ! $ controller -> isAction ( $ action ) ) { return nul...
Main execution method handles initial authentication check and redirection of invalid users .
25,263
protected function _isAllowed ( Controller $ controller ) { $ action = strtolower ( $ controller -> getRequest ( ) -> getParam ( 'action' ) ) ; return in_array ( $ action , array_map ( 'strtolower' , $ this -> allowedActions ) ) ; }
Checks whether current action is accessible without authentication .
25,264
protected function _loginActionRedirectUrl ( ) { $ urlToRedirectBackTo = $ this -> _getUrlToRedirectBackTo ( ) ; $ loginAction = $ this -> _config [ 'loginAction' ] ; if ( $ urlToRedirectBackTo === '/' ) { return $ loginAction ; } if ( is_array ( $ loginAction ) ) { $ loginAction [ '?' ] [ static :: QUERY_STRING_REDIRE...
Returns the URL of the login action to redirect to .
25,265
protected function _isLoginAction ( Controller $ controller ) { $ uri = $ controller -> request -> getUri ( ) ; $ url = Router :: normalize ( $ uri -> getPath ( ) ) ; $ loginAction = Router :: normalize ( $ this -> _config [ 'loginAction' ] ) ; return $ loginAction === $ url ; }
Normalizes config loginAction and checks if current request URL is same as login action .
25,266
protected function _unauthorized ( Controller $ controller ) { if ( $ this -> _config [ 'unauthorizedRedirect' ] === false ) { throw new ForbiddenException ( $ this -> _config [ 'authError' ] ) ; } $ this -> flash ( $ this -> _config [ 'authError' ] ) ; if ( $ this -> _config [ 'unauthorizedRedirect' ] === true ) { $ d...
Handle unauthorized access attempt
25,267
public function isAuthorized ( $ user = null , ServerRequest $ request = null ) { if ( empty ( $ user ) && ! $ this -> user ( ) ) { return false ; } if ( empty ( $ user ) ) { $ user = $ this -> user ( ) ; } if ( empty ( $ request ) ) { $ request = $ this -> getController ( ) -> getRequest ( ) ; } if ( empty ( $ this ->...
Check if the provided user is authorized for the request .
25,268
public function constructAuthorize ( ) { if ( empty ( $ this -> _config [ 'authorize' ] ) ) { return null ; } $ this -> _authorizeObjects = [ ] ; $ authorize = Hash :: normalize ( ( array ) $ this -> _config [ 'authorize' ] ) ; $ global = [ ] ; if ( isset ( $ authorize [ AuthComponent :: ALL ] ) ) { $ global = $ author...
Loads the authorization objects configured .
25,269
public function getAuthorize ( $ alias ) { if ( empty ( $ this -> _authorizeObjects ) ) { $ this -> constructAuthorize ( ) ; } return isset ( $ this -> _authorizeObjects [ $ alias ] ) ? $ this -> _authorizeObjects [ $ alias ] : null ; }
Getter for authorize objects . Will return a particular authorize object .
25,270
public function allow ( $ actions = null ) { if ( $ actions === null ) { $ controller = $ this -> _registry -> getController ( ) ; $ this -> allowedActions = get_class_methods ( $ controller ) ; return ; } $ this -> allowedActions = array_merge ( $ this -> allowedActions , ( array ) $ actions ) ; }
Takes a list of actions in the current controller for which authentication is not required or no parameters to allow all actions .
25,271
public function user ( $ key = null ) { $ user = $ this -> storage ( ) -> read ( ) ; if ( ! $ user ) { return null ; } if ( $ key === null ) { return $ user ; } return Hash :: get ( $ user , $ key ) ; }
Get the current user from storage .
25,272
public function redirectUrl ( $ url = null ) { $ redirectUrl = $ this -> getController ( ) -> getRequest ( ) -> getQuery ( static :: QUERY_STRING_REDIRECT ) ; if ( $ redirectUrl && ( substr ( $ redirectUrl , 0 , 1 ) !== '/' || substr ( $ redirectUrl , 0 , 2 ) === '//' ) ) { $ redirectUrl = null ; } if ( $ url !== null ...
Get the URL a user should be redirected to upon login .
25,273
public function constructAuthenticate ( ) { if ( empty ( $ this -> _config [ 'authenticate' ] ) ) { return null ; } $ this -> _authenticateObjects = [ ] ; $ authenticate = Hash :: normalize ( ( array ) $ this -> _config [ 'authenticate' ] ) ; $ global = [ ] ; if ( isset ( $ authenticate [ AuthComponent :: ALL ] ) ) { $...
Loads the configured authentication objects .
25,274
public function getAuthenticate ( $ alias ) { if ( empty ( $ this -> _authenticateObjects ) ) { $ this -> constructAuthenticate ( ) ; } return isset ( $ this -> _authenticateObjects [ $ alias ] ) ? $ this -> _authenticateObjects [ $ alias ] : null ; }
Getter for authenticate objects . Will return a particular authenticate object .
25,275
public function flash ( $ message ) { if ( $ message === false ) { return ; } $ this -> Flash -> set ( $ message , $ this -> _config [ 'flash' ] ) ; }
Set a flash message . Uses the Flash component with values from flash config .
25,276
public function authentication ( Request $ request , array $ credentials ) { if ( ! isset ( $ credentials [ 'consumerKey' ] ) ) { return $ request ; } if ( empty ( $ credentials [ 'method' ] ) ) { $ credentials [ 'method' ] = 'hmac-sha1' ; } $ credentials [ 'method' ] = strtoupper ( $ credentials [ 'method' ] ) ; $ val...
Add headers for Oauth authorization .
25,277
protected function _hmacSha1 ( $ request , $ credentials ) { $ nonce = isset ( $ credentials [ 'nonce' ] ) ? $ credentials [ 'nonce' ] : uniqid ( ) ; $ timestamp = isset ( $ credentials [ 'timestamp' ] ) ? $ credentials [ 'timestamp' ] : time ( ) ; $ values = [ 'oauth_version' => '1.0' , 'oauth_nonce' => $ nonce , 'oau...
Use HMAC - SHA1 signing .
25,278
protected function _rsaSha1 ( $ request , $ credentials ) { if ( ! function_exists ( 'openssl_pkey_get_private' ) ) { throw new RuntimeException ( 'RSA-SHA1 signature method requires the OpenSSL extension.' ) ; } $ nonce = isset ( $ credentials [ 'nonce' ] ) ? $ credentials [ 'nonce' ] : bin2hex ( Security :: randomByt...
Use RSA - SHA1 signing .
25,279
public function baseString ( $ request , $ oauthValues ) { $ parts = [ $ request -> getMethod ( ) , $ this -> _normalizedUrl ( $ request -> getUri ( ) ) , $ this -> _normalizedParams ( $ request , $ oauthValues ) , ] ; $ parts = array_map ( [ $ this , '_encode' ] , $ parts ) ; return implode ( '&' , $ parts ) ; }
Generate the Oauth basestring
25,280
protected function _normalizedUrl ( $ uri ) { $ out = $ uri -> getScheme ( ) . '://' ; $ out .= strtolower ( $ uri -> getHost ( ) ) ; $ out .= $ uri -> getPath ( ) ; return $ out ; }
Builds a normalized URL
25,281
protected function _normalizedParams ( $ request , $ oauthValues ) { $ query = parse_url ( $ request -> getUri ( ) , PHP_URL_QUERY ) ; parse_str ( $ query , $ queryArgs ) ; $ post = [ ] ; $ body = $ request -> body ( ) ; if ( is_string ( $ body ) && $ request -> getHeaderLine ( 'content-type' ) === 'application/x-www-f...
Sorts and normalizes request data and oauthValues
25,282
protected function _normalizeData ( $ args , $ path = '' ) { $ data = [ ] ; foreach ( $ args as $ key => $ value ) { if ( $ path ) { if ( ! is_numeric ( $ key ) ) { $ key = "{$path}[{$key}]" ; } else { $ key = $ path ; } } if ( is_array ( $ value ) ) { uksort ( $ value , 'strcmp' ) ; $ data = array_merge ( $ data , $ t...
Recursively convert request data into the normalized form .
25,283
protected function _buildAuth ( $ data ) { $ out = 'OAuth ' ; $ params = [ ] ; foreach ( $ data as $ key => $ value ) { $ params [ ] = $ key . '="' . $ this -> _encode ( $ value ) . '"' ; } $ out .= implode ( ',' , $ params ) ; return $ out ; }
Builds the Oauth Authorization header value .
25,284
protected static function _splitConditions ( $ token ) { $ conditions = false ; $ position = strpos ( $ token , '[' ) ; if ( $ position !== false ) { $ conditions = substr ( $ token , $ position ) ; $ token = substr ( $ token , 0 , $ position ) ; } return [ $ token , $ conditions ] ; }
Split token conditions
25,285
protected static function _matchToken ( $ key , $ token ) { switch ( $ token ) { case '{n}' : return is_numeric ( $ key ) ; case '{s}' : return is_string ( $ key ) ; case '{*}' : return true ; default : return is_numeric ( $ token ) ? ( $ key == $ token ) : $ key === $ token ; } }
Check a key against a token .
25,286
public static function contains ( array $ data , array $ needle ) { if ( empty ( $ data ) || empty ( $ needle ) ) { return false ; } $ stack = [ ] ; while ( ! empty ( $ needle ) ) { $ key = key ( $ needle ) ; $ val = $ needle [ $ key ] ; unset ( $ needle [ $ key ] ) ; if ( array_key_exists ( $ key , $ data ) && is_arra...
Determines if one array contains the exact keys and values of another .
25,287
public static function filter ( array $ data , $ callback = [ 'self' , '_filter' ] ) { foreach ( $ data as $ k => $ v ) { if ( is_array ( $ v ) ) { $ data [ $ k ] = static :: filter ( $ v , $ callback ) ; } } return array_filter ( $ data , $ callback ) ; }
Recursively filters a data set .
25,288
public function store ( Response $ response , $ url ) { $ host = parse_url ( $ url , PHP_URL_HOST ) ; $ path = parse_url ( $ url , PHP_URL_PATH ) ; $ path = $ path ? : '/' ; $ header = $ response -> getHeader ( 'Set-Cookie' ) ; $ cookies = $ this -> parseSetCookieHeader ( $ header ) ; $ cookies = $ this -> setRequestDe...
Store the cookies from a response .
25,289
public function get ( $ url ) { $ path = parse_url ( $ url , PHP_URL_PATH ) ? : '/' ; $ host = parse_url ( $ url , PHP_URL_HOST ) ; $ scheme = parse_url ( $ url , PHP_URL_SCHEME ) ; return $ this -> findMatchingCookies ( $ scheme , $ host , $ path ) ; }
Get stored cookies for a URL .
25,290
public function getAll ( ) { $ out = [ ] ; foreach ( $ this -> cookies as $ cookie ) { $ out [ ] = $ this -> convertCookieToArray ( $ cookie ) ; } return $ out ; }
Get all the stored cookies as arrays .
25,291
protected function _addConditions ( array $ orders , array $ types ) { foreach ( $ orders as $ key => $ val ) { if ( is_string ( $ key ) && is_string ( $ val ) && ! in_array ( strtoupper ( $ val ) , [ 'ASC' , 'DESC' ] , true ) ) { deprecationWarning ( 'Passing extra sort expressions by associative array is deprecated. ...
Auxiliary function used for decomposing a nested array of conditions and building a tree structure inside this object to represent the full SQL expression .
25,292
public function help ( $ width = 0 ) { $ name = $ this -> _name ; if ( strlen ( $ name ) < $ width ) { $ name = str_pad ( $ name , $ width , ' ' ) ; } return $ name . $ this -> _help ; }
Generate the help for this this subcommand .
25,293
public function xml ( SimpleXMLElement $ parent ) { $ command = $ parent -> addChild ( 'command' ) ; $ command -> addAttribute ( 'name' , $ this -> _name ) ; $ command -> addAttribute ( 'help' , $ this -> _help ) ; return $ parent ; }
Append this subcommand to the Parent element
25,294
public function key ( ) { $ extractor = $ this -> _key ; return $ extractor ( $ this -> _fetchCurrent ( ) , parent :: key ( ) , $ this ) ; }
Returns the current iteration key
25,295
public function current ( ) { $ extractor = $ this -> _value ; $ current = $ this -> _fetchCurrent ( ) ; $ spacer = str_repeat ( $ this -> _spacer , $ this -> getDepth ( ) ) ; return $ spacer . $ extractor ( $ current , parent :: key ( ) , $ this ) ; }
Returns the current iteration value
25,296
protected function _fetchCurrent ( ) { if ( $ this -> _current !== null ) { return $ this -> _current ; } return $ this -> _current = parent :: current ( ) ; }
Returns the current iteration element and caches its value
25,297
public function prepare ( $ sql ) { return $ this -> getDisconnectRetry ( ) -> run ( function ( ) use ( $ sql ) { $ statement = $ this -> _driver -> prepare ( $ sql ) ; if ( $ this -> _logQueries ) { $ statement = $ this -> _newLogger ( $ statement ) ; } return $ statement ; } ) ; }
Prepares a SQL statement to be executed .
25,298
public function compileQuery ( Query $ query , ValueBinder $ generator ) { return $ this -> getDriver ( ) -> compileQuery ( $ query , $ generator ) [ 1 ] ; }
Compiles a Query object into a SQL string according to the dialect for this connection s driver
25,299
public function run ( Query $ query ) { return $ this -> getDisconnectRetry ( ) -> run ( function ( ) use ( $ query ) { $ statement = $ this -> prepare ( $ query ) ; $ query -> getValueBinder ( ) -> attachTo ( $ statement ) ; $ statement -> execute ( ) ; return $ statement ; } ) ; }
Executes the provided query after compiling it for the specific driver dialect and returns the executed Statement object .