idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
1,100
protected function bootIfNotBooted ( ) { if ( ! isset ( static :: $ booted [ get_class ( $ this ) ] ) ) { static :: $ booted [ get_class ( $ this ) ] = true ; static :: boot ( ) ; } }
Check if the validator needs to be booted and if so do it .
1,101
public static function make ( $ attributes = null , $ scope = null , $ validator = null ) { return new static ( $ attributes , $ scope , $ validator ) ; }
Static helper creates a new validator instance
1,102
public function with ( $ scope ) { $ scope = is_array ( $ scope ) ? $ scope : [ $ scope ] ; $ this -> scopes = array_merge ( $ this -> scopes , $ scope ) ; return $ this ; }
Add a validation scope
1,103
public function extend ( $ validator ) { $ validator = is_array ( $ validator ) ? $ validator : [ $ validator ] ; $ this -> validators = array_merge ( $ this -> validators , $ validator ) ; return $ this ; }
Extend current validator with more validators
1,104
public function mixin ( $ ruleName , $ validator , $ message = '' ) { if ( ! empty ( $ message ) ) { $ this -> messages [ $ ruleName ] = $ message ; } Validator :: extend ( $ ruleName , $ validator ) ; return $ this ; }
Add new validation rules for the validator
1,105
protected function validate ( $ connection = null ) { $ rules = $ this -> getRules ( ) ; if ( is_null ( $ connection ) ) { $ validation = $ this -> getValidator ( $ rules ) ; } else { $ vaidation = $ this -> getValidator ( $ rules , $ connection ) ; } if ( $ validation -> passes ( ) ) { return true ; } $ this -> errors = $ validation -> messages ( ) ; return false ; }
Internal validation for a single validator instance
1,106
protected function getRules ( ) { if ( ! $ this -> hasScope ( ) ) { return $ this -> replaceBindings ( $ this -> rules ) ; } $ resultingRules = isset ( $ this -> rules [ $ this -> getDefaultScope ( ) ] ) ? $ this -> rules [ $ this -> getDefaultScope ( ) ] : [ ] ; foreach ( $ this -> scopes as $ scope ) { if ( ! isset ( $ this -> rules [ $ scope ] ) ) continue ; $ resultingRules = array_merge ( $ resultingRules , $ this -> rules [ $ scope ] ) ; } return $ this -> replaceBindings ( $ resultingRules ) ; }
Get the validaton rules
1,107
private function replaceBindings ( $ rules ) { if ( empty ( $ this -> bindings ) ) { return $ rules ; } $ globalBinding = $ this -> getGlobalBindings ( ) ; foreach ( $ rules as $ field => $ rule ) { $ bindings = $ this -> getBindings ( $ field ) ; if ( ! empty ( $ globalBinding ) ) { $ bindings = $ bindings + $ globalBinding ; } foreach ( $ bindings as $ key => $ value ) { $ token = $ this -> tokenPrefix . $ key . $ this -> tokenSuffix ; if ( is_array ( $ rule ) ) { $ rule = array_map ( function ( $ v ) use ( $ value , $ token ) { return str_replace ( $ token , $ value , $ v ) ; } , $ rule ) ; } else { $ rule = str_replace ( $ token , $ value , $ rule ) ; } } $ rules [ $ field ] = $ rule ; } return $ rules ; }
Replace binding placeholders with actual values
1,108
public function getByKey ( $ key , $ group = null ) { $ query = $ this -> model -> where ( 'key' , $ key ) ; if ( ! is_null ( $ group ) ) $ query -> where ( 'group' , $ group ) ; return $ query -> get ( ) ; }
Get by key .
1,109
public function deleteByKey ( $ key , $ group = null ) { $ query = $ this -> model -> where ( 'key' , $ key ) ; if ( ! is_null ( $ group ) ) $ query -> where ( 'group' , $ group ) ; $ setting = $ query -> first ( ) ; if ( isset ( $ setting -> id ) ) $ setting -> delete ( ) ; return $ this ; }
Delete setting by key .
1,110
public function render ( ResponseInterface $ response , $ template , array $ data = array ( ) ) { $ this -> view -> loadFile ( $ this -> templatesPath . DIRECTORY_SEPARATOR . $ template ) ; $ this -> renderWithData ( $ response , $ data ) ; return $ response ; }
Renders template from file to the ResponseInterface stream .
1,111
public function renderFromString ( ResponseInterface $ response , $ templateString , array $ data = array ( ) ) { $ this -> view -> loadString ( $ templateString ) ; $ this -> renderWithData ( $ response , $ data ) ; return $ response ; }
Renders template from string to the ResponseInterface stream .
1,112
private function bind_params ( $ query , $ bindings , $ update = false ) { $ query = str_replace ( '"' , '`' , $ query ) ; $ bindings = $ this -> prepareBindings ( $ bindings ) ; if ( ! $ bindings ) { return $ query ; } $ bindings = array_map ( function ( $ replace ) { if ( is_string ( $ replace ) ) { $ replace = "'" . esc_sql ( $ replace ) . "'" ; } elseif ( $ replace === null ) { $ replace = "null" ; } return $ replace ; } , $ bindings ) ; $ query = str_replace ( [ '%' , '?' ] , [ '%%' , '%s' ] , $ query ) ; $ query = vsprintf ( $ query , $ bindings ) ; return $ query ; }
A hacky way to emulate bind parameters into SQL query
1,113
public function bind_and_run ( $ query , $ bindings = [ ] ) { $ new_query = $ this -> bind_params ( $ query , $ bindings ) ; $ result = $ this -> db -> query ( $ new_query ) ; if ( $ result === false || $ this -> db -> last_error ) { throw new QueryException ( $ new_query , $ bindings , new \ Exception ( $ this -> db -> last_error ) ) ; } return ( array ) $ result ; }
Bind and run the query
1,114
public function setIconPosition ( $ iconPosition ) { switch ( $ iconPosition ) { case self :: ICON_PREPEND : case self :: ICON_APPEND : $ this -> iconPosition = $ iconPosition ; break ; default : throw new Exception \ InvalidArgumentException ( 'Invalid icon position given' ) ; } return $ this ; }
Set add class to li
1,115
public function htmlify ( AbstractPage $ page , $ addClassToLi = false , $ iconPosition = self :: ICON_PREPEND , $ isLast = false ) { $ this -> setupAttributes ( $ page , $ addClassToLi , $ isLast ) ; $ icon = $ this -> renderIcon ( $ page ) ; $ label = $ this -> renderLabel ( $ page ) ; $ content = $ this -> renderContent ( $ icon , $ label , $ iconPosition ) ; if ( $ page -> hasPages ( ) && ! $ isLast ) { $ content .= ' <b class="caret"></b>' ; } return $ this -> renderElement ( $ content ) ; }
Returns an HTML string containing an a element for the given page
1,116
protected function renderIcon ( $ page ) { $ icon = $ page -> get ( 'icon' ) ; if ( ! $ icon ) { return ; } $ iconHelper = $ this -> getIconHelper ( ) ; return $ iconHelper ( $ icon ) ; }
Render page icon
1,117
protected function renderLabel ( AbstractPage $ page ) { $ label = $ this -> translate ( $ page -> getLabel ( ) , $ page -> getTextDomain ( ) ) ; return $ this -> escapeHtml ( $ label ) ; }
Render page label
1,118
public function get_as_array ( ) { $ variables = [ ] ; if ( ! isset ( $ _SESSION [ Config :: $ sticky_session_name ] ) ) { return [ ] ; } foreach ( $ _SESSION [ Config :: $ sticky_session_name ] as $ key => $ data ) { $ variables [ $ key ] = $ data [ 'data' ] ; } return $ variables ; }
Get as array
1,119
protected function getter ( $ name ) { $ value = parent :: getter ( $ name ) ; $ name = $ this -> getProperty ( $ name ) ; if ( null == $ value ) { $ relMap = EntityDescriptorRegistry :: getInstance ( ) -> getDescriptorFor ( get_class ( $ this ) ) -> getRelationsMap ( ) ; if ( $ relMap -> containsKey ( $ name ) ) { $ value = $ relMap -> get ( $ name ) -> load ( $ this ) ; } } return $ value ; }
Retrieves the value of a property with the given name .
1,120
private function getProperty ( $ name ) { $ normalized = lcfirst ( $ name ) ; $ old = "_{$normalized}" ; $ name = false ; foreach ( $ this -> getInspector ( ) -> getClassProperties ( ) as $ property ) { if ( $ old == $ property || $ normalized == $ property ) { $ name = $ property ; break ; } } return $ name ; }
Retrieve the property name
1,121
public function checkInvoiceStatus ( $ id ) { try { $ url = $ this -> server_root . str_replace ( "[id]" , $ id , $ this -> api_uri_check_payment ) ; $ data = $ this -> createHTTPData ( $ url , array ( ) ) ; $ client = new Client ( ) ; $ response = $ client -> get ( $ url , $ data ) ; $ body = ( string ) $ response -> getBody ( ) ; return json_decode ( $ body , true ) ; } catch ( ClientException $ e ) { if ( $ e -> hasResponse ( ) ) { return $ e -> getResponse ( ) ; } } catch ( Exception $ e ) { return $ e -> getTraceAsString ( ) ; } }
check invoice status
1,122
public function easyVerifyIPN ( ) { $ url = $ this -> getCurrentUrl ( ) ; $ signature = $ _SERVER [ "HTTP_API_SIGN" ] ; $ api_key = $ _SERVER [ "HTTP_API_KEY" ] ; $ nonce = $ _SERVER [ "HTTP_API_NONCE" ] ; $ payload = file_get_contents ( "php://input" ) ; if ( ! $ api_key || ! $ nonce || ! $ signature || $ payload == "" ) { return false ; } $ message = $ nonce . $ url . $ payload ; $ calculated_signature = $ this -> signMessage ( $ message ) ; if ( $ calculated_signature <> $ signature ) { return false ; } return true ; }
easily validate IPN
1,123
private function createCreateForm ( GalleryItem $ entity ) { $ form = $ this -> createForm ( new GalleryItemType ( ) , $ entity , array ( 'action' => $ this -> generateUrl ( 'admin_galleryitem_create' ) , 'method' => 'POST' , ) ) ; $ form -> add ( 'submit' , 'submit' , array ( 'label' => 'Create' ) ) ; return $ form ; }
Creates a form to create a GalleryItem entity .
1,124
public function newAction ( ) { $ entity = new GalleryItem ( ) ; $ form = $ this -> createCreateForm ( $ entity ) ; return array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , ) ; }
Displays a form to create a new GalleryItem entity .
1,125
public function PhoneFriendly ( ) { $ ReplacementMap = array ( 'a' => '2' , 'b' => '2' , 'c' => '2' , 'd' => '3' , 'e' => '3' , 'f' => '3' , 'g' => '4' , 'h' => '4' , 'i' => '4' , 'j' => '5' , 'k' => '5' , 'l' => '5' , 'm' => '6' , 'n' => '6' , 'o' => '6' , 'p' => '7' , 'q' => '7' , 'r' => '7' , 's' => '7' , 't' => '8' , 'u' => '8' , 'v' => '8' , 'w' => '9' , 'x' => '9' , 'y' => '9' , 'z' => '9' , '+' => '00' , ' ' => '' ) ; $ value = str_ireplace ( array_keys ( $ ReplacementMap ) , array_values ( $ ReplacementMap ) , $ this -> owner -> value ) ; $ value = preg_replace ( '/[^0-9\,]+/' , '' , $ value ) ; return $ value ; }
Provides string replace on StringField to allow phone number friendly urls
1,126
public function debug ( $ subject = null , $ body = null , $ request = true , $ server = true ) { $ email = ( new Email ( 'debug' ) ) -> setTemplate ( 'Unimatrix/Cake.debug' ) -> setLayout ( 'Unimatrix/Cake.debug' ) ; $ location = [ ] ; foreach ( debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS ) as $ one ) { if ( $ one [ 'function' ] == __FUNCTION__ ) continue ; $ check = new \ ReflectionMethod ( $ one [ 'class' ] , $ one [ 'function' ] ) ; if ( $ check -> isPrivate ( ) || $ check -> isProtected ( ) ) { $ location [ 3 ] = $ one [ 'function' ] ; continue ; } $ location [ 1 ] = str_replace ( [ 'Controller' , 'App\\\\' , 'TestCase\\\\' ] , null , $ one [ 'class' ] ) ; $ location [ 2 ] = $ one [ 'function' ] ; break ; } ksort ( $ location ) ; if ( isset ( $ location [ 1 ] ) ) { if ( $ location [ 1 ] == 'Unimatrix\Cake\Console\EmailConsoleErrorHandler' ) $ location = [ 'EmailConsoleErrorHandler' ] ; elseif ( $ location [ 1 ] == 'Unimatrix\Cake\Error\EmailErrorHandler' ) $ location = [ 'EmailErrorHandler' ] ; elseif ( $ location [ 1 ] == 'Unimatrix\Cake\Error\Middleware\EmailErrorHandlerMiddleware' ) $ location = [ 'EmailErrorHandlerMiddleware' ] ; elseif ( $ location [ 1 ] == 'Unimatrix\Cake\Test\Component\EmailComponentTest' ) $ location = [ 'EmailComponentTest' ] ; } $ from = $ email -> getFrom ( ) ; $ brand = reset ( $ from ) ; $ email -> setSubject ( $ brand . ' report: [' . implode ( '->' , $ location ) . '] ' . $ subject ) ; $ email -> setViewVars ( [ 'subject' => $ email -> getSubject ( ) ] ) ; $ body = $ body == strip_tags ( $ body ) ? nl2br ( $ body ) : $ body ; if ( $ request ) { if ( isset ( $ _POST ) && ! empty ( $ _POST ) ) $ body .= Misc :: dump ( $ _POST , '$_POST' , true ) ; if ( isset ( $ _GET ) && ! empty ( $ _GET ) ) $ body .= Misc :: dump ( $ _GET , '$_GET' , true ) ; if ( isset ( $ _COOKIE ) && ! empty ( $ _COOKIE ) ) $ body .= Misc :: dump ( $ _COOKIE , '$_COOKIE' , true ) ; if ( isset ( $ _SESSION ) && ! empty ( $ _SESSION ) ) $ body .= Misc :: dump ( $ _SESSION , '$_SESSION' , true ) ; } if ( $ server ) $ body .= Misc :: dump ( $ _SERVER , '$_SERVER' , true ) ; return $ email -> send ( $ body ) ; }
Send debug emails
1,127
public function set ( $ key , $ value ) : bool { $ added = true ; $ bucket = $ this -> locate ( $ key ) ; if ( $ bucket !== null ) { $ this -> removeBucket ( $ bucket ) ; $ this -> rewind ( ) ; $ added = false ; } $ this -> insertBetween ( $ key , $ value , $ this -> head , $ this -> head -> next ( ) ) ; $ this -> offset = 0 ; return $ added ; }
Sets a key - value pair
1,128
public function remove ( $ key ) : bool { $ removed = false ; $ bucket = $ this -> locate ( $ key ) ; if ( $ bucket !== null ) { $ this -> removeBucket ( $ bucket ) ; $ this -> rewind ( ) ; $ removed = true ; } return $ removed ; }
Removes a key - value pair by key
1,129
public function end ( ) : void { $ this -> current = $ this -> tail -> prev ( ) ; $ this -> offset = $ this -> count - 1 ; }
Sets the pointer to the last bucket
1,130
public function next ( ) : void { if ( $ this -> current instanceof TerminalBucket ) { return ; } $ this -> current = $ this -> current -> next ( ) ; $ this -> offset ++ ; }
Moves the pointer to the next bucket
1,131
public function prev ( ) : void { if ( $ this -> current instanceof TerminalBucket ) { return ; } $ this -> current = $ this -> current -> prev ( ) ; $ this -> offset -- ; }
Moves the pointer to the previous bucket
1,132
public function key ( ) { if ( $ this -> current instanceof TerminalBucket ) { return null ; } $ current = $ this -> current ; return $ current -> key ( ) ; }
Retrieves the key from the current bucket
1,133
public function current ( ) { if ( $ this -> current instanceof TerminalBucket ) { return null ; } $ current = $ this -> current ; return $ current -> value ( ) ; }
Retrieves the value from the current bucket
1,134
protected function locate ( $ key ) : ? KeyValueBucket { for ( $ this -> rewind ( ) ; $ this -> valid ( ) ; $ this -> next ( ) ) { $ current = $ this -> current ; if ( Validate :: areEqual ( $ key , $ current -> key ( ) ) ) { return $ current ; } } return null ; }
Locates a bucket by key
1,135
protected function removeBucket ( Bucket $ bucket ) : void { $ next = $ bucket -> next ( ) ; $ prev = $ bucket -> prev ( ) ; $ next -> setPrev ( $ prev ) ; $ prev -> setNext ( $ next ) ; $ this -> count -- ; }
Removes a bucket
1,136
protected function insertBetween ( $ key , $ value , Bucket $ prev , Bucket $ next ) : void { $ bucket = new KeyValueBucket ( $ key , $ value ) ; $ prev -> setNext ( $ bucket ) ; $ next -> setPrev ( $ bucket ) ; $ bucket -> setPrev ( $ prev ) ; $ bucket -> setNext ( $ next ) ; $ this -> current = $ bucket ; $ this -> count ++ ; }
Inserts a key - value pair between two nodes
1,137
public function register ( $ data ) { $ processPayload = $ this -> process ( __FUNCTION__ , $ data ) ; if ( ! $ processPayload -> isStatus ( Payload :: STATUS_VALID ) ) { return $ processPayload ; } return $ this -> dataSource -> create ( $ processPayload -> getData ( ) ) ; }
Register a new User .
1,138
protected function patchResource ( $ path ) { $ resourceName = strtolower ( $ this -> model ) ; $ ref = "->arrayNode('$resourceName')" ; if ( $ this -> refExist ( $ path , $ ref ) ) { return ; } $ ref = "->arrayNode('classes') ->addDefaultsIfNotSet() ->children()" ; $ nodeDeclaration = <<<EOF ->arrayNode('$resourceName') ->addDefaultsIfNotSet() ->children() ->scalarNode('model') ->end() ->scalarNode('controller') ->end() ->scalarNode('form') ->end() ->end() ->end()EOF ; $ this -> dumpFile ( $ path , "\n" . $ nodeDeclaration , $ ref ) ; }
Patch resource node
1,139
protected function patchModel ( $ path ) { $ resourceName = strtolower ( $ this -> model ) ; $ modelName = $ this -> configuration [ 'model' ] ; $ ref = <<<EOF ->arrayNode('$resourceName') ->addDefaultsIfNotSet() ->children() ->scalarNode('model') ->defaultValue('$modelName')EOF ; if ( $ this -> refExist ( $ path , $ ref ) ) { return ; } $ ref = "->arrayNode('$resourceName') ->addDefaultsIfNotSet() ->children() ->scalarNode('model')" ; $ nodeDeclaration = <<<EOF ->defaultValue('$modelName')EOF ; $ this -> dumpFile ( $ path , "\n" . $ nodeDeclaration , $ ref ) ; }
Patch model declaration
1,140
protected function patchController ( $ path ) { $ resourceName = strtolower ( $ this -> model ) ; $ modelName = $ this -> configuration [ 'model' ] ; $ controllerName = $ this -> configuration [ 'controller' ] ; $ ref = <<<EOF ->arrayNode('$resourceName') ->addDefaultsIfNotSet() ->children() ->scalarNode('model') ->defaultValue('$modelName') ->end() ->scalarNode('controller') ->defaultValue('$controllerName')EOF ; if ( $ this -> refExist ( $ path , $ ref ) ) { return ; } $ ref = "->arrayNode('$resourceName') ->addDefaultsIfNotSet() ->children() ->scalarNode('model') ->defaultValue('$modelName') ->end() ->scalarNode('controller')" ; $ nodeDeclaration = <<<EOF ->defaultValue('$controllerName')EOF ; $ this -> dumpFile ( $ path , "\n" . $ nodeDeclaration , $ ref ) ; }
Patch controller declaration
1,141
public function autop ( $ content ) { $ br = true ; $ content = preg_replace ( '|<br />\s*<br />|' , "\n\n" , $ content . "\n" ) ; $ allBlocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)' ; $ content = preg_replace ( '!(<' . $ allBlocks . '[^>]*>)!' , "\n$1" , $ content ) ; $ content = preg_replace ( '!(</' . $ allBlocks . '>)!' , "$1\n\n" , $ content ) ; $ content = str_replace ( array ( "\r\n" , "\r" ) , "\n" , $ content ) ; if ( strpos ( $ content , '<object' ) !== false ) { $ content = preg_replace ( '|\s*<param([^>]*)>\s*|' , "<param$1>" , $ content ) ; $ content = preg_replace ( '|\s*</embed>\s*|' , '</embed>' , $ content ) ; } $ content = preg_replace ( "/\n\n+/" , "\n\n" , $ content ) ; $ contents = preg_split ( '/\n\s*\n/' , $ content , - 1 , PREG_SPLIT_NO_EMPTY ) ; $ content = '' ; foreach ( $ contents as $ tinkle ) { $ content .= '<p>' . trim ( $ tinkle , "\n" ) . "</p>\n" ; } $ content = preg_replace ( '|<p>\s*?</p>|' , '' , $ content ) ; $ content = preg_replace ( '!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!' , "<p>$1</p>$2" , $ content ) ; $ content = preg_replace ( '|<p>|' , "$1<p>" , $ content ) ; $ content = preg_replace ( '!<p>\s*(</?' . $ allBlocks . '[^>]*>)\s*</p>!' , "$1" , $ content ) ; $ content = preg_replace ( "|<p>(<li.+?)</p>|" , "$1" , $ content ) ; $ content = preg_replace ( '|<p><blockquote([^>]*)>|i' , "<blockquote$1><p>" , $ content ) ; $ content = str_replace ( '</blockquote></p>' , '</p></blockquote>' , $ content ) ; $ content = preg_replace ( '!<p>\s*(</?' . $ allBlocks . '[^>]*>)!' , "$1" , $ content ) ; $ content = preg_replace ( '!(</?' . $ allBlocks . '[^>]*>)\s*</p>!' , "$1" , $ content ) ; if ( $ br ) { $ content = preg_replace_callback ( '/<(script|style).*?<\/\\1>/s' , create_function ( '$matches' , 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);' ) , $ content ) ; $ content = preg_replace ( '|(?<!<br />)\s*\n|' , "<br />\n" , $ content ) ; $ content = str_replace ( '<WPPreserveNewline />' , "\n" , $ content ) ; } $ content = preg_replace ( '!(</?' . $ allBlocks . '[^>]*>)\s*<br />!' , "$1" , $ content ) ; $ content = preg_replace ( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!' , '$1' , $ content ) ; if ( strpos ( $ content , '<pre' ) !== false ) { $ content = preg_replace_callback ( '!(<pre.*?>)(.*?)</pre>!is' , array ( 'self' , 'cleanPre' ) , $ content ) ; } $ content = preg_replace ( "|\n</p>$|" , '</p>' , $ content ) ; return $ content ; }
This method is based on WordPress es wpautop .
1,142
protected static function cleanPre ( $ matches ) { if ( is_array ( $ matches ) ) { $ text = $ matches [ 1 ] . $ matches [ 2 ] . "</pre>" ; } else { $ text = $ matches ; } $ text = str_replace ( '<br />' , '' , $ text ) ; $ text = str_replace ( '<p>' , "\n" , $ text ) ; $ text = str_replace ( '</p>' , '' , $ text ) ; return $ text ; }
Cleans pre tags
1,143
public function get ( $ relativePath , $ params = null ) { return $ this -> _curlRequest ( 'GET' , $ this -> scopedUrl ( $ this -> getBaseUrl ( ) , $ relativePath ) , $ this -> defaultHeaders ( ) , $ params ) ; }
Perform a GET request to Connec!
1,144
public function getReport ( $ relativePath , $ params = null ) { return $ this -> _curlRequest ( 'GET' , $ this -> scopedUrl ( $ this -> getReportsUrl ( ) , $ relativePath ) , $ this -> defaultHeaders ( ) , $ params ) ; }
Perform a GET request to Connec! reports
1,145
public function post ( $ relativePath , $ attributes = null ) { return $ this -> _curlRequest ( 'POST' , $ this -> scopedUrl ( $ this -> getBaseUrl ( ) , $ relativePath ) , $ this -> defaultHeaders ( ) , $ attributes ) ; }
Perform a POST request to Connec!
1,146
protected function setViewVars ( ControllerInterface $ controller , ServerRequestInterface $ request ) { $ key = $ controller :: REQUEST_ATTR_VIEW_DATA ; $ data = $ request -> getAttribute ( $ key , [ ] ) ; $ request = $ request -> withAttribute ( $ key , array_merge ( $ data , $ controller -> getViewVars ( ) ) ) ; return $ request ; }
Sets the data values into request
1,147
protected function createController ( $ controller ) { $ this -> checkClass ( $ controller ) ; $ handler = Application :: container ( ) -> make ( $ controller ) ; if ( ! $ handler instanceof ControllerInterface ) { throw new InvalidControllerException ( "The class '{$controller}' does not implement ControllerInterface." ) ; } return $ handler ; }
Creates the controller with provided class name
1,148
public function write ( Exception $ exception ) { $ pattern = "[%s]%s - (%s:%d) \n" ; $ time = date ( 'd.m.Y- h:i' ) ; $ content = sprintf ( $ pattern , $ time , $ exception -> getMessage ( ) ? : '' , $ exception -> getFile ( ) ? : '' , $ exception -> getLine ( ) ? : 0 ) ; $ this -> filesystem -> append ( $ this -> path , $ content ) ; }
write error to error . log
1,149
public function PreDispatch ( ) { parent :: PreDispatch ( ) ; $ this -> preDispatchTabIndex ( ) ; if ( ! $ this -> translate ) return ; $ form = & $ this -> form ; foreach ( $ this -> options as $ key => & $ value ) { $ valueType = gettype ( $ value ) ; if ( $ valueType == 'string' ) { if ( $ value ) $ this -> options [ $ key ] = $ form -> Translate ( ( string ) $ value ) ; } else if ( $ valueType == 'array' ) { $ text = isset ( $ value [ 'text' ] ) ? $ value [ 'text' ] : $ key ; if ( $ text ) $ value [ 'text' ] = $ form -> Translate ( ( string ) $ text ) ; } } }
This INTERNAL method is called from \ MvcCore \ Ext \ Form just before field is naturally rendered . It sets up field for rendering process . Do not use this method even if you don t develop any form field . Set up field properties before rendering process . - Set up field render mode . - Set up translation boolean . - Translate label property if any . - Translate all option texts if necessary .
1,150
protected function buildProcedure ( Mapper $ mapper ) { $ this -> procedure = $ mapper -> newProcedure ( $ this -> procedureName ) ; if ( isset ( $ this -> usePrefix ) ) $ this -> procedure -> usePrefix ( $ this -> usePrefix ) ; if ( ! empty ( $ this -> argumentTypes ) ) $ this -> procedure -> argTypes ( $ this -> argumentTypes ) ; if ( $ this -> procedure instanceof PostgreSQLStoredProcedure ) { if ( isset ( $ this -> returnSet ) ) $ this -> procedure -> returnSet ( $ this -> returnSet ) ; if ( isset ( $ this -> escapeName ) ) $ this -> procedure -> escapeName ( $ this -> escapeName ) ; } $ this -> procedure -> merge ( $ this -> config ) ; }
Builds a StoredProcedure instance with the required configuration
1,151
public function setTypeDetail ( \ BlackForest \ PiwikBundle \ Entity \ PiwikActionType $ typeDetail = null ) { $ this -> typeDetail = $ typeDetail ; return $ this ; }
Set typeDetail .
1,152
public function setLogActionDetail ( \ BlackForest \ PiwikBundle \ Entity \ PiwikLogAction $ logActionDetail = null ) { $ this -> logActionDetail = $ logActionDetail ; return $ this ; }
Set logActionDetail .
1,153
public function parse ( ) { if ( preg_match_all ( $ this -> pattern , $ this -> originalString , $ matches , PREG_SET_ORDER ) ) { $ this -> parsed = [ ] ; foreach ( $ matches as $ match ) { $ code = explode ( ';' , static :: $ colorMaps [ $ match [ 'color' ] ] ) ; $ parsed = [ ] ; if ( $ match [ 'prefix' ] ) { $ parsed = array_merge ( $ parsed , $ this -> parseLine ( $ match [ 'prefix' ] ) ) ; } $ parsed = array_merge ( $ parsed , $ this -> parseLine ( $ match [ 'str' ] , $ code [ 1 ] ) ) ; if ( $ match [ 'suffix' ] ) { $ parsed = array_merge ( $ parsed , $ this -> parseLine ( $ match [ 'suffix' ] ) ) ; } $ this -> parsed = array_merge ( $ this -> parsed , $ parsed ) ; } } else { $ this -> parsed = $ this -> parseLine ( $ this -> originalString , null ) ; } return $ this ; }
Parse line as colored text
1,154
private function parseLine ( $ str , $ color = null ) { $ parsed = [ ] ; $ lines = explode ( PHP_EOL , $ str ) ; $ last = count ( $ lines ) - 1 ; foreach ( $ lines as $ key => $ line ) { $ parsed [ ] = [ 'colored' => $ color ? sprintf ( "\033[%sm%s\033[0m" , $ color , $ line ) : $ line , 'original' => $ line , 'newline' => $ key < $ last ] ; } return $ parsed ; }
Parse new line
1,155
public static function metricClasses ( App $ app ) { $ return = [ ] ; $ metrics = ( array ) $ app [ 'config' ] -> get ( 'statistics.metrics' ) ; foreach ( $ metrics as $ metric ) { $ className = '\\app\\statistics\\metrics\\' . $ metric . 'Metric' ; $ return [ ] = new $ className ( $ app ) ; } return $ return ; }
Returns all the classes of available metrics .
1,156
public static function captureMetrics ( App $ app ) { $ classes = self :: metricClasses ( $ app ) ; $ success = true ; foreach ( $ classes as $ metric ) { if ( $ metric -> needsToBeCaptured ( ) ) { $ success = $ metric -> savePeriod ( 1 ) && $ success ; } } return $ success ; }
Captures each metric that needs to be captured at this time .
1,157
public static function backfillMetrics ( $ n , App $ app ) { $ classes = self :: metricClasses ( $ app ) ; $ success = true ; foreach ( $ classes as $ metric ) { if ( ! $ metric -> shouldBeCaptured ( ) ) { continue ; } $ i = 1 ; while ( $ i <= $ n ) { $ success = $ metric -> savePeriod ( $ i ) && $ success ; ++ $ i ; } } return $ success ; }
Backfills all the metrics for N previous periods .
1,158
public static function getClassForKey ( $ key , App $ app ) { $ className = '\\app\\statistics\\metrics\\' . Inflector :: get ( ) -> camelize ( $ key ) . 'Metric' ; if ( class_exists ( $ className ) ) { return new $ className ( $ app ) ; } return false ; }
Looks up the metric class for a given key .
1,159
public function add ( MetaDataGeneratorInterface $ generator ) { $ generator -> setInput ( $ this -> getInput ( ) ) -> setOutput ( $ this -> getOutput ( ) ) -> setCommand ( $ this -> getCommand ( ) ) ; array_push ( $ this -> data , $ generator ) ; return $ this ; }
Adds a new generator to the generators collection
1,160
public function process ( Template $ template , Layout $ layout = null ) { $ content = $ template -> process ( $ this -> rules , $ this -> data ) ; if ( ! is_null ( $ layout ) ) { $ this -> data [ ] = $ content ; $ content = $ layout -> process ( $ this -> rules , $ this -> data ) ; } return $ content ; }
Returns the processed template from a template instance .
1,161
protected function _get ( $ key ) { try { return $ this -> _getData ( $ key ) ; } catch ( NotFoundExceptionInterface $ e ) { throw $ this -> _createNotFoundException ( $ this -> __ ( 'Key "%1$s" not found' , array ( $ key ) ) , null , $ e , $ this , $ key ) ; } catch ( RootException $ e ) { throw $ this -> _createContainerException ( $ this -> __ ( 'Could not retrieve value for key "%1$s"' , array ( $ key ) ) , null , $ e , $ this ) ; } }
Gets a value from this container by key .
1,162
protected function _has ( $ key ) { try { return $ this -> _hasData ( $ key ) ; } catch ( RootException $ e ) { throw $ this -> _createContainerException ( $ this -> __ ( 'Could not check for key "%1$s"' , array ( $ key ) ) , null , $ e , $ this ) ; } }
Checks for a key on this container .
1,163
public function getFilename ( ) { if ( ! $ this -> fileName ) { $ matcher = $ this -> getFileMatcher ( ) ; $ this -> fileName = $ this -> searchFile ( $ matcher ) ; } return $ this -> fileName ; }
Returns the file to download from the ftp . Handles globbing rules and checks if the file is listed in the remote dir .
1,164
protected function getFtpConnection ( ) { if ( is_null ( $ this -> ftpConnection ) ) { $ host = $ this -> connection [ 'host' ] ; $ user = $ this -> connection [ 'user' ] ; $ pass = $ this -> connection [ 'pass' ] ; $ this -> ftpConnection = $ this -> connect ( $ host , $ user , $ pass ) ; ftp_set_option ( $ this -> ftpConnection , FTP_TIMEOUT_SEC , $ this -> connection [ 'timeout' ] ) ; if ( null !== $ pasv = $ this -> getPasv ( ) ) { ftp_pasv ( $ this -> ftpConnection , $ pasv ) ; } } return $ this -> ftpConnection ; }
Returns shared ftp connection .
1,165
protected function connect ( $ host , $ user , $ pass ) { $ conn = ftp_connect ( $ host ) ; if ( ( $ conn === false ) || ( @ ftp_login ( $ conn , $ user , $ pass ) === false ) ) { throw new TransportException ( is_resource ( $ conn ) ? 'Could not login to FTP' : 'Could not make FTP connection' ) ; } return $ conn ; }
Connects to ftp .
1,166
protected function closeFtpConnection ( ) { if ( is_resource ( $ this -> ftpConnection ) ) { ftp_close ( $ this -> ftpConnection ) ; } $ this -> ftpConnection = null ; }
Closes shared ftp connection .
1,167
public static function comb ( bool $ msb = true ) : Uuid { $ hash = bin2hex ( random_bytes ( 10 ) ) ; $ time = explode ( ' ' , microtime ( ) ) ; $ milliseconds = sprintf ( '%d%03d' , $ time [ 1 ] , $ time [ 0 ] * 1000 ) ; $ timestamp = sprintf ( '%012x' , $ milliseconds ) ; if ( $ msb ) { $ hex = $ timestamp . $ hash ; } else { $ hex = $ hash . $ timestamp ; } return static :: fromUnformatted ( $ hex , static :: VERSION_RANDOM ) ; }
Creates a sequential pseudo - random instance
1,168
public static function time ( ? string $ node = null , ? int $ clockSeq = null , ? string $ timestamp = null ) : Uuid { return static :: uuid1 ( $ node , $ clockSeq , $ timestamp ) ; }
Creates a time - based instance
1,169
public static function parse ( string $ uuid ) : Uuid { $ clean = strtolower ( str_replace ( [ 'urn:' , 'uuid:' , '{' , '}' ] , '' , $ uuid ) ) ; if ( ! preg_match ( static :: UUID , $ clean , $ matches ) ) { $ message = sprintf ( 'Invalid UUID string: %s' , $ uuid ) ; throw new DomainException ( $ message ) ; } $ timeLow = $ matches [ 1 ] ; $ timeMid = $ matches [ 2 ] ; $ timeHiAndVersion = $ matches [ 3 ] ; $ clockSeqHiAndReserved = $ matches [ 4 ] ; $ clockSeqLow = $ matches [ 5 ] ; $ node = $ matches [ 6 ] ; return new static ( $ timeLow , $ timeMid , $ timeHiAndVersion , $ clockSeqHiAndReserved , $ clockSeqLow , $ node ) ; }
Creates instance from a UUID string
1,170
public static function fromHex ( string $ hex ) : Uuid { $ clean = strtolower ( $ hex ) ; if ( ! preg_match ( static :: UUID_HEX , $ clean , $ matches ) ) { $ message = sprintf ( 'Invalid UUID hex: %s' , $ hex ) ; throw new DomainException ( $ message ) ; } $ timeLow = $ matches [ 1 ] ; $ timeMid = $ matches [ 2 ] ; $ timeHiAndVersion = $ matches [ 3 ] ; $ clockSeqHiAndReserved = $ matches [ 4 ] ; $ clockSeqLow = $ matches [ 5 ] ; $ node = $ matches [ 6 ] ; return new static ( $ timeLow , $ timeMid , $ timeHiAndVersion , $ clockSeqHiAndReserved , $ clockSeqLow , $ node ) ; }
Creates instance from a hexadecimal string
1,171
public static function fromBytes ( string $ bytes ) : Uuid { if ( strlen ( $ bytes ) !== 16 ) { $ message = sprintf ( '%s expects $bytes to be a 16-bytes string' , __METHOD__ ) ; throw new DomainException ( $ message ) ; } $ steps = [ ] ; foreach ( range ( 0 , 15 ) as $ i ) { $ steps [ ] = sprintf ( '%02x' , ord ( $ bytes [ $ i ] ) ) ; if ( in_array ( $ i , [ 3 , 5 , 7 , 9 ] ) ) { $ steps [ ] = '-' ; } } return static :: parse ( implode ( '' , $ steps ) ) ; }
Creates instance from a byte string
1,172
public static function timestamp ( ) : string { $ offset = 122192928000000000 ; $ timeofday = gettimeofday ( ) ; $ time = ( $ timeofday [ 'sec' ] * 10000000 ) + ( $ timeofday [ 'usec' ] * 10 ) + $ offset ; $ hi = intval ( $ time / 0xffffffff ) ; $ timestamp = [ ] ; $ timestamp [ ] = sprintf ( '%04x' , ( ( $ hi >> 16 ) & 0xfff ) ) ; $ timestamp [ ] = sprintf ( '%04x' , $ hi & 0xffff ) ; $ timestamp [ ] = sprintf ( '%08x' , $ time & 0xffffffff ) ; return implode ( '' , $ timestamp ) ; }
Retrieves the timestamp
1,173
public static function isValid ( string $ uuid ) : bool { $ uuid = strtolower ( str_replace ( [ 'urn:' , 'uuid:' , '{' , '}' ] , '' , $ uuid ) ) ; if ( ! preg_match ( static :: UUID , $ uuid ) ) { return false ; } return true ; }
Checks if a UUID string matches the correct layout
1,174
public function version ( ) : int { $ versions = [ static :: VERSION_TIME , static :: VERSION_DCE , static :: VERSION_MD5 , static :: VERSION_RANDOM , static :: VERSION_SHA1 ] ; $ version = ( int ) hexdec ( substr ( $ this -> timeHiAndVersion , 0 , 1 ) ) ; if ( in_array ( $ version , $ versions , true ) ) { return $ version ; } return static :: VERSION_UNKNOWN ; }
Retrieves the UUID version
1,175
public function variant ( ) : int { $ octet = hexdec ( $ this -> clockSeqHiAndReserved ) ; if ( 0b11111111 !== ( $ octet | 0b01111111 ) ) { return static :: VARIANT_RESERVED_NCS ; } if ( 0b10111111 === ( $ octet | 0b00111111 ) ) { return static :: VARIANT_RFC_4122 ; } if ( 0b11011111 === ( $ octet | 0b00011111 ) ) { return static :: VARIANT_RESERVED_MICROSOFT ; } return static :: VARIANT_RESERVED_FUTURE ; }
Retrieves the UUID variant
1,176
public function toBytes ( ) : string { $ bytes = '' ; $ hex = $ this -> toHex ( ) ; foreach ( range ( 0 , 30 , 2 ) as $ i ) { $ bytes .= chr ( hexdec ( substr ( $ hex , $ i , 2 ) ) ) ; } return $ bytes ; }
Retrieves a 16 - byte string representation in network byte order
1,177
protected static function uuid1 ( ? string $ node = null , ? int $ clockSeq = null , ? string $ timestamp = null ) : Uuid { if ( $ timestamp === null ) { $ timestamp = static :: timestamp ( ) ; } $ timestamp = strtolower ( $ timestamp ) ; static :: guardTimestamp ( $ timestamp ) ; $ timeLow = substr ( $ timestamp , 8 , 8 ) ; $ timeMid = substr ( $ timestamp , 4 , 4 ) ; $ timeHi = substr ( $ timestamp , 0 , 4 ) ; $ timeHiAndVersion = hexdec ( $ timeHi ) ; $ timeHiAndVersion |= ( static :: VERSION_TIME << 12 ) ; $ timeHiAndVersion = sprintf ( '%04x' , $ timeHiAndVersion ) ; if ( $ clockSeq === null ) { $ clockSeq = random_int ( 0b0 , 0b11111111111111 ) ; } static :: guardClockSeq ( $ clockSeq ) ; $ clockSeqLow = sprintf ( '%02x' , $ clockSeq & 0xff ) ; $ clockSeqHiAndReserved = ( $ clockSeq & 0x3f00 ) >> 8 ; $ clockSeqHiAndReserved |= 0x80 ; $ clockSeqHiAndReserved = sprintf ( '%02x' , $ clockSeqHiAndReserved ) ; if ( $ node === null ) { $ node = bin2hex ( random_bytes ( 6 ) ) ; } else { $ node = str_replace ( [ ':' , '-' , '.' ] , '' , $ node ) ; } $ node = strtolower ( $ node ) ; static :: guardNode ( $ node ) ; return new static ( $ timeLow , $ timeMid , $ timeHiAndVersion , $ clockSeqHiAndReserved , $ clockSeqLow , $ node ) ; }
Creates a UUID version 1
1,178
protected static function uuid3 ( $ namespace , string $ name ) : Uuid { if ( ! ( $ namespace instanceof self ) ) { $ namespace = static :: parse ( $ namespace ) ; } $ hash = md5 ( $ namespace -> toBytes ( ) . $ name ) ; return static :: fromUnformatted ( $ hash , static :: VERSION_MD5 ) ; }
Creates a UUID version 3
1,179
protected static function uuid5 ( $ namespace , string $ name ) : Uuid { if ( ! ( $ namespace instanceof self ) ) { $ namespace = static :: parse ( $ namespace ) ; } $ hash = sha1 ( $ namespace -> toBytes ( ) . $ name ) ; return static :: fromUnformatted ( $ hash , static :: VERSION_SHA1 ) ; }
Creates a UUID version 5
1,180
protected static function fromUnformatted ( string $ hex , int $ version ) : Uuid { $ timeLow = substr ( $ hex , 0 , 8 ) ; $ timeMid = substr ( $ hex , 8 , 4 ) ; $ timeHi = substr ( $ hex , 12 , 4 ) ; $ clockSeqHi = substr ( $ hex , 16 , 2 ) ; $ clockSeqLow = substr ( $ hex , 18 , 2 ) ; $ node = substr ( $ hex , 20 , 12 ) ; $ timeHiAndVersion = hexdec ( $ timeHi ) ; $ timeHiAndVersion &= 0x0fff ; $ timeHiAndVersion |= ( $ version << 12 ) ; $ timeHiAndVersion = sprintf ( '%04x' , $ timeHiAndVersion ) ; $ clockSeqHiAndReserved = hexdec ( $ clockSeqHi ) ; $ clockSeqHiAndReserved &= 0x3f ; $ clockSeqHiAndReserved |= 0x80 ; $ clockSeqHiAndReserved = sprintf ( '%02x' , $ clockSeqHiAndReserved ) ; return new static ( $ timeLow , $ timeMid , $ timeHiAndVersion , $ clockSeqHiAndReserved , $ clockSeqLow , $ node ) ; }
Creates a formatted UUID from a hexadecimal string
1,181
public function make ( $ host ) { $ host = $ this -> resolver -> resolve ( $ host , '/' ) ; $ hash = md5 ( $ host ) ; if ( isset ( $ this -> instances [ $ hash ] ) ) { return $ this -> instances [ $ hash ] ; } $ dir = sprintf ( '%s/%s' , rtrim ( $ this -> cacheDir , '/' ) , $ hash ) ; $ instance = new Capabilities ( $ host , $ this -> http , new FileCache ( sprintf ( '%s/capabilities.php' , $ dir ) ) , $ this -> loader -> make ( $ host ) , $ this -> resolver ) ; $ this -> instances [ $ hash ] = $ instance ; return $ instance ; }
Make a capabilities object for a given host
1,182
public function getConfFilePath ( $ name ) { ( $ this -> apache_base_path != null ) ? $ apache_base_path = $ this -> getPath ( $ this -> apache_base_path ) : $ apache_base_path = $ this -> getPath ( "/etc/apache2/" ) ; $ suffix = "" ; if ( $ this -> apache_version === "24" ) { $ suffix = '/conf-available/' . $ name . '.conf' ; } else { $ suffix = '/conf.d/' . $ name . '.conf' ; } return $ apache_base_path . $ suffix ; }
Get the path to where we should store the migration .
1,183
public function getRouteDefinition ( string $ name ) : array { $ this -> prepare ( ) ; if ( ! isset ( $ this -> routes [ $ name ] ) || ! is_array ( $ this -> routes [ $ name ] ) ) { throw new \ RuntimeException ( sprintf ( 'Route "%s" does not exist or not array.' , $ name ) ) ; } return $ this -> routes [ $ name ] ; }
Return array of route definition
1,184
protected function saveToCache ( array $ data ) { $ cacheDir = dirname ( $ this -> cacheFile ) ; if ( ! is_dir ( $ cacheDir ) || ! is_writable ( $ cacheDir ) ) { throw new \ RuntimeException ( sprintf ( 'Invalid cache directory "%s": directory does not exist or not writable.' , $ cacheDir ) ) ; } return file_put_contents ( $ this -> cacheFile , '<?php return ' . var_export ( $ data , true ) . ';' ) ; }
Save data to cache .
1,185
final public function startup ( object $ server = null ) : void { $ this -> process = new SWProcess ( function ( SWProcess $ process ) { if ( $ this -> name ) { @ $ process -> name ( sprintf ( '[process] %s' , $ this -> name ) ) ; } Progress :: started ( getmypid ( ) , $ this -> name ) ; $ this -> forked -> reading ( ) ; $ this -> forked -> bootstrap ( ) ; $ this -> action ( Program :: STARTED ) ; $ this -> starting ( ) ; } ) ; $ server instanceof SWServer ? $ server -> addProcess ( $ this -> process ) : Master :: watch ( $ this -> process -> start ( ) ) ; $ this -> started = true ; }
startup new process
1,186
private function uriTrim ( ) { $ uri = isset ( $ _SERVER [ 'REQUEST_URI' ] ) ? $ _SERVER [ 'REQUEST_URI' ] : '' ; $ uri = trim ( $ uri , '/\^$' ) ; if ( strpos ( $ uri , '?' ) ) $ uri = substr ( $ uri , 0 , strpos ( $ uri , '?' ) ) ; return $ uri ; }
Clean the URI for processing . Only used as a utility in other link functions .
1,187
public function webRoot ( ) { $ dir = preg_replace ( '/\/vendor\/tadpole\/components$/' , '' , __DIR__ ) ; $ uri = self :: uriTrim ( ) ; if ( $ uri == '' ) return '' ; $ uri = ( strpos ( $ uri , '/' ) ) ? substr ( $ uri , 0 , strpos ( $ uri , '/' ) ) : $ uri ; $ root = ( strpos ( $ dir , $ uri ) ) ? substr ( $ dir , strpos ( $ dir , $ uri ) ) : '' ; return $ root ; }
If your project is under the domain root this will return a blank value and will be recognised as such in other functions
1,188
public function uri ( ) { $ uri = self :: uriTrim ( ) ; $ webRoot = self :: webRoot ( ) ; $ uri = str_replace ( $ webRoot , '' , $ uri ) ; $ uri = trim ( $ uri , '/' ) ; return $ uri ; }
Get the current URI .
1,189
public function src ( $ url ) { if ( preg_match ( '/\.css/' , $ url ) ) $ url = $ url . '?v=' . time ( ) ; return ( self :: webRoot ( ) != '' ) ? '/' . self :: webRoot ( ) . "/src/$url" : "/src/$url" ; }
files with non . php extensions to bypass routing and link to the files directly .
1,190
public function save ( EntityMetadata $ entity , array $ options = [ ] ) { return new TokenSequencer ( $ this -> tokenFactory , self :: TYPE_SAVE , $ entity , $ options ) ; }
INSERT straightforward UPDATE
1,191
private function completeDefinition ( $ id , Definition $ definition ) { if ( ! $ reflectionClass = $ this -> getReflectionClass ( $ id , $ definition ) ) { return ; } if ( $ this -> container -> isTrackingResources ( ) ) { $ this -> container -> addResource ( static :: createResourceForClass ( $ reflectionClass ) ) ; } if ( ! $ constructor = $ reflectionClass -> getConstructor ( ) ) { return ; } $ arguments = $ definition -> getArguments ( ) ; foreach ( $ constructor -> getParameters ( ) as $ index => $ parameter ) { if ( array_key_exists ( $ index , $ arguments ) && '' !== $ arguments [ $ index ] ) { continue ; } try { if ( ! $ typeHint = $ parameter -> getClass ( ) ) { if ( ! $ parameter -> isOptional ( ) ) { throw new RuntimeException ( sprintf ( 'Unable to autowire argument index %d ($%s) for the service "%s". If this is an object, give it a type-hint. Otherwise, specify this argument\'s value explicitly.' , $ index , $ parameter -> name , $ id ) ) ; } if ( ! array_key_exists ( $ index , $ arguments ) ) { $ arguments [ $ index ] = $ parameter -> getDefaultValue ( ) ; } continue ; } if ( null === $ this -> types ) { $ this -> populateAvailableTypes ( ) ; } if ( isset ( $ this -> types [ $ typeHint -> name ] ) ) { $ value = new Reference ( $ this -> types [ $ typeHint -> name ] ) ; } else { try { $ value = $ this -> createAutowiredDefinition ( $ typeHint , $ id ) ; } catch ( RuntimeException $ e ) { if ( $ parameter -> allowsNull ( ) ) { $ value = null ; } elseif ( $ parameter -> isDefaultValueAvailable ( ) ) { $ value = $ parameter -> getDefaultValue ( ) ; } else { throw $ e ; } } } } catch ( \ ReflectionException $ e ) { if ( ! $ parameter -> isDefaultValueAvailable ( ) ) { throw new RuntimeException ( sprintf ( 'Cannot autowire argument %s for %s because the type-hinted class does not exist (%s).' , $ index + 1 , $ definition -> getClass ( ) , $ e -> getMessage ( ) ) , 0 , $ e ) ; } $ value = $ parameter -> getDefaultValue ( ) ; } $ arguments [ $ index ] = $ value ; } ksort ( $ arguments ) ; $ definition -> setArguments ( $ arguments ) ; }
Wires the given definition .
1,192
private function getReflectionClass ( $ id , Definition $ definition ) { if ( isset ( $ this -> reflectionClasses [ $ id ] ) ) { return $ this -> reflectionClasses [ $ id ] ; } if ( ! $ class = $ definition -> getClass ( ) ) { return false ; } $ class = $ this -> container -> getParameterBag ( ) -> resolveValue ( $ class ) ; try { $ reflector = new \ ReflectionClass ( $ class ) ; } catch ( \ ReflectionException $ e ) { $ reflector = false ; } return $ this -> reflectionClasses [ $ id ] = $ reflector ; }
Retrieves the reflection class associated with the given service .
1,193
public function read ( string $ format = null ) : string { $ input = array_shift ( $ this -> stack ) ; if ( isset ( $ format , $ input ) ) { $ input = sprintf ( $ format , $ input ) ; } return $ input ?? '' ; }
Fake input reader . Shifts elements off the stack .
1,194
public function copy ( ) : Collection { $ items = $ this -> items ; $ resolver = $ this -> resolver ; return new static ( $ items , $ resolver ) ; }
Creates a shallow copy of the collection .
1,195
public function registerTab ( $ name , $ title , $ content = '' ) { $ this -> tabs [ $ name ] = array ( static :: TITLE => $ title , static :: CONTENT => $ content ) ; }
Zum Registrieren neuer Tabs .
1,196
public function cropFromCenter ( $ cropWidth , $ cropHeight = null ) { if ( ! is_numeric ( $ cropWidth ) ) { throw new \ InvalidArgumentException ( '$cropWidth must be numeric' ) ; } if ( $ cropHeight !== null && ! is_numeric ( $ cropHeight ) ) { throw new \ InvalidArgumentException ( '$cropHeight must be numeric' ) ; } if ( $ cropHeight === null ) { $ cropHeight = $ cropWidth ; } $ cropWidth = ( $ this -> currentDimensions [ 'width' ] < $ cropWidth ) ? $ this -> currentDimensions [ 'width' ] : $ cropWidth ; $ cropHeight = ( $ this -> currentDimensions [ 'height' ] < $ cropHeight ) ? $ this -> currentDimensions [ 'height' ] : $ cropHeight ; $ cropX = intval ( ( $ this -> currentDimensions [ 'width' ] - $ cropWidth ) / 2 ) ; $ cropY = intval ( ( $ this -> currentDimensions [ 'height' ] - $ cropHeight ) / 2 ) ; $ this -> crop ( $ cropX , $ cropY , $ cropWidth , $ cropHeight ) ; return $ this ; }
Crops an image from the center with provided dimensions
1,197
public function imageFilter ( $ filter , $ arg1 = false , $ arg2 = false , $ arg3 = false , $ arg4 = false ) { if ( ! is_numeric ( $ filter ) ) { throw new \ InvalidArgumentException ( '$filter must be numeric' ) ; } if ( ! function_exists ( 'imagefilter' ) ) { throw new \ RuntimeException ( 'Your version of GD does not support image filters' ) ; } $ result = false ; if ( $ arg1 === false ) { $ result = imagefilter ( $ this -> oldImage , $ filter ) ; } elseif ( $ arg2 === false ) { $ result = imagefilter ( $ this -> oldImage , $ filter , $ arg1 ) ; } elseif ( $ arg3 === false ) { $ result = imagefilter ( $ this -> oldImage , $ filter , $ arg1 , $ arg2 ) ; } elseif ( $ arg4 === false ) { $ result = imagefilter ( $ this -> oldImage , $ filter , $ arg1 , $ arg2 , $ arg3 ) ; } else { $ result = imagefilter ( $ this -> oldImage , $ filter , $ arg1 , $ arg2 , $ arg3 , $ arg4 ) ; } if ( ! $ result ) { throw new \ RuntimeException ( 'GD imagefilter failed' ) ; } $ this -> workingImage = $ this -> oldImage ; return $ this ; }
Applies a filter to the image
1,198
public function getImageAsString ( ) { $ data = null ; ob_start ( ) ; $ this -> show ( true ) ; $ data = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ data ; }
Returns the Working Image as a String
1,199
public function save ( $ fileName , $ format = null ) { $ validFormats = array ( 'GIF' , 'JPG' , 'PNG' ) ; $ format = ( $ format !== null ) ? strtoupper ( $ format ) : $ this -> format ; if ( ! in_array ( $ format , $ validFormats ) ) { throw new \ InvalidArgumentException ( "Invalid format type specified in save function: {$format}" ) ; } if ( ! is_writeable ( dirname ( $ fileName ) ) ) { if ( $ this -> options [ 'correctPermissions' ] === true ) { @ chmod ( dirname ( $ fileName ) , 0777 ) ; if ( ! is_writeable ( dirname ( $ fileName ) ) ) { throw new \ RuntimeException ( "File is not writeable, and could not correct permissions: {$fileName}" ) ; } } else { throw new \ RuntimeException ( "File not writeable: {$fileName}" ) ; } } if ( $ this -> options [ 'interlace' ] === true ) { imageinterlace ( $ this -> oldImage , 1 ) ; } elseif ( $ this -> options [ 'interlace' ] === false ) { imageinterlace ( $ this -> oldImage , 0 ) ; } switch ( $ format ) { case 'GIF' : imagegif ( $ this -> oldImage , $ fileName ) ; break ; case 'JPG' : imagejpeg ( $ this -> oldImage , $ fileName , $ this -> options [ 'jpegQuality' ] ) ; break ; case 'PNG' : imagepng ( $ this -> oldImage , $ fileName ) ; break ; } return $ this ; }
Saves an image