idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
50,000 | private function unDoubling ( ) { if ( $ this -> search ( array ( 'kk' , 'dd' , 'tt' ) ) !== false ) { $ this -> word = Utf8 :: substr ( $ this -> word , 0 , - 1 ) ; } } | Define undoubling the ending as removing the last letter if the word ends kk dd or tt . |
50,001 | private function step1 ( ) { if ( ( $ position = $ this -> search ( array ( 'heden' ) ) ) !== false ) { if ( $ this -> inR1 ( $ position ) ) { $ this -> word = preg_replace ( '#(heden)$#u' , 'heid' , $ this -> word ) ; } return true ; } if ( ( $ position = $ this -> search ( array ( 'ene' , 'en' ) ) ) !== false ) { if ( $ this -> inR1 ( $ position ) ) { $ word = Utf8 :: substr ( $ this -> word , 0 , $ position ) ; if ( $ this -> hasValidEnEnding ( $ word ) ) { $ this -> word = $ word ; $ this -> unDoubling ( ) ; } } return true ; } if ( ( $ position = $ this -> search ( array ( 'se' , 's' ) ) ) !== false ) { if ( $ this -> inR1 ( $ position ) ) { $ word = Utf8 :: substr ( $ this -> word , 0 , $ position ) ; if ( $ this -> hasValidSEnding ( $ word ) ) { $ this -> word = $ word ; } } return true ; } return false ; } | Step 1 Search for the longest among the following suffixes and perform the action indicated |
50,002 | private function step2 ( ) { if ( ( $ position = $ this -> search ( array ( 'e' ) ) ) !== false ) { if ( $ this -> inR1 ( $ position ) ) { $ letter = Utf8 :: substr ( $ this -> word , - 2 , 1 ) ; if ( ! in_array ( $ letter , self :: $ vowels ) ) { $ this -> word = Utf8 :: substr ( $ this -> word , 0 , $ position ) ; $ this -> unDoubling ( ) ; return true ; } } } return false ; } | Step 2 Delete suffix e if in R1 and preceded by a non - vowel and then undouble the ending |
50,003 | protected static function exception ( $ phery , $ exception , $ code ) { if ( $ phery instanceof Phery && $ phery -> config [ 'exceptions' ] === true ) { throw new PheryException ( $ exception , $ code ) ; } return false ; } | Throw an exception if enabled |
50,004 | public function data ( $ args ) { foreach ( func_get_args ( ) as $ arg ) { if ( is_array ( $ arg ) ) { $ this -> data = array_merge_recursive ( $ arg , $ this -> data ) ; } else { $ this -> data [ ] = $ arg ; } } return $ this ; } | Set any data to pass to the callbacks |
50,005 | public function csrf ( $ check = false , $ force = false ) { if ( $ this -> config [ 'csrf' ] !== true ) { return ! empty ( $ check ) ? true : '' ; } if ( session_id ( ) == '' && $ this -> config [ 'auto_session' ] === true ) { @ session_start ( ) ; } if ( $ check === false ) { $ current_token = $ this -> get_csrf_token ( ) ; if ( ( $ current_token !== false && $ force ) || $ current_token === false ) { $ token = sha1 ( uniqid ( microtime ( true ) , true ) ) ; $ _SESSION [ 'phery' ] = array ( 'csrf' => $ token ) ; $ token = base64_encode ( $ token ) ; } else { $ token = base64_encode ( $ _SESSION [ 'phery' ] [ 'csrf' ] ) ; } return "<meta id=\"csrf-token\" name=\"csrf-token\" content=\"{$token}\" />\n" ; } else { if ( empty ( $ _SESSION [ 'phery' ] [ 'csrf' ] ) ) { return false ; } return $ _SESSION [ 'phery' ] [ 'csrf' ] === base64_decode ( $ check , true ) ; } } | Output the meta HTML with the token . This method needs to use sessions through session_start |
50,006 | public static function is_ajax ( $ is_phery = false ) { switch ( $ is_phery ) { case true : return ( bool ) ( ! empty ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] ) && strcasecmp ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] , 'XMLHttpRequest' ) === 0 && strtoupper ( $ _SERVER [ 'REQUEST_METHOD' ] ) === 'POST' && ! empty ( $ _SERVER [ 'HTTP_X_PHERY' ] ) ) ; case false : return ( bool ) ( ! empty ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] ) && strcasecmp ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] , 'XMLHttpRequest' ) === 0 ) ; } return false ; } | Check if the current call is an ajax call |
50,007 | private function stripslashes_recursive ( $ variable ) { if ( ! empty ( $ variable ) && is_string ( $ variable ) ) { return stripslashes ( $ variable ) ; } if ( ! empty ( $ variable ) && is_array ( $ variable ) ) { foreach ( $ variable as $ i => $ value ) { $ variable [ $ i ] = $ this -> stripslashes_recursive ( $ value ) ; } } return $ variable ; } | Strip slashes recursive |
50,008 | public static function shutdown_handler ( $ errors = false , $ handled = false ) { if ( $ handled ) { self :: flush ( ) ; } if ( $ errors === true && ( $ error = error_get_last ( ) ) && ! $ handled ) { self :: error_handler ( $ error [ "type" ] , $ error [ "message" ] , $ error [ "file" ] , $ error [ "line" ] ) ; } if ( ! $ handled ) { self :: flush ( ) ; } if ( session_id ( ) != '' ) { session_write_close ( ) ; } exit ; } | Default shutdown handler |
50,009 | protected function before_user_func ( ) { if ( $ this -> config [ 'error_reporting' ] !== false ) { set_error_handler ( sprintf ( '%s::error_handler' , __CLASS__ ) , $ this -> config [ 'error_reporting' ] ) ; } if ( empty ( $ _POST [ 'phery' ] [ 'csrf' ] ) ) { $ _POST [ 'phery' ] [ 'csrf' ] = '' ; } if ( $ this -> csrf ( $ _POST [ 'phery' ] [ 'csrf' ] ) === false ) { self :: exception ( $ this , 'Invalid CSRF token' , self :: ERROR_CSRF ) ; } } | Initialize stuff before calling the AJAX function |
50,010 | public function process ( $ last_call = true ) { if ( self :: is_ajax ( true ) ) { return $ this -> process_data ( $ last_call ) ; } return true ; } | Process the AJAX requests if any . |
50,011 | public function config ( $ config = null ) { $ register_function = false ; if ( ! empty ( $ config ) ) { if ( is_array ( $ config ) ) { if ( isset ( $ config [ 'exit_allowed' ] ) ) { $ this -> config [ 'exit_allowed' ] = ( bool ) $ config [ 'exit_allowed' ] ; } if ( isset ( $ config [ 'auto_session' ] ) ) { $ this -> config [ 'auto_session' ] = ( bool ) $ config [ 'auto_session' ] ; } if ( isset ( $ config [ 'return' ] ) ) { $ this -> config [ 'return' ] = ( bool ) $ config [ 'return' ] ; } if ( isset ( $ config [ 'set_always_available' ] ) ) { $ this -> config [ 'set_always_available' ] = ( bool ) $ config [ 'set_always_available' ] ; } if ( isset ( $ config [ 'exceptions' ] ) ) { $ this -> config [ 'exceptions' ] = ( bool ) $ config [ 'exceptions' ] ; } if ( isset ( $ config [ 'csrf' ] ) ) { $ this -> config [ 'csrf' ] = ( bool ) $ config [ 'csrf' ] ; } if ( isset ( $ config [ 'error_reporting' ] ) ) { if ( $ config [ 'error_reporting' ] !== false ) { $ this -> config [ 'error_reporting' ] = ( int ) $ config [ 'error_reporting' ] ; } else { $ this -> config [ 'error_reporting' ] = false ; } $ register_function = true ; } if ( $ register_function || $ this -> init ) { register_shutdown_function ( sprintf ( '%s::shutdown_handler' , __CLASS__ ) , $ this -> config [ 'error_reporting' ] !== false ) ; $ this -> init = false ; } return $ this ; } elseif ( ! empty ( $ config ) && is_string ( $ config ) && isset ( $ this -> config [ $ config ] ) ) { return $ this -> config [ $ config ] ; } } return $ this -> config ; } | Config the current instance of Phery |
50,012 | public static function instance ( array $ config = array ( ) ) { if ( ! ( self :: $ instance instanceof Phery ) ) { self :: $ instance = new Phery ( $ config ) ; } else if ( $ config ) { self :: $ instance -> config ( $ config ) ; } return self :: $ instance ; } | Generates just one instance . Useful to use in many included files . Chainable |
50,013 | protected static function common_check ( & $ attributes , $ include_method = true ) { if ( ! empty ( $ attributes [ 'args' ] ) ) { $ attributes [ 'data-phery-args' ] = json_encode ( $ attributes [ 'args' ] ) ; unset ( $ attributes [ 'args' ] ) ; } if ( ! empty ( $ attributes [ 'confirm' ] ) ) { $ attributes [ 'data-phery-confirm' ] = $ attributes [ 'confirm' ] ; unset ( $ attributes [ 'confirm' ] ) ; } if ( ! empty ( $ attributes [ 'cache' ] ) ) { $ attributes [ 'data-phery-cache' ] = "1" ; unset ( $ attributes [ 'cache' ] ) ; } if ( ! empty ( $ attributes [ 'target' ] ) ) { $ attributes [ 'data-phery-target' ] = $ attributes [ 'target' ] ; unset ( $ attributes [ 'target' ] ) ; } if ( ! empty ( $ attributes [ 'related' ] ) ) { $ attributes [ 'data-phery-related' ] = $ attributes [ 'related' ] ; unset ( $ attributes [ 'related' ] ) ; } if ( ! empty ( $ attributes [ 'phery-type' ] ) ) { $ attributes [ 'data-phery-type' ] = $ attributes [ 'phery-type' ] ; unset ( $ attributes [ 'phery-type' ] ) ; } if ( ! empty ( $ attributes [ 'only' ] ) ) { $ attributes [ 'data-phery-only' ] = $ attributes [ 'only' ] ; unset ( $ attributes [ 'only' ] ) ; } if ( isset ( $ attributes [ 'clickable' ] ) ) { $ attributes [ 'data-phery-clickable' ] = "1" ; unset ( $ attributes [ 'clickable' ] ) ; } if ( $ include_method ) { if ( isset ( $ attributes [ 'method' ] ) ) { $ attributes [ 'data-phery-method' ] = $ attributes [ 'method' ] ; unset ( $ attributes [ 'method' ] ) ; } } $ encoding = 'UTF-8' ; if ( isset ( $ attributes [ 'encoding' ] ) ) { $ encoding = $ attributes [ 'encoding' ] ; unset ( $ attributes [ 'encoding' ] ) ; } return $ encoding ; } | Common check for all static factories |
50,014 | public static function link_to ( $ content , $ function , array $ attributes = array ( ) , Phery $ phery = null , $ no_close = false ) { if ( $ phery && ! isset ( $ phery -> functions [ $ function ] ) ) { self :: exception ( $ phery , 'The function "' . $ function . '" provided in "link_to" hasnt been set' , self :: ERROR_TO ) ; } $ tag = 'a' ; if ( isset ( $ attributes [ 'tag' ] ) ) { $ tag = $ attributes [ 'tag' ] ; unset ( $ attributes [ 'tag' ] ) ; } $ encoding = self :: common_check ( $ attributes ) ; if ( $ function ) { $ attributes [ 'data-phery-remote' ] = $ function ; } $ ret = array ( ) ; $ ret [ ] = "<{$tag}" ; foreach ( $ attributes as $ attribute => $ value ) { $ ret [ ] = "{$attribute}=\"" . htmlentities ( $ value , ENT_COMPAT , $ encoding , false ) . "\"" ; } if ( ! in_array ( strtolower ( $ tag ) , array ( 'img' , 'input' , 'iframe' , 'hr' , 'area' , 'embed' , 'keygen' ) ) ) { $ ret [ ] = ">{$content}" ; if ( ! $ no_close ) { $ ret [ ] = "</{$tag}>" ; } } else { $ ret [ ] = "/>" ; } return join ( ' ' , $ ret ) ; } | Helper function that generates an ajax link defaults to A tag |
50,015 | public function compile ( ) { $ value = $ this -> value ( ) ; if ( ! empty ( $ this -> parameters ) ) { $ params = $ this -> parameters ; $ value = strtr ( $ value , $ params ) ; } return $ value ; } | Compile function and return it . Replaces any parameters with their given values . |
50,016 | private function step0 ( ) { if ( ( $ position = $ this -> search ( array ( "'s'" , "'s" , "'" ) ) ) !== false ) { $ this -> word = Utf8 :: substr ( $ this -> word , 0 , $ position ) ; } } | Step 0 Remove s s |
50,017 | public function step4 ( ) { if ( ( $ position = $ this -> search ( array ( 'ance' , 'ence' , 'ement' , 'able' , 'ible' , 'ant' , 'ment' , 'ent' , 'ism' , 'ate' , 'iti' , 'ous' , 'ive' , 'ize' , 'al' , 'er' , 'ic' ) ) ) !== false ) { if ( $ this -> inR2 ( $ position ) ) { $ this -> word = Utf8 :: substr ( $ this -> word , 0 , $ position ) ; } return true ; } if ( ( $ position = $ this -> searchIfInR2 ( array ( 'ion' ) ) ) !== false ) { $ before = $ position - 1 ; $ letter = Utf8 :: substr ( $ this -> word , $ before , 1 ) ; if ( $ letter == 's' || $ letter == 't' ) { $ this -> word = Utf8 :: substr ( $ this -> word , 0 , $ position ) ; } return true ; } return false ; } | Step 4 Search for the longest among the following suffixes and if found and in R2 perform the action indicated . |
50,018 | private function exception2 ( ) { $ exceptions = array ( 'inning' => 'inning' , 'outing' => 'outing' , 'canning' => 'canning' , 'herring' => 'herring' , 'earring' => 'earring' , 'proceed' => 'proceed' , 'exceed' => 'exceed' , 'succeed' => 'succeed' ) ; if ( isset ( $ exceptions [ $ this -> word ] ) ) { return $ exceptions [ $ this -> word ] ; } return null ; } | Following step 1a leave the following invariant |
50,019 | public function set_config ( array $ config ) { if ( isset ( $ config [ 'convert_integers' ] ) ) { $ this -> config [ 'convert_integers' ] = ( bool ) $ config [ 'convert_integers' ] ; } if ( isset ( $ config [ 'typecast_objects' ] ) ) { $ this -> config [ 'typecast_objects' ] = ( bool ) $ config [ 'typecast_objects' ] ; } return $ this ; } | Change the config for this response You may pass in an associative array of your config |
50,020 | protected function set_internal_counter ( $ type , $ force = false ) { $ last = $ this -> last_selector ; if ( $ force && $ last !== null && ! isset ( $ this -> data [ $ last ] ) ) { $ this -> data [ $ last ] = array ( ) ; } $ this -> last_selector = '{' . $ type . ( self :: $ internal_count ++ ) . '}' ; return $ last ; } | Increment the internal counter so there are no conflicting stacked commands |
50,021 | public function renew_csrf ( Phery $ instance ) { if ( $ instance -> config ( 'csrf' ) === true ) { $ this -> cmd ( 13 , array ( $ instance -> csrf ( ) ) ) ; } return $ this ; } | Renew the CSRF token on a given Phery instance Resets any selectors that were being chained before |
50,022 | public function set_response_name ( $ name ) { if ( ! empty ( $ this -> name ) ) { unset ( self :: $ responses [ $ this -> name ] ) ; } $ this -> name = $ name ; self :: $ responses [ $ this -> name ] = $ this ; return $ this ; } | Set the name of this response |
50,023 | public function phery_broadcast ( $ name , array $ params = array ( ) ) { $ this -> last_selector = null ; return $ this -> cmd ( 12 , array ( $ name , array ( $ this -> typecast ( $ params , true , true ) ) , true ) ) ; } | Broadcast a remote message to the client to all elements that are subscribed to them . This removes the current selector if any |
50,024 | public function unless ( $ condition , $ remote = false ) { if ( ! $ remote && ! ( $ condition instanceof PheryFunction ) && ! ( $ condition instanceof PheryResponse ) ) { $ this -> matched = ! $ condition ; } else { $ this -> set_internal_counter ( '!' , true ) ; $ this -> cmd ( 0xff , array ( $ this -> typecast ( $ condition , true , true ) ) ) ; } return $ this ; } | Borrowed from Ruby the next imediate instruction will be executed unless it matches this criteria . |
50,025 | public function offsetSet ( $ index , $ newval ) { if ( $ index === null ) { $ this [ ] = $ newval ; } else { parent :: offsetSet ( $ index , $ newval ) ; } } | Set local variables will be available only in this instance |
50,026 | public function offsetGet ( $ index ) { if ( parent :: offsetExists ( $ index ) ) { return parent :: offsetGet ( $ index ) ; } if ( isset ( self :: $ global [ $ index ] ) ) { return self :: $ global [ $ index ] ; } return null ; } | Return null if no value |
50,027 | public static function get_response ( $ name ) { if ( isset ( self :: $ responses [ $ name ] ) && self :: $ responses [ $ name ] instanceof PheryResponse ) { return self :: $ responses [ $ name ] ; } return null ; } | Get a response by name |
50,028 | public function get_merged ( $ name ) { if ( isset ( $ this -> merged [ $ name ] ) ) { if ( isset ( self :: $ responses [ $ name ] ) ) { return self :: $ responses [ $ name ] ; } $ response = new PheryResponse ; $ response -> data = $ this -> merged [ $ name ] ; return $ response ; } return null ; } | Get merged response data as a new PheryResponse . This method works like a constructor if the previous response was destroyed |
50,029 | public function set_var ( $ variable , $ data ) { $ this -> last_selector = null ; if ( ! empty ( $ data ) && is_array ( $ data ) ) { foreach ( $ data as $ name => $ d ) { $ data [ $ name ] = $ this -> typecast ( $ d , true , true ) ; } } else { $ data = $ this -> typecast ( $ data , true , true ) ; } return $ this -> cmd ( 9 , array ( ! is_array ( $ variable ) ? array ( $ variable ) : $ variable , array ( $ data ) ) ) ; } | Set a global variable that can be accessed directly through window object can set properties inside objects if you pass an array as the variable . If it doesn t exist it will be created |
50,030 | public function unset_var ( $ variable ) { $ this -> last_selector = null ; return $ this -> cmd ( 9 , array ( ! is_array ( $ variable ) ? array ( $ variable ) : $ variable , ) ) ; } | Delete a global variable that can be accessed directly through window can unset object properties if you pass an array |
50,031 | public function remove_selector ( $ selector ) { if ( ( is_string ( $ selector ) || is_int ( $ selector ) ) && isset ( $ this -> data [ $ selector ] ) ) { unset ( $ this -> data [ $ selector ] ) ; } return $ this ; } | Remove a batch of calls for a selector . Won t remove for merged responses . Passing an integer will remove commands like dump_vars call etc in the order they were called |
50,032 | public function unmerge ( $ phery_response ) { if ( is_string ( $ phery_response ) ) { if ( isset ( self :: $ responses [ $ phery_response ] ) ) { unset ( $ this -> merged [ self :: $ responses [ $ phery_response ] -> name ] ) ; } } elseif ( $ phery_response instanceof PheryResponse ) { unset ( $ this -> merged [ $ phery_response -> name ] ) ; } elseif ( $ phery_response === true ) { $ this -> merged = array ( ) ; } return $ this ; } | Remove a previously merged response if you pass TRUE will removed all merged responses |
50,033 | public function print_vars ( $ vars ) { $ this -> last_selector = null ; $ args = array ( ) ; foreach ( func_get_args ( ) as $ name => $ arg ) { if ( is_object ( $ arg ) ) { $ arg = get_object_vars ( $ arg ) ; } $ args [ $ name ] = array ( var_export ( $ arg , true ) ) ; } return $ this -> cmd ( 6 , $ args ) ; } | Pretty print to console . log |
50,034 | public function dump_vars ( $ vars ) { $ this -> last_selector = null ; $ args = array ( ) ; foreach ( func_get_args ( ) as $ index => $ func ) { if ( $ func instanceof PheryResponse || $ func instanceof PheryFunction ) { $ args [ $ index ] = array ( $ this -> typecast ( $ func , true , true ) ) ; } elseif ( is_object ( $ func ) ) { $ args [ $ index ] = array ( get_object_vars ( $ func ) ) ; } else { $ args [ $ index ] = array ( $ func ) ; } } return $ this -> cmd ( 6 , $ args ) ; } | Dump var to console . log |
50,035 | public function jquery ( $ selector , array $ constructor = array ( ) ) { if ( $ selector ) { $ this -> last_selector = $ selector ; } if ( isset ( $ selector ) && is_string ( $ selector ) && count ( $ constructor ) && substr ( $ selector , 0 , 1 ) === '<' ) { foreach ( $ constructor as $ name => $ value ) { $ this -> $ name ( $ value ) ; } } return $ this ; } | Sets the jQuery selector so you can chain many calls to it . |
50,036 | public function alert ( $ msg ) { if ( is_array ( $ msg ) ) { $ msg = join ( "\n" , $ msg ) ; } $ this -> last_selector = null ; return $ this -> cmd ( 1 , array ( $ this -> typecast ( $ msg , true ) ) ) ; } | Show an alert box |
50,037 | public function cmd ( $ cmd , array $ args = array ( ) , $ selector = null ) { if ( ! $ this -> matched ) { $ this -> matched = true ; return $ this ; } $ selector = Phery :: coalesce ( $ selector , $ this -> last_selector ) ; if ( $ selector === null ) { $ this -> data [ '0' . ( $ this -> internal_cmd_count ++ ) ] = array ( 'c' => $ cmd , 'a' => $ args ) ; } else { if ( ! isset ( $ this -> data [ $ selector ] ) ) { $ this -> data [ $ selector ] = array ( ) ; } $ this -> data [ $ selector ] [ ] = array ( 'c' => $ cmd , 'a' => $ args ) ; } if ( $ this -> restore !== null ) { $ this -> last_selector = $ this -> restore ; $ this -> restore = null ; } return $ this ; } | Add a command to the response |
50,038 | public function attr ( $ attr , $ data , $ selector = null ) { return $ this -> cmd ( 'attr' , array ( $ attr , $ data ) , $ selector ) ; } | Set the attribute of a jQuery selector |
50,039 | public function render_view ( $ html , $ data = array ( ) ) { $ this -> last_selector = null ; if ( is_array ( $ html ) ) { $ html = join ( "\n" , $ html ) ; } return $ this -> cmd ( 5 , array ( $ this -> typecast ( $ html , true , true ) , $ data ) ) ; } | Render a view to the container previously specified |
50,040 | public function redirect ( $ url , $ view = false ) { if ( $ view === false && ! preg_match ( '#^https?\://#i' , $ url ) ) { $ _url = ( empty ( $ _SERVER [ 'HTTPS' ] ) || $ _SERVER [ 'HTTPS' ] === 'off' ? 'http://' : 'https://' ) . $ _SERVER [ 'HTTP_HOST' ] ; $ start = substr ( $ url , 0 , 1 ) ; if ( ! empty ( $ start ) ) { if ( $ start === '?' ) { $ _url .= str_replace ( '?' . $ _SERVER [ 'QUERY_STRING' ] , '' , $ _SERVER [ 'REQUEST_URI' ] ) ; } elseif ( $ start !== '/' ) { $ _url .= '/' ; } } $ _url .= $ url ; } else { $ _url = $ url ; } $ this -> last_selector = null ; if ( $ view !== false ) { return $ this -> reset_response ( ) -> cmd ( 8 , array ( $ _url , $ view ) ) ; } else { return $ this -> cmd ( 8 , array ( $ _url , false ) ) ; } } | Creates a redirect |
50,041 | public function include_stylesheet ( array $ path , $ replace = false ) { $ this -> last_selector = null ; return $ this -> cmd ( 10 , array ( 'c' , $ path , $ replace ) ) ; } | Include a stylesheet in the head of the page |
50,042 | public function include_script ( $ path , $ replace = false ) { $ this -> last_selector = null ; return $ this -> cmd ( 10 , array ( 'j' , $ path , $ replace ) ) ; } | Include a script in the head of the page |
50,043 | protected function typecast ( $ argument , $ toString = true , $ nested = false , $ depth = 4 ) { if ( $ nested ) { $ depth -- ; if ( $ argument instanceof PheryResponse ) { $ argument = array ( 'PR' => $ argument -> process_merged ( ) ) ; } elseif ( $ argument instanceof PheryFunction ) { $ argument = array ( 'PF' => $ argument -> compile ( ) ) ; } elseif ( $ depth > 0 && is_array ( $ argument ) ) { foreach ( $ argument as $ name => $ arg ) { $ argument [ $ name ] = $ this -> typecast ( $ arg , $ toString , $ nested , $ depth ) ; } } } if ( $ toString && ! empty ( $ argument ) ) { if ( is_string ( $ argument ) && ctype_digit ( $ argument ) ) { if ( $ this -> config [ 'convert_integers' ] === true ) { $ argument = ( int ) $ argument ; } } elseif ( is_object ( $ argument ) && $ this -> config [ 'typecast_objects' ] === true ) { $ class = get_class ( $ argument ) ; if ( $ class !== false ) { $ rc = new ReflectionClass ( get_class ( $ argument ) ) ; if ( $ rc -> hasMethod ( '__toString' ) ) { $ argument = "{$argument}" ; } else { $ argument = json_decode ( json_encode ( $ argument ) , true ) ; } } else { $ argument = json_decode ( json_encode ( $ argument ) , true ) ; } } } return $ argument ; } | Convert to a maximum depth nested responses and typecast int properly |
50,044 | protected function process_merged ( ) { $ data = $ this -> data ; if ( empty ( $ data ) && $ this -> last_selector !== null && ! $ this -> is_special_selector ( '#' ) ) { $ data [ $ this -> last_selector ] = array ( ) ; } foreach ( $ this -> merged as $ r ) { foreach ( $ r as $ selector => $ response ) { if ( ! ctype_digit ( $ selector ) ) { if ( isset ( $ data [ $ selector ] ) ) { $ data [ $ selector ] = array_merge_recursive ( $ data [ $ selector ] , $ response ) ; } else { $ data [ $ selector ] = $ response ; } } else { $ selector = ( int ) $ selector ; while ( isset ( $ data [ '0' . $ selector ] ) ) { $ selector ++ ; } $ data [ '0' . $ selector ] = $ response ; } } } return $ data ; } | Process merged responses |
50,045 | public function unserialize ( $ serialized ) { $ obj = json_decode ( $ serialized , true ) ; if ( $ obj && is_array ( $ obj ) && json_last_error ( ) === JSON_ERROR_NONE ) { $ this -> exchangeArray ( $ obj [ 'this' ] ) ; $ this -> data = ( array ) $ obj [ 'data' ] ; $ this -> set_response_name ( ( string ) $ obj [ 'name' ] ) ; $ this -> merged = ( array ) $ obj [ 'merged' ] ; } else { throw new PheryException ( 'Invalid data passed to unserialize' ) ; } return $ this ; } | Initialize the instance from a serialized state |
50,046 | public function serialize ( ) { return json_encode ( array ( 'data' => $ this -> data , 'this' => $ this -> getArrayCopy ( ) , 'name' => $ this -> name , 'merged' => $ this -> merged , ) ) ; } | Serialize the response in JSON |
50,047 | protected function is_special_selector ( $ type = null , $ selector = null ) { $ selector = Phery :: coalesce ( $ selector , $ this -> last_selector ) ; if ( $ selector && preg_match ( '/\{([\D]+)\d+\}/' , $ selector , $ matches ) ) { if ( $ type === null ) { return true ; } return ( $ matches [ 1 ] === $ type ) ; } return false ; } | Determine if the last selector or the selector provided is an special |
50,048 | public static function insertIgnore ( array $ attributes = [ ] ) { $ model = new static ( ) ; $ driver = $ model -> GetConnection ( ) -> GetDriverName ( ) ; switch ( $ driver ) { case 'sqlite' : return static :: executeQuery ( 'insert or ignore' , $ attributes ) ; break ; default : return static :: executeQuery ( 'insert ignore' , $ attributes ) ; break ; } } | performs an insert ignore query with the data |
50,049 | protected function executeDecorators ( $ command ) { foreach ( $ this -> decorators as $ className ) { $ instance = $ this -> app -> make ( $ className ) ; if ( ! $ instance instanceof CommandBus ) { $ message = 'The class to decorate must be an implementation of Laracasts\Commander\CommandBus' ; throw new InvalidArgumentException ( $ message ) ; } $ instance -> execute ( $ command ) ; } } | Execute all registered decorators |
50,050 | protected function mapInputToCommand ( $ command , array $ input ) { $ dependencies = [ ] ; $ class = new ReflectionClass ( $ command ) ; foreach ( $ class -> getConstructor ( ) -> getParameters ( ) as $ parameter ) { $ name = $ parameter -> getName ( ) ; if ( array_key_exists ( $ name , $ input ) ) { $ dependencies [ ] = $ input [ $ name ] ; } elseif ( $ parameter -> isDefaultValueAvailable ( ) ) { $ dependencies [ ] = $ parameter -> getDefaultValue ( ) ; } else { throw new InvalidArgumentException ( "Unable to map input to command: {$name}" ) ; } } return $ class -> newInstanceArgs ( $ dependencies ) ; } | Map an array of input to a command s properties . |
50,051 | public function dispatch ( array $ events ) { foreach ( $ events as $ event ) { $ eventName = $ this -> getEventName ( $ event ) ; $ this -> event -> fire ( $ eventName , $ event ) ; $ this -> log -> info ( "{$eventName} was fired." ) ; } } | Dispatch all raised events . |
50,052 | public function parse ( $ path , $ properties ) { $ segments = explode ( '\\' , str_replace ( '/' , '\\' , $ path ) ) ; $ name = array_pop ( $ segments ) ; $ namespace = implode ( '\\' , $ segments ) ; $ properties = $ this -> parseProperties ( $ properties ) ; return new CommandInput ( $ name , $ namespace , $ properties ) ; } | Parse the command input . |
50,053 | public function toCommandHandler ( $ command ) { $ commandClass = get_class ( $ command ) ; $ handler = substr_replace ( $ commandClass , 'CommandHandler' , strrpos ( $ commandClass , 'Command' ) ) ; if ( ! class_exists ( $ handler ) ) { $ message = "Command handler [$handler] does not exist." ; throw new HandlerNotRegisteredException ( $ message ) ; } return $ handler ; } | Translate a command to its handler counterpart |
50,054 | public function execute ( $ uri ) { foreach ( $ this -> routes as $ pattern => $ callback ) { if ( preg_match ( $ pattern , $ uri , $ params ) === 1 ) { call_user_func_array ( $ this -> beforeRouteCallback , $ params ) ; array_shift ( $ params ) ; return call_user_func_array ( $ callback , array_values ( $ params ) ) ; } else { error_log ( "$pattern did not match $uri" ) ; } } } | Match URI to route definition and call it |
50,055 | public function createToken ( ) { return $ this -> generator -> generateString ( $ this -> tokenBytes , $ this -> formatMap [ $ this -> tokenFormat ] ) ; } | Generate a random 32 - byte Token |
50,056 | public function login ( ) { $ cookieValue = $ this -> cookie -> getValue ( ) ; if ( ! $ cookieValue ) { return LoginResult :: newNoCookieResult ( ) ; } $ triplet = Triplet :: fromString ( $ cookieValue ) ; if ( ! $ triplet -> isValid ( ) ) { return LoginResult :: newManipulationResult ( ) ; } if ( $ this -> cleanExpiredTokensOnLogin ) { $ this -> storage -> cleanExpiredTokens ( time ( ) - $ this -> expireTime ) ; } $ tripletLookupResult = $ this -> storage -> findTriplet ( $ triplet -> getCredential ( ) , $ triplet -> getSaltedOneTimeToken ( $ this -> salt ) , $ triplet -> getSaltedPersistentToken ( $ this -> salt ) ) ; switch ( $ tripletLookupResult ) { case Storage \ StorageInterface :: TRIPLET_FOUND : $ expire = time ( ) + $ this -> expireTime ; $ newTriplet = new Triplet ( $ triplet -> getCredential ( ) , $ this -> tokenGenerator -> createToken ( ) , $ triplet -> getPersistentToken ( ) ) ; $ this -> storage -> replaceTriplet ( $ newTriplet -> getCredential ( ) , $ newTriplet -> getSaltedOneTimeToken ( $ this -> salt ) , $ newTriplet -> getSaltedPersistentToken ( $ this -> salt ) , $ expire ) ; $ this -> cookie -> setValue ( ( string ) $ newTriplet ) ; return LoginResult :: newSuccessResult ( $ triplet -> getCredential ( ) ) ; case Storage \ StorageInterface :: TRIPLET_INVALID : $ this -> cookie -> deleteCookie ( ) ; if ( $ this -> cleanStoredTokensOnInvalidResult ) { $ this -> storage -> cleanAllTriplets ( $ triplet -> getCredential ( ) ) ; } return LoginResult :: newManipulationResult ( ) ; default : return LoginResult :: newExpiredResult ( ) ; } } | Check Credentials from cookie . Returns false if login was not successful credential string if it was successful |
50,057 | public function registerClientScript ( ) { $ view = $ this -> getView ( ) ; FancyBoxAsset :: register ( $ view ) ; if ( $ this -> mouse ) { MousewheelAsset :: register ( $ view ) ; } if ( $ this -> helpers ) { FancyBoxHelpersAsset :: register ( $ view ) ; } } | Registers required script for the plugin to work as DatePicker |
50,058 | public function time ( $ time ) { if ( $ time instanceof Carbon ) { $ time = $ time -> timestamp ; } $ this -> timestamp = $ time ; return $ this ; } | Set the time of the Pushover message . |
50,059 | public function url ( $ url , $ title = null ) { $ this -> url = $ url ; $ this -> urlTitle = $ title ; return $ this ; } | Set a supplementary url for the Pushover message . |
50,060 | public function priority ( $ priority , $ retryTimeout = null , $ expireAfter = null ) { $ this -> noEmergencyWithoutRetryOrExpire ( $ priority , $ retryTimeout , $ expireAfter ) ; $ this -> priority = $ priority ; $ this -> retry = $ retryTimeout ; $ this -> expire = $ expireAfter ; return $ this ; } | Set the priority of the Pushover message . Retry and expire are mandatory when setting the priority to emergency . |
50,061 | public function toArray ( ) { return [ 'message' => $ this -> content , 'title' => $ this -> title , 'timestamp' => $ this -> timestamp , 'priority' => $ this -> priority , 'url' => $ this -> url , 'url_title' => $ this -> urlTitle , 'sound' => $ this -> sound , 'retry' => $ this -> retry , 'expire' => $ this -> expire , ] ; } | Array representation of Pushover Message . |
50,062 | protected function noEmergencyWithoutRetryOrExpire ( $ priority , $ retry , $ expire ) { if ( $ priority == self :: EMERGENCY_PRIORITY && ( ! isset ( $ retry ) || ! isset ( $ expire ) ) ) { throw new EmergencyNotificationRequiresRetryAndExpire ( ) ; } } | Ensure an emergency message has an retry and expiry time . |
50,063 | public function send ( $ params ) { try { return $ this -> http -> post ( $ this -> pushoverApiUrl , [ 'form_params' => $ this -> paramsWithToken ( $ params ) , ] ) ; } catch ( RequestException $ exception ) { if ( $ exception -> getResponse ( ) ) { throw CouldNotSendNotification :: serviceRespondedWithAnError ( $ exception -> getResponse ( ) ) ; } throw ServiceCommunicationError :: communicationFailed ( $ exception ) ; } catch ( Exception $ exception ) { throw ServiceCommunicationError :: communicationFailed ( $ exception ) ; } } | Send Pushover message . |
50,064 | public function toDevice ( $ device ) { if ( is_array ( $ device ) ) { $ this -> devices = array_merge ( $ device , $ this -> devices ) ; return $ this ; } $ this -> devices [ ] = $ device ; return $ this ; } | Send the message to a specific device . |
50,065 | public function toArray ( ) { return array_merge ( [ 'user' => $ this -> key , 'device' => implode ( ',' , $ this -> devices ) , ] , $ this -> token ? [ 'token' => $ this -> token ] : [ ] ) ; } | Get array representation of Pushover receiver . |
50,066 | public function initialize ( array $ config ) { $ this -> config = $ config ; $ this -> controller = $ this -> _registry -> getController ( ) ; $ registry = new ComponentRegistry ( ) ; $ this -> Acl = new AclComponent ( $ registry , Configure :: read ( 'Acl' ) ) ; $ this -> Aco = $ this -> Acl -> Aco ; $ this -> Aro = $ this -> Acl -> Aro ; return null ; } | Initialize all properties we need |
50,067 | public function checkNodeOrSave ( $ path , $ alias , $ parentId = null ) { $ node = $ this -> Aco -> node ( $ path ) ; if ( $ node === false ) { $ data = [ 'parent_id' => $ parentId , 'model' => null , 'alias' => $ alias , ] ; $ entity = $ this -> Aco -> newEntity ( $ data ) ; $ node = $ this -> Aco -> save ( $ entity ) ; return $ node ; } return $ node -> first ( ) ; } | Check if the aco exist and store it if empty |
50,068 | private function __findAro ( $ aro ) { if ( isset ( $ aro -> parent_id ) ) { $ conditions = [ 'parent_id' => $ aro -> parent_id , 'foreign_key' => $ aro -> foreign_key , 'model' => $ aro -> model ] ; } else { $ conditions = [ 'parent_id IS NULL' , 'foreign_key' => $ aro -> foreign_key , 'model' => $ aro -> model ] ; } return $ this -> Acl -> Aro -> find ( 'all' , [ 'conditions' => $ conditions , 'recursive' => - 1 ] ) -> count ( ) ; } | Find aro in database and returns the number of matches |
50,069 | protected function _getKeys ( ) { $ keys = $ this -> Permissions -> schema ( ) -> columns ( ) ; $ newKeys = array ( ) ; foreach ( $ keys as $ key ) { if ( ! in_array ( $ key , array ( 'id' , 'aro_id' , 'aco_id' ) ) ) { $ newKeys [ ] = $ key ; } } return $ newKeys ; } | Returns permissions keys in Permission schema |
50,070 | protected function _getAcos ( ) { $ acos = $ this -> Acl -> Aco -> find ( 'all' , array ( 'order' => 'Acos.lft ASC' , 'recursive' => - 1 ) ) -> toArray ( ) ; $ parents = array ( ) ; foreach ( $ acos as $ key => $ data ) { $ aco = & $ acos [ $ key ] ; $ aco = $ aco -> toArray ( ) ; $ id = $ aco [ 'id' ] ; if ( $ aco [ 'parent_id' ] && isset ( $ parents [ $ aco [ 'parent_id' ] ] ) ) { $ parents [ $ id ] = $ parents [ $ aco [ 'parent_id' ] ] . '/' . $ aco [ 'alias' ] ; } else { $ parents [ $ id ] = $ aco [ 'alias' ] ; } $ aco [ 'action' ] = $ parents [ $ id ] ; } return $ acos ; } | Returns all the ACOs including their path |
50,071 | private function _parseAcos ( $ acos ) { $ cache = [ ] ; foreach ( $ acos as $ aco ) { $ data [ 'Aco' ] = [ 'id' => $ aco -> id , 'parent_id' => $ aco -> parent_id , 'foreign_key' => $ aco -> foreign_key , 'alias' => $ aco -> alias , 'lft' => $ aco -> lft , 'rght' => $ aco -> rght , ] ; if ( isset ( $ aco -> model ) ) { $ data [ 'Aco' ] [ 'model' ] = $ aco -> model ; } $ d = [ ] ; foreach ( $ aco [ 'aros' ] as $ aro ) { $ d [ ] = [ 'id' => $ aro -> id , 'parent_id' => $ aro -> parent_id , 'model' => $ aro -> model , 'foreign_key' => $ aro -> foreign_key , 'alias' => $ aro -> alias , 'lft' => $ aro -> lft , 'rght' => $ aro -> rght , 'Permission' => [ 'aro_id' => $ aro -> _joinData -> aro_id , 'id' => $ aro -> _joinData -> id , 'aco_id' => $ aro -> _joinData -> aco_id , '_create' => $ aro -> _joinData -> _create , '_read' => $ aro -> _joinData -> _read , '_update' => $ aro -> _joinData -> _update , '_delete' => $ aro -> _joinData -> _delete , ] ] ; } $ data [ 'Aro' ] = $ d ; array_push ( $ cache , $ data ) ; } return $ cache ; } | Returns an array with acos |
50,072 | private function _parseAros ( $ aros ) { $ cache = array ( ) ; foreach ( $ aros as $ aro ) { $ data [ $ this -> model ] = $ aro ; array_push ( $ cache , $ data ) ; } return $ cache ; } | Returns an array with aros |
50,073 | public function check ( $ aro , $ aco ) { if ( empty ( $ aro ) || empty ( $ aco ) ) { return false ; } return $ this -> Acl -> check ( $ aro , $ aco ) ; } | Check if the User have access to the aco |
50,074 | public function value ( $ value = NULL ) { if ( $ value == NULL ) { return false ; } $ o = explode ( '.' , $ value ) ; $ data = $ this -> request -> data ; return $ data [ $ o [ 0 ] ] [ $ o [ 1 ] ] [ $ o [ 2 ] ] ; } | Return value from permissions input |
50,075 | public function acoUpdate ( $ params = [ ] ) { $ root = $ this -> _checkNode ( $ this -> rootNode , $ this -> rootNode , null ) ; if ( empty ( $ params [ 'plugin' ] ) ) { $ plugins = Plugin :: loaded ( ) ; $ this -> _processControllers ( $ root ) ; $ this -> _processPrefixes ( $ root ) ; $ this -> _processPlugins ( $ root , $ plugins ) ; } else { $ plugin = $ params [ 'plugin' ] ; if ( ! Plugin :: loaded ( $ plugin ) ) { $ this -> err ( __d ( 'cake_acl' , "Plugin {0} not found or not activated." , [ $ plugin ] ) ) ; return false ; } $ plugins = [ $ params [ 'plugin' ] ] ; $ this -> _processPlugins ( $ root , $ plugins ) ; $ this -> foundACOs = array_slice ( $ this -> foundACOs , 1 , null , true ) ; } if ( $ this -> _clean ) { foreach ( $ this -> foundACOs as $ parentId => $ acosList ) { $ this -> _cleaner ( $ parentId , $ acosList ) ; } } $ this -> out ( __d ( 'cake_acl' , '{0} ACOs have been created, updated or deleted' , ( int ) $ this -> counter ) ) ; return true ; } | Updates the Aco Tree with new controller actions . |
50,076 | protected function _processControllers ( $ root ) { $ controllers = $ this -> getControllerList ( ) ; $ this -> foundACOs [ $ root -> id ] = $ this -> _updateControllers ( $ root , $ controllers ) ; } | Updates the Aco Tree with all App controllers . |
50,077 | protected function _processPrefixes ( $ root ) { foreach ( array_keys ( $ this -> prefixes ) as $ prefix ) { $ controllers = $ this -> getControllerList ( null , $ prefix ) ; $ path = $ this -> rootNode . '/' . $ prefix ; $ pathNode = $ this -> _checkNode ( $ path , $ prefix , $ root -> id ) ; $ this -> foundACOs [ $ root -> id ] [ ] = $ prefix ; if ( isset ( $ this -> foundACOs [ $ pathNode -> id ] ) ) { $ this -> foundACOs [ $ pathNode -> id ] += $ this -> _updateControllers ( $ pathNode , $ controllers , null , $ prefix ) ; } else { $ this -> foundACOs [ $ pathNode -> id ] = $ this -> _updateControllers ( $ pathNode , $ controllers , null , $ prefix ) ; } } } | Updates the Aco Tree with all App route prefixes . |
50,078 | protected function _processPlugins ( $ root , array $ plugins = [ ] ) { foreach ( $ plugins as $ plugin ) { $ controllers = $ this -> getControllerList ( $ plugin ) ; $ pluginAlias = $ this -> _pluginAlias ( $ plugin ) ; $ path = [ $ this -> rootNode , $ pluginAlias ] ; $ path = implode ( '/' , Hash :: filter ( $ path ) ) ; if ( ! in_array ( $ path , $ this -> ignorePaths ) && ! in_array ( $ path , $ this -> ignoreActions ) ) { $ pathNode = $ this -> _checkNode ( $ path , $ pluginAlias , $ root -> id ) ; $ this -> foundACOs [ $ root -> id ] [ ] = $ pluginAlias ; if ( isset ( $ this -> foundACOs [ $ pathNode -> id ] ) ) { $ this -> foundACOs [ $ pathNode -> id ] += $ this -> _updateControllers ( $ pathNode , $ controllers , $ plugin ) ; } else { $ this -> foundACOs [ $ pathNode -> id ] = $ this -> _updateControllers ( $ pathNode , $ controllers , $ plugin ) ; } if ( isset ( $ this -> pluginPrefixes [ $ plugin ] ) ) { foreach ( array_keys ( $ this -> pluginPrefixes [ $ plugin ] ) as $ prefix ) { $ path = [ $ this -> rootNode , $ pluginAlias ] ; $ path = implode ( '/' , Hash :: filter ( $ path ) ) ; $ pluginNode = $ this -> _checkNode ( $ path , $ pluginAlias , $ root -> id ) ; $ this -> foundACOs [ $ root -> id ] [ ] = $ pluginAlias ; $ path = [ $ this -> rootNode , $ pluginAlias , $ prefix , ] ; $ path = implode ( '/' , Hash :: filter ( $ path ) ) ; $ pathNode = $ this -> _checkNode ( $ path , $ prefix , $ pluginNode -> id ) ; $ this -> foundACOs [ $ pluginNode -> id ] [ ] = $ prefix ; $ controllers = $ this -> getControllerList ( $ plugin , $ prefix ) ; if ( isset ( $ this -> foundACOs [ $ pathNode -> id ] ) ) { $ this -> foundACOs [ $ pathNode -> id ] += $ this -> _updateControllers ( $ pathNode , $ controllers , $ pluginAlias , $ prefix ) ; } else { $ this -> foundACOs [ $ pathNode -> id ] = $ this -> _updateControllers ( $ pathNode , $ controllers , $ pluginAlias , $ prefix ) ; } } } } } } | Updates the Aco Tree with all Plugins . |
50,079 | protected function _updateControllers ( $ root , $ controllers , $ plugin = null , $ prefix = null ) { $ pluginPath = $ this -> _pluginAlias ( $ plugin ) ; $ controllersNames = [ ] ; foreach ( $ controllers as $ controller ) { $ tmp = explode ( '/' , $ controller ) ; $ controllerName = str_replace ( 'Controller.php' , '' , array_pop ( $ tmp ) ) ; if ( $ controllerName == 'App' ) { continue ; } $ controllersNames [ ] = $ controllerName ; $ path = [ $ this -> rootNode , $ pluginPath , $ prefix , $ controllerName ] ; $ path = implode ( '/' , Hash :: filter ( $ path ) ) ; if ( ! in_array ( $ path , $ this -> ignorePaths ) ) { $ controllerNode = $ this -> _checkNode ( $ path , $ controllerName , $ root -> id ) ; $ this -> _checkMethods ( $ controller , $ controllerName , $ controllerNode , $ pluginPath , $ prefix ) ; } } return $ controllersNames ; } | Updates a collection of controllers . |
50,080 | public function getControllerList ( $ plugin = null , $ prefix = null ) { if ( ! $ plugin ) { $ path = App :: path ( 'Controller' . ( empty ( $ prefix ) ? '' : DS . Inflector :: camelize ( $ prefix ) ) ) ; $ dir = new Folder ( $ path [ 0 ] ) ; $ controllers = $ dir -> find ( '.*Controller\.php' ) ; } else { $ path = App :: path ( 'Controller' . ( empty ( $ prefix ) ? '' : DS . Inflector :: camelize ( $ prefix ) ) , $ plugin ) ; $ dir = new Folder ( $ path [ 0 ] ) ; $ controllers = $ dir -> find ( '.*Controller\.php' ) ; } return $ controllers ; } | Get a list of controllers in the app and plugins . |
50,081 | protected function _checkNode ( $ path , $ alias , $ parentId = null ) { $ node = $ this -> Aco -> node ( $ path ) ; if ( ! $ node ) { $ data = [ 'parent_id' => $ parentId , 'model' => null , 'alias' => $ alias , ] ; $ entity = $ this -> Aco -> newEntity ( $ data ) ; $ node = $ this -> Aco -> save ( $ entity ) ; $ this -> counter ++ ; } else { $ node = $ node -> first ( ) ; } return $ node ; } | Check a node for existance create it if it doesn t exist . |
50,082 | protected function _getCallbacks ( $ className , $ pluginPath = null , $ prefixPath = null ) { $ callbacks = [ ] ; $ namespace = $ this -> _getNamespace ( $ className , $ pluginPath , $ prefixPath ) ; $ reflection = new \ ReflectionClass ( $ namespace ) ; if ( $ reflection -> isAbstract ( ) ) { return $ callbacks ; } try { $ method = $ reflection -> getMethod ( 'implementedEvents' ) ; } catch ( ReflectionException $ e ) { return $ callbacks ; } if ( version_compare ( phpversion ( ) , '5.4' , '>=' ) ) { $ object = $ reflection -> newInstanceWithoutConstructor ( ) ; } else { $ object = unserialize ( sprintf ( 'O:%d:"%s":0:{}' , strlen ( $ className ) , $ className ) ) ; } $ implementedEvents = $ method -> invoke ( $ object ) ; foreach ( $ implementedEvents as $ event => $ callable ) { if ( is_string ( $ callable ) ) { $ callbacks [ ] = $ callable ; } if ( is_array ( $ callable ) && isset ( $ callable [ 'callable' ] ) ) { $ callbacks [ ] = $ callable [ 'callable' ] ; } } return $ callbacks ; } | Get a list of registered callback methods |
50,083 | public function recover ( ) { $ type = Inflector :: camelize ( $ this -> args [ 0 ] ) ; $ this -> Acl -> { $ type } -> recover ( ) ; $ this -> out ( __ ( 'Tree has been recovered, or tree did not need recovery.' ) ) ; } | Recover an Acl Tree |
50,084 | protected function _getNamespace ( $ className , $ pluginPath = null , $ prefixPath = null ) { $ namespace = preg_replace ( '/(.*)Controller\//' , '' , $ className ) ; $ namespace = preg_replace ( '/\//' , '\\' , $ namespace ) ; $ namespace = preg_replace ( '/\.php/' , '' , $ namespace ) ; $ prefixPath = preg_replace ( '/\//' , '\\' , Inflector :: camelize ( $ prefixPath ) ) ; if ( ! $ pluginPath ) { $ rootNamespace = Configure :: read ( 'App.namespace' ) ; } else { $ rootNamespace = preg_replace ( '/\//' , '\\' , $ pluginPath ) ; } $ namespace = [ $ rootNamespace , 'Controller' , $ prefixPath , $ namespace ] ; return implode ( '\\' , Hash :: filter ( $ namespace ) ) ; } | Get the namespace for a given class . |
50,085 | protected function _buildPrefixes ( ) { $ routes = Router :: routes ( ) ; foreach ( $ routes as $ key => $ route ) { if ( isset ( $ route -> defaults [ 'prefix' ] ) ) { $ prefix = Inflector :: camelize ( $ route -> defaults [ 'prefix' ] ) ; if ( ! isset ( $ route -> defaults [ 'plugin' ] ) ) { $ this -> prefixes [ $ prefix ] = true ; } else { $ this -> pluginPrefixes [ $ route -> defaults [ 'plugin' ] ] [ $ prefix ] = true ; } } } } | Build prefixes for App and Plugins based on configured routes |
50,086 | protected function _cleaner ( $ parentId , $ preservedItems = [ ] ) { $ nodes = $ this -> Aco -> find ( ) -> where ( [ 'parent_id' => $ parentId ] ) ; $ methodFlip = array_flip ( $ preservedItems ) ; foreach ( $ nodes as $ node ) { if ( ! isset ( $ methodFlip [ $ node -> alias ] ) ) { $ crumbs = $ this -> Aco -> find ( 'path' , [ 'for' => $ node -> id , 'order' => 'lft' ] ) ; $ path = null ; foreach ( $ crumbs as $ crumb ) { $ path .= '/' . $ crumb -> alias ; } $ entity = $ this -> Aco -> get ( $ node -> id ) ; if ( $ this -> Aco -> delete ( $ entity ) ) { $ this -> out ( __d ( 'cake_acl' , 'Deleted ACO node: <warning>{0}</warning> and all children' , $ path ) ) ; } } } } | Delete unused ACOs . |
50,087 | public function setSubscriptionCount ( $ active , $ inactive ) { $ this -> _subscriptionCount [ 'active' ] = $ active ; $ this -> _subscriptionCount [ 'inactive' ] = $ inactive ; return $ this ; } | Sets the subscriptionCount array |
50,088 | public function parameterize ( $ method ) { $ parameterArray = parent :: parameterize ( $ method ) ; if ( 'create' == $ method ) { if ( $ this -> getChecksumAction ( ) ) { $ parameterArray [ 'checksum_action' ] = $ this -> getChecksumAction ( ) ; } if ( $ this -> getShippingAddress ( ) ) { $ parameterArray [ 'shipping_address' ] = $ this -> getShippingAddress ( ) ; } if ( $ this -> getBillingAddress ( ) ) { $ parameterArray [ 'billing_address' ] = $ this -> getBillingAddress ( ) ; } if ( $ this -> getItems ( ) ) { $ parameterArray [ 'items' ] = $ this -> getItems ( ) ; } if ( $ this -> getShippingAmount ( ) ) { $ parameterArray [ 'shipping_amount' ] = $ this -> getShippingAmount ( ) ; } if ( $ this -> getHandlingAmount ( ) ) { $ parameterArray [ 'handling_amount' ] = $ this -> getHandlingAmount ( ) ; } if ( $ this -> getRequireReusablePayment ( ) ) { $ parameterArray [ 'require_reusable_payment' ] = $ this -> getRequireReusablePayment ( ) ; } if ( $ this -> getReusablePaymentDescription ( ) ) { $ parameterArray [ 'reusable_payment_description' ] = $ this -> getReusablePaymentDescription ( ) ; } } return $ parameterArray ; } | Converts the model into an array to prepare method calls |
50,089 | public function getJSONObject ( ) { $ result = false ; $ responseHandler = new ResponseHandler ( ) ; if ( is_array ( $ this -> _lastResponse ) ) { $ result = $ responseHandler -> arrayToObject ( $ this -> _lastResponse [ 'body' ] ) ; } return $ result ; } | Returns the LastResponse as StdClassObject . Returns false if no request was made earlier . |
50,090 | private function _request ( Base $ model , $ method ) { if ( ! is_a ( $ this -> _connectionClass , '\Paymill\API\CommunicationAbstract' ) ) { throw new PaymillException ( null , 'The connection class is missing!' ) ; } $ convertedResponse = null ; $ httpMethod = $ this -> _getHTTPMethod ( $ method ) ; $ parameter = $ model -> parameterize ( $ method ) ; $ serviceResource = $ model -> getServiceResource ( ) . $ model -> getId ( ) ; if ( ( is_a ( $ model , '\Paymill\Models\Request\Transaction' ) || is_a ( $ model , '\Paymill\Models\Request\Preauthorization' ) ) && $ method === "create" ) { $ source = ! array_key_exists ( 'source' , $ parameter ) ? "PhpLib" . $ this -> getVersion ( ) : "PhpLib" . $ this -> getVersion ( ) . "_" . $ parameter [ 'source' ] ; $ parameter [ 'source' ] = $ source ; } try { $ this -> _lastRequest = $ parameter ; $ response = $ this -> _connectionClass -> requestApi ( $ serviceResource , $ parameter , $ httpMethod ) ; $ this -> _lastResponse = $ response ; $ responseHandler = new ResponseHandler ( ) ; if ( $ method === "getAllAsModel" && $ responseHandler -> validateResponse ( $ response ) && $ this -> _util -> isNumericArray ( $ response [ 'body' ] [ 'data' ] ) ) { foreach ( $ response [ 'body' ] [ 'data' ] as $ object ) { $ convertedResponse [ ] = $ responseHandler -> convertResponse ( $ object , $ model -> getServiceResource ( ) ) ; } } elseif ( $ method === "getAll" && $ responseHandler -> validateResponse ( $ response ) ) { $ convertedResponse = $ response [ 'body' ] [ 'data' ] ; } elseif ( $ responseHandler -> validateResponse ( $ response ) ) { $ convertedResponse = $ responseHandler -> convertResponse ( $ response [ 'body' ] [ 'data' ] , $ model -> getServiceResource ( ) ) ; } else { $ convertedResponse = $ responseHandler -> convertErrorToModel ( $ response , $ model -> getServiceResource ( ) ) ; } } catch ( Exception $ e ) { $ errorModel = new Error ( ) ; $ convertedResponse = $ errorModel -> setErrorMessage ( $ e -> getMessage ( ) ) ; } if ( is_a ( $ convertedResponse , '\Paymill\Models\Response\Error' ) ) { throw new PaymillException ( $ convertedResponse -> getResponseCode ( ) , $ convertedResponse -> getErrorMessage ( ) , $ convertedResponse -> getHttpStatusCode ( ) , $ convertedResponse -> getRawObject ( ) , $ convertedResponse -> getErrorResponseArray ( ) ) ; } return $ convertedResponse ; } | Sends a request based on the provided request model and according to the argumented method |
50,091 | public function requestApi ( $ action = '' , $ params = array ( ) , $ method = 'POST' ) { $ curlOpts = array ( CURLOPT_URL => $ this -> _apiUrl . $ action , CURLOPT_RETURNTRANSFER => true , CURLOPT_CUSTOMREQUEST => $ method , CURLOPT_USERAGENT => 'Paymill-php/0.0.2' , CURLOPT_SSL_VERIFYPEER => true ) ; if ( ! empty ( $ this -> _extraOptions ) ) { $ curlOpts = $ this -> _extraOptions + $ curlOpts ; } if ( 'GET' === $ method || 'DELETE' === $ method ) { if ( 0 !== count ( $ params ) ) { $ curlOpts [ CURLOPT_URL ] .= false === strpos ( $ curlOpts [ CURLOPT_URL ] , '?' ) ? '?' : '&' ; $ curlOpts [ CURLOPT_URL ] .= http_build_query ( $ params , null , '&' ) ; } } else { $ curlOpts [ CURLOPT_POSTFIELDS ] = http_build_query ( $ params , null , '&' ) ; } if ( $ this -> _apiKey ) { $ curlOpts [ CURLOPT_USERPWD ] = $ this -> _apiKey . ':' ; } $ curl = curl_init ( ) ; $ this -> _curlOpts ( $ curl , $ curlOpts ) ; $ responseBody = $ this -> _curlExec ( $ curl ) ; $ responseInfo = $ this -> _curlInfo ( $ curl ) ; if ( $ responseBody === false ) { $ responseBody = array ( 'error' => $ this -> _curlError ( $ curl ) ) ; } curl_close ( $ curl ) ; if ( 'application/json' === $ responseInfo [ 'content_type' ] ) { $ responseBody = json_decode ( $ responseBody , true ) ; } elseif ( strpos ( strtolower ( $ responseInfo [ 'content_type' ] ) , 'text/csv' ) !== false && ! isset ( $ responseBody [ 'error' ] ) ) { return $ responseBody ; } $ result = array ( 'header' => array ( 'status' => $ responseInfo [ 'http_code' ] , 'reason' => null , ) , 'body' => $ responseBody ) ; return $ result ; } | Perform HTTP request to REST endpoint |
50,092 | public function convertResponse ( $ response , $ serviceResource ) { $ resourceName = substr ( $ serviceResource , 0 , - 2 ) ; return $ this -> _convertResponseToModel ( $ response , $ resourceName ) ; } | Converts a response to a model |
50,093 | private function _convertResponseToModel ( $ response , $ resourceName ) { if ( ! is_array ( $ response ) || empty ( $ response ) ) { return $ response ; } $ model = null ; switch ( strtolower ( $ resourceName ) ) { case 'client' : $ model = $ this -> _createClient ( $ response ) ; break ; case 'payment' : $ model = $ this -> _createPayment ( $ response ) ; break ; case 'transaction' : $ model = $ this -> _createTransaction ( $ response ) ; break ; case 'preauthorization' : if ( isset ( $ response [ 'preauthorization' ] ) ) { $ response = $ response [ 'preauthorization' ] ; } $ model = $ this -> _createPreauthorization ( $ response ) ; break ; case 'refund' : $ model = $ this -> _createRefund ( $ response ) ; break ; case 'offer' : $ model = $ this -> _createOffer ( $ response ) ; break ; case 'subscription' : $ model = $ this -> _createSubscription ( $ response ) ; break ; case 'webhook' : $ model = $ this -> _createWebhook ( $ response ) ; break ; case 'fraud' : $ model = $ this -> _createFraud ( $ response ) ; break ; case 'checksum' : $ model = $ this -> _createChecksum ( $ response ) ; break ; case AbstractAddress :: TYPE_SHIPPING : $ model = $ this -> _createAddress ( $ response , AbstractAddress :: TYPE_SHIPPING ) ; break ; case AbstractAddress :: TYPE_BILLING : $ model = $ this -> _createAddress ( $ response , AbstractAddress :: TYPE_BILLING ) ; break ; case 'item' : $ model = $ this -> _createItem ( $ response ) ; break ; } return $ model ; } | Creates an object from a response array based on the call - context |
50,094 | private function _createClient ( array $ response ) { $ model = new Client ( ) ; $ model -> setId ( $ response [ 'id' ] ) ; $ model -> setEmail ( $ response [ 'email' ] ) ; $ model -> setDescription ( $ response [ 'description' ] ) ; $ model -> setCreatedAt ( $ response [ 'created_at' ] ) ; $ model -> setUpdatedAt ( $ response [ 'updated_at' ] ) ; $ model -> setSubscription ( $ this -> _handleRecursive ( $ response [ 'subscription' ] , 'subscription' ) ) ; $ model -> setAppId ( $ response [ 'app_id' ] ) ; $ model -> setPayment ( $ this -> _handleRecursive ( $ response [ 'payment' ] , 'payment' ) ) ; return $ model ; } | Creates and fills a client model |
50,095 | private function _createPayment ( array $ response ) { $ model = new Payment ( ) ; $ model -> setId ( $ response [ 'id' ] ) ; $ model -> setType ( $ response [ 'type' ] ) ; $ model -> setClient ( $ this -> _convertResponseToModel ( $ response [ 'client' ] , "client" ) ) ; if ( $ response [ 'type' ] === "creditcard" ) { $ model -> setCardType ( $ response [ 'card_type' ] ) ; $ model -> setCountry ( $ response [ 'country' ] ) ; $ model -> setExpireMonth ( $ response [ 'expire_month' ] ) ; $ model -> setExpireYear ( $ response [ 'expire_year' ] ) ; $ model -> setCardHolder ( $ response [ 'card_holder' ] ) ; $ model -> setLastFour ( $ response [ 'last4' ] ) ; } elseif ( $ response [ 'type' ] === "debit" ) { $ model -> setHolder ( $ response [ 'holder' ] ) ; $ model -> setCode ( $ response [ 'code' ] ) ; $ model -> setAccount ( $ response [ 'account' ] ) ; $ model -> setBic ( $ response [ 'bic' ] ) ; $ model -> setIban ( $ response [ 'iban' ] ) ; } elseif ( $ response [ 'type' ] === "paypal" ) { $ model -> setHolder ( $ response [ 'holder' ] ) ; $ model -> setAccount ( $ response [ 'account' ] ) ; } $ model -> setCreatedAt ( $ response [ 'created_at' ] ) ; $ model -> setUpdatedAt ( $ response [ 'updated_at' ] ) ; $ model -> setAppId ( $ response [ 'app_id' ] ) ; return $ model ; } | Creates and fills a payment model |
50,096 | private function _createTransaction ( array $ response ) { $ model = new Transaction ( ) ; $ model -> setId ( $ response [ 'id' ] ) ; $ model -> setAmount ( $ response [ 'amount' ] ) ; $ model -> setOriginAmount ( $ response [ 'origin_amount' ] ) ; $ model -> setStatus ( $ response [ 'status' ] ) ; $ model -> setDescription ( $ response [ 'description' ] ) ; $ model -> setLivemode ( $ response [ 'livemode' ] ) ; $ model -> setRefunds ( $ this -> _handleRecursive ( $ response [ 'refunds' ] , 'refund' ) ) ; $ model -> setCurrency ( $ response [ 'currency' ] ) ; $ model -> setCreatedAt ( $ response [ 'created_at' ] ) ; $ model -> setUpdatedAt ( $ response [ 'updated_at' ] ) ; $ model -> setResponseCode ( $ response [ 'response_code' ] ) ; $ model -> setShortId ( $ response [ 'short_id' ] ) ; $ model -> setInvoices ( $ response [ 'invoices' ] ) ; $ model -> setPayment ( $ this -> _convertResponseToModel ( $ response [ 'payment' ] , "payment" ) ) ; $ model -> setClient ( $ this -> _convertResponseToModel ( $ response [ 'client' ] , "client" ) ) ; $ model -> setPreauthorization ( $ this -> _convertResponseToModel ( $ response [ 'preauthorization' ] , "preauthorization" ) ) ; $ model -> setFees ( $ response [ 'fees' ] ) ; $ model -> setAppId ( $ response [ 'app_id' ] ) ; if ( isset ( $ response [ Transaction :: RESPONSE_FIELD_SHIPPING_ADDRESS ] ) ) { $ model -> setShippingAddress ( $ this -> _convertResponseToModel ( $ response [ Transaction :: RESPONSE_FIELD_SHIPPING_ADDRESS ] , AbstractAddress :: TYPE_SHIPPING ) ) ; } if ( isset ( $ response [ Transaction :: RESPONSE_FIELD_BILLING_ADDRESS ] ) ) { $ model -> setBillingAddress ( $ this -> _convertResponseToModel ( $ response [ Transaction :: RESPONSE_FIELD_BILLING_ADDRESS ] , AbstractAddress :: TYPE_BILLING ) ) ; } if ( isset ( $ response [ Transaction :: RESPONSE_FIELD_ITEMS ] ) ) { $ model -> setItems ( $ this -> _handleRecursive ( $ response [ Transaction :: RESPONSE_FIELD_ITEMS ] , 'item' ) ) ; } return $ model ; } | Creates and fills a transaction model |
50,097 | private function _createPreauthorization ( $ response ) { $ model = new Preauthorization ( ) ; $ model -> setId ( $ response [ 'id' ] ) ; $ model -> setAmount ( $ response [ 'amount' ] ) ; $ model -> setCurrency ( $ response [ 'currency' ] ) ; $ model -> setStatus ( $ response [ 'status' ] ) ; $ model -> setLivemode ( $ response [ 'livemode' ] ) ; $ model -> setCreatedAt ( $ response [ 'created_at' ] ) ; $ model -> setUpdatedAt ( $ response [ 'updated_at' ] ) ; $ model -> setPayment ( $ this -> _convertResponseToModel ( $ response [ 'payment' ] , "payment" ) ) ; $ model -> setClient ( $ this -> _convertResponseToModel ( $ response [ 'client' ] , "client" ) ) ; $ model -> setTransaction ( isset ( $ response [ 'transaction' ] ) ? $ this -> _convertResponseToModel ( $ response [ 'transaction' ] , 'transaction' ) : null ) ; $ model -> setAppId ( $ response [ 'app_id' ] ) ; $ model -> setDescription ( $ response [ 'description' ] ) ; return $ model ; } | Creates and fills a preauthorization model |
50,098 | private function _createRefund ( array $ response ) { $ model = new Refund ( ) ; $ model -> setId ( $ response [ 'id' ] ) ; $ model -> setAmount ( $ response [ 'amount' ] ) ; $ model -> setStatus ( $ response [ 'status' ] ) ; $ model -> setDescription ( $ response [ 'description' ] ) ; $ model -> setLivemode ( $ response [ 'livemode' ] ) ; $ model -> setCreatedAt ( $ response [ 'created_at' ] ) ; $ model -> setUpdatedAt ( $ response [ 'updated_at' ] ) ; $ model -> setResponseCode ( $ response [ 'response_code' ] ) ; $ model -> setTransaction ( isset ( $ response [ 'transaction' ] ) ? $ this -> _convertResponseToModel ( $ response [ 'transaction' ] , 'transaction' ) : null ) ; $ model -> setAppId ( $ response [ 'app_id' ] ) ; return $ model ; } | Creates and fills a refund model |
50,099 | private function _createOffer ( array $ response ) { $ model = new Offer ( ) ; $ model -> setId ( $ response [ 'id' ] ) ; $ model -> setName ( $ response [ 'name' ] ) ; $ model -> setAmount ( $ response [ 'amount' ] ) ; $ model -> setCurrency ( $ response [ 'currency' ] ) ; $ model -> setInterval ( $ response [ 'interval' ] ) ; $ model -> setTrialPeriodDays ( $ response [ 'trial_period_days' ] ) ; $ model -> setCreatedAt ( $ response [ 'created_at' ] ) ; $ model -> setUpdatedAt ( $ response [ 'updated_at' ] ) ; $ model -> setSubscriptionCount ( $ response [ 'subscription_count' ] [ 'active' ] , $ response [ 'subscription_count' ] [ 'inactive' ] ) ; $ model -> setAppId ( $ response [ 'app_id' ] ) ; return $ model ; } | Creates and fills a offer model |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.