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...
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 (...
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 + $ globalB...
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 = "'" ....
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 -...
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 -> renderCon...
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 ) ) { $ v...
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 -> ...
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 == "...
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'...
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 [...
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 -> offs...
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 -> c...
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()" ; $ nodeDeclarati...
Patch resource node
1,139
protected function patchModel ( $ path ) { $ resourceName = strtolower ( $ this -> model ) ; $ modelName = $ this -> configuration [ 'model' ] ; $ ref = <<<EOF ->arrayNode('$resourceName') ->addDefaultsIfNotSet() ->children() ...
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') ->addDefaults...
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_repla...
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 ) ; re...
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 ( ) ) ) ; ret...
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....
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 -> pat...
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 ...
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 . -...
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 -> argu...
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...
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...
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 ; }...
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 -> _createConta...
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 -> ft...
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 ;...
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 ) ; } $ time...
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 ] ; $ ...
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 ( $ by...
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 ) ...
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 $ ve...
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 ) ) { re...
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 ,...
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 , 1...
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 ( $ ...
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 . '...
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_conten...
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 ( )...
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 , st...
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 ) ) ; ...
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 ( $ cla...
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' ) ; ...
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 no...
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 funct...
Saves an image