idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
58,000
|
public static function Text ( $ Mixed , $ AddBreaks = TRUE ) { if ( ! is_string ( $ Mixed ) ) return self :: To ( $ Mixed , 'Text' ) ; else { $ Charset = C ( 'Garden.Charset' , 'UTF-8' ) ; $ Result = htmlspecialchars ( strip_tags ( preg_replace ( '`<br\s?/?>`' , "\n" , html_entity_decode ( $ Mixed , ENT_QUOTES , $ Charset ) ) ) , ENT_NOQUOTES , $ Charset ) ; if ( $ AddBreaks && C ( 'Garden.Format.ReplaceNewlines' , TRUE ) ) $ Result = nl2br ( trim ( $ Result ) ) ; return $ Result ; } }
|
Takes a mixed variable formats it for display on the screen as plain text .
|
58,001
|
public static function To ( $ Mixed , $ FormatMethod ) { if ( $ FormatMethod == '' ) return $ Mixed ; if ( is_string ( $ Mixed ) ) { if ( method_exists ( 'Gdn_Format' , $ FormatMethod ) ) { $ Mixed = self :: $ FormatMethod ( $ Mixed ) ; } elseif ( function_exists ( $ FormatMethod ) ) { $ Mixed = $ FormatMethod ( $ Mixed ) ; } elseif ( $ Formatter = Gdn :: Factory ( $ FormatMethod . 'Formatter' ) ) { ; $ Mixed = $ Formatter -> Format ( $ Mixed ) ; } else { $ Mixed = Gdn_Format :: Text ( $ Mixed ) ; } } else if ( is_array ( $ Mixed ) ) { foreach ( $ Mixed as $ Key => $ Val ) { $ Mixed [ $ Key ] = self :: To ( $ Val , $ FormatMethod ) ; } } else if ( is_object ( $ Mixed ) ) { foreach ( get_object_vars ( $ Mixed ) as $ Prop => $ Val ) { $ Mixed -> $ Prop = self :: To ( $ Val , $ FormatMethod ) ; } } return $ Mixed ; }
|
Takes a mixed variable formats it in the specified format type and returns it .
|
58,002
|
public static function ToDate ( $ Timestamp = '' ) { if ( $ Timestamp == '' ) $ Timestamp = time ( ) ; elseif ( ! is_numeric ( $ Timestamp ) ) $ Timestamp = self :: ToTimestamp ( $ Timestamp ) ; return date ( 'Y-m-d' , $ Timestamp ) ; }
|
Format a timestamp or the current time to go into the database .
|
58,003
|
public static function ToTimestamp ( $ DateTime = '' ) { if ( ( $ TestTime = strtotime ( $ DateTime ) ) !== FALSE ) { return $ TestTime ; } elseif ( preg_match ( '/^(\d{4})-(\d{1,2})-(\d{1,2})(?:\s{1}(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/' , $ DateTime , $ Matches ) ) { $ Year = $ Matches [ 1 ] ; $ Month = $ Matches [ 2 ] ; $ Day = $ Matches [ 3 ] ; $ Hour = ArrayValue ( 4 , $ Matches , 0 ) ; $ Minute = ArrayValue ( 5 , $ Matches , 0 ) ; $ Second = ArrayValue ( 6 , $ Matches , 0 ) ; return mktime ( $ Hour , $ Minute , $ Second , $ Month , $ Day , $ Year ) ; } elseif ( preg_match ( '/^(\d{4})-(\d{1,2})-(\d{1,2})$/' , $ DateTime , $ Matches ) ) { $ Year = $ Matches [ 1 ] ; $ Month = $ Matches [ 2 ] ; $ Day = $ Matches [ 3 ] ; return mktime ( 0 , 0 , 0 , $ Month , $ Day , $ Year ) ; } else { return FALSE ; } }
|
Convert a datetime to a timestamp
|
58,004
|
public static function ToTimezone ( $ Timestamp ) { static $ GuestHourOffset ; $ Now = time ( ) ; $ Session = Gdn :: Session ( ) ; $ HourOffset = 0 ; if ( $ Session -> UserID > 0 ) { $ HourOffset = $ Session -> User -> HourOffset ; } elseif ( class_exists ( 'DateTimeZone' ) ) { if ( ! isset ( $ GuestHourOffset ) ) { $ GuestTimeZone = C ( 'Garden.GuestTimeZone' ) ; if ( $ GuestTimeZone ) { try { $ TimeZone = new DateTimeZone ( $ GuestTimeZone ) ; $ Offset = $ TimeZone -> getOffset ( new DateTime ( 'now' , new DateTimeZone ( 'UTC' ) ) ) ; $ GuestHourOffset = floor ( $ Offset / 3600 ) ; } catch ( Exception $ Ex ) { $ GuestHourOffset = 0 ; LogException ( $ Ex ) ; } } } $ HourOffset = $ GuestHourOffset ; } if ( $ HourOffset <> 0 ) { $ SecondsOffset = $ HourOffset * 3600 ; $ Timestamp += $ SecondsOffset ; $ Now += $ SecondsOffset ; } return $ Timestamp ; }
|
Formats a timestamp to the current user s timezone .
|
58,005
|
public static function Url ( $ Mixed ) { if ( ! is_string ( $ Mixed ) ) return self :: To ( $ Mixed , 'Url' ) ; $ Mixed = strip_tags ( html_entity_decode ( $ Mixed , ENT_COMPAT , 'UTF-8' ) ) ; $ Mixed = strtr ( $ Mixed , self :: $ _UrlTranslations ) ; $ UnicodeSupport = ( preg_replace ( '`[\pP]`u' , '' , 'P' ) != '' ) ; if ( $ UnicodeSupport ) $ Mixed = preg_replace ( '`[\pP\pS\s]`u' , '-' , $ Mixed ) ; else $ Mixed = preg_replace ( '`[\s_[^\w\d]]`' , '-' , $ Mixed ) ; $ Mixed = preg_replace ( '`-+`' , '-' , strtolower ( $ Mixed ) ) ; $ Mixed = trim ( $ Mixed , '-' ) ; return rawurlencode ( $ Mixed ) ; }
|
Creates URL codes containing only lowercase Roman letters digits and hyphens .
|
58,006
|
public static function Unserialize ( $ SerializedString ) { $ Result = $ SerializedString ; if ( is_string ( $ SerializedString ) ) { if ( substr_compare ( 'a:' , $ SerializedString , 0 , 2 ) === 0 || substr_compare ( 'O:' , $ SerializedString , 0 , 2 ) === 0 ) $ Result = unserialize ( $ SerializedString ) ; elseif ( substr_compare ( 'obj:' , $ SerializedString , 0 , 4 ) === 0 ) $ Result = json_decode ( substr ( $ SerializedString , 4 ) , FALSE ) ; elseif ( substr_compare ( 'arr:' , $ SerializedString , 0 , 4 ) === 0 ) $ Result = json_decode ( substr ( $ SerializedString , 4 ) , TRUE ) ; } return $ Result ; }
|
Takes a serialized variable and unserializes it back into it s original state .
|
58,007
|
private function createPalette ( \ Imagick $ imagick ) { switch ( $ imagick -> getImageColorspace ( ) ) { case \ Imagick :: COLORSPACE_RGB : case \ Imagick :: COLORSPACE_SRGB : return new RGB ( ) ; case \ Imagick :: COLORSPACE_CMYK : return new CMYK ( ) ; case \ Imagick :: COLORSPACE_GRAY : return new Grayscale ( ) ; default : throw new NotSupportedException ( 'Only RGB and CMYK colorspace are currently supported' ) ; } }
|
Returns the palette corresponding to an \ Imagick resource colorspace .
|
58,008
|
private function getVersion ( \ Imagick $ imagick ) { $ v = $ imagick -> getVersion ( ) ; list ( $ version ) = sscanf ( $ v [ 'versionString' ] , 'ImageMagick %s %04d-%02d-%02d %s %s' ) ; return $ version ; }
|
Returns ImageMagick version .
|
58,009
|
public function sortableConcreteData ( ) { $ list = [ ] ; foreach ( $ this as $ index => $ value ) { $ list [ $ index ] = $ value ; } return $ list ; }
|
this function return the filtered and sanitized internal array
|
58,010
|
private function sortableResetArray ( $ list ) { $ removedKeys = array_keys ( $ this -> baseConcreteData ) ; foreach ( $ list as $ index => $ value ) { $ this [ $ index ] = $ value ; if ( ( $ key = array_search ( $ index , $ removedKeys ) ) !== false ) { unset ( $ removedKeys [ $ key ] ) ; } } unset ( $ list ) ; foreach ( $ removedKeys as $ index ) { unset ( $ this [ $ index ] ) ; } if ( method_exists ( $ this , 'rewind' ) ) { $ this -> rewind ( ) ; } }
|
this function remap current data array with a new one
|
58,011
|
private function sortableCallByReference ( $ function , $ arguments ) { $ list = $ this -> sortableConcreteData ( ) ; $ params = array_merge ( [ & $ list ] , $ arguments ) ; $ result = call_user_func_array ( $ function , $ params ) ; if ( $ result ) { $ this -> sortableResetArray ( $ list ) ; } return $ result ; }
|
call a function by reference and send this array filtered data to it as argument one and then resort the data by new array that calculated in the function
|
58,012
|
private function sortableCallSpecial ( $ function , $ arguments ) { $ params = array_merge ( array_slice ( $ arguments , 0 , 1 ) , [ $ this -> sortableConcreteData ( ) ] , array_values ( array_slice ( $ arguments , 1 ) ) ) ; return call_user_func_array ( $ function , $ params ) ; }
|
call a function by reference and send this array filtered data to it as argument two
|
58,013
|
protected function renderPage ( $ page , $ widgetInstances ) { $ title = isset ( $ page [ 'title' ] ) ? $ page [ 'title' ] : '' ; $ widgets = array_map ( function ( $ w ) { return $ w -> render ( ) ; } , $ widgetInstances ) ; $ banner = $ this -> banner ; $ page_number = $ this -> pageNumber ; if ( ! isset ( $ page [ 'finish' ] ) ) { if ( $ page_number > $ this -> startPage ) $ show_back = true ; if ( $ page_number < $ this -> getNumberOfPages ( ) - 1 ) $ show_next = true ; } $ prev_page_number = $ page_number - 1 ; $ messages = $ _SESSION [ 'messages' ] ?? null ; unset ( $ _SESSION [ 'messages' ] ) ; require __DIR__ . "/../templates/web/main.tpl.php" ; }
|
Renders the page
|
58,014
|
protected function findProxyFile ( string $ class ) : ? string { $ class = substr ( $ class , 24 ) ; $ filePath = $ this -> directory . '/Proxy/' . str_replace ( '\\' , '/' , $ class ) . '.php' ; if ( file_exists ( $ filePath ) && is_file ( $ filePath ) ) { return $ filePath ; } return null ; }
|
Find proxy file
|
58,015
|
public function createPathAlias ( $ alias , $ path ) { $ this -> _alias = $ alias ; $ this -> _path = $ path ; Yii :: setPathOfAlias ( $ alias , $ path ) ; }
|
Creates a path alias for the extension .
|
58,016
|
public static function deleteBlankLines ( array $ activeConfig = [ ] ) { $ cleanedActiveConfig = [ ] ; foreach ( array_map ( 'trim' , $ activeConfig ) as $ line ) { if ( $ line != '' ) { $ cleanedActiveConfig [ ] = $ line ; } } return $ cleanedActiveConfig ; }
|
Trim all blank lines .
|
58,017
|
public static function continuingDirectives ( array $ activeConfig = [ ] ) { $ cleanedActiveConfig = [ ] ; foreach ( $ activeConfig as $ line ) { if ( ! self :: setLineIfPrevious ( $ line ) ) { $ cleanedActiveConfig [ ] = $ line ; } } return $ cleanedActiveConfig ; }
|
Reassembles discontinued simple directives in one line .
|
58,018
|
private static function setLineIfPrevious ( & $ line ) { static $ previousLine = '' ; if ( $ previousLine ) { $ line = $ previousLine . ' ' . trim ( $ line ) ; $ previousLine = '' ; } if ( preg_match ( '/(.+)\\\$/' , $ line , $ container ) ) { $ previousLine = $ container [ 1 ] ; } return $ previousLine ; }
|
Helps to gather continuing lines as one .
|
58,019
|
private static function normalize ( & $ val ) : void { if ( is_array ( $ val ) ) { array_walk ( $ val , [ __CLASS__ , 'normalize' ] ) ; } elseif ( is_scalar ( $ val ) ) { $ val = strlen ( $ val ) ? $ val : null ; } }
|
Internal helper to recursively normalize a value .
|
58,020
|
public function exists ( $ path ) { $ metadata = $ this -> dropbox -> getMetadata ( $ this -> pathRoot . $ path ) ; return is_array ( $ metadata ) && isset ( $ metadata [ 'path' ] ) ; }
|
If path exists
|
58,021
|
public function showAction ( BrandModel $ brandModel ) { $ deleteForm = $ this -> createDeleteForm ( $ brandModel ) ; return array ( 'entity' => $ brandModel , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
|
Finds and displays a BrandModel entity .
|
58,022
|
private function createDeleteForm ( BrandModel $ brandModel ) { return $ this -> createFormBuilder ( ) -> setAction ( $ this -> generateUrl ( 'ecommerce_brandmodel_delete' , array ( 'id' => $ brandModel -> getId ( ) ) ) ) -> setMethod ( 'DELETE' ) -> getForm ( ) ; }
|
Creates a form to delete a BrandModel entity .
|
58,023
|
public function modelJsonAction ( $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ brand = $ em -> getRepository ( 'EcommerceBundle:Brand' ) -> find ( $ id ) ; if ( ! $ brand instanceof Brand ) { throw $ this -> createNotFoundException ( 'Unable to find Brand entity.' ) ; } $ entities = $ em -> getRepository ( 'EcommerceBundle:BrandModel' ) -> findByBrand ( $ brand ) ; $ returnValues = array ( ) ; foreach ( $ entities as $ entity ) { $ returnValues [ $ entity -> getId ( ) ] = $ entity -> getName ( ) ; } return new JsonResponse ( $ returnValues ) ; }
|
Returns a list of BrandModel entities in JSON format .
|
58,024
|
public static function cnpj ( $ cnpj ) { return substr ( $ cnpj , 0 , 2 ) . '.' . substr ( $ cnpj , 2 , 3 ) . '.' . substr ( $ cnpj , 5 , 3 ) . '/' . substr ( $ cnpj , 8 , 4 ) . '-' . substr ( $ cnpj , 12 , 2 ) ; }
|
Formats Brazilian CNPJ
|
58,025
|
public static function cpf ( $ cpf ) { return substr ( $ cpf , 0 , 3 ) . '.' . substr ( $ cpf , 3 , 3 ) . '.' . substr ( $ cpf , 6 , 3 ) . '-' . substr ( $ cpf , 9 , 2 ) ; }
|
Formats Brazilian CPF
|
58,026
|
public static function dateRange ( $ date0 , $ date1 , $ prefix = true ) { $ date0 = strtotime ( 'Today 00:00:00' , strtotime ( $ date0 ) ) ; $ date1 = strtotime ( 'Today 00:00:00' , strtotime ( $ date1 ) ) ; $ range = [ date ( 'd/m/Y' , min ( $ date0 , $ date1 ) ) ] ; if ( $ date0 != $ date1 ) { $ range [ ] = date ( 'd/m/Y' , max ( $ date0 , $ date1 ) ) ; } $ prefix = ( $ prefix ? 'Data' . ( $ date0 != $ date1 ? 's' : '' ) . ': ' : '' ) ; $ glue = ( strtotime ( '+ 1 day' , $ date0 ) == $ date1 ? ' e ' : ' a ' ) ; return $ prefix . implode ( $ glue , $ range ) ; }
|
Formats two dates to represent a range
|
58,027
|
public static function money ( $ val , $ country = 'BR' ) { switch ( $ country ) { case 'US' : $ arr = [ 'US$' , ',' , '.' ] ; break ; case 'BR' : default : $ arr = [ 'R$' , '.' , ',' ] ; } return ( $ arr [ 0 ] . ' ' . number_format ( $ val , 2 , $ arr [ 2 ] , $ arr [ 1 ] ) ) ; }
|
Formats money value based in a country code
|
58,028
|
public static function naturalLanguageJoin ( array $ arr , string $ last = null , string $ glue = null ) { $ last_item = array_pop ( $ arr ) ; if ( $ arr ) { return implode ( $ glue ?? ', ' , $ arr ) . ' ' . ( $ last ?? 'and' ) . ' ' . $ last_item ; } return $ last_item ; }
|
Implodes an array with and and before last element
|
58,029
|
public static function multiReplace ( $ map , $ subject , $ repeat = false ) { do { $ count = $ c = 0 ; foreach ( $ map as $ search => $ replace ) { $ subject = str_replace ( $ search , $ replace , $ subject , $ c ) ; $ count += $ c ; } } while ( $ repeat && $ count > 0 ) ; return $ subject ; }
|
Replaces keys of an array by its values in a string
|
58,030
|
private function registerSettingsPackage ( ) { $ this -> registerProvider ( SettingsServiceProvider :: class ) ; $ this -> alias ( 'Settings' , \ Arcanedev \ LaravelSettings \ Facades \ Settings :: class ) ; }
|
Register the Settings Package .
|
58,031
|
private function registerHasherPackage ( ) { $ this -> registerProvider ( HasherServiceProvider :: class ) ; $ this -> alias ( 'Hasher' , \ Arcanedev \ Hasher \ Facades \ Hasher :: class ) ; }
|
Register the Hasher Package .
|
58,032
|
private function registerLaravelHtmlPackage ( ) { $ this -> registerProvider ( HtmlServiceProvider :: class ) ; $ this -> alias ( 'Html' , \ Arcanedev \ LaravelHtml \ Facades \ Html :: class ) ; $ this -> alias ( 'Form' , \ Arcanedev \ LaravelHtml \ Facades \ Form :: class ) ; }
|
Register the Laravel Html Package
|
58,033
|
private function registerSeoHelperPackage ( ) { $ this -> registerProvider ( SeoHelperServiceProvider :: class ) ; $ this -> alias ( 'SeoHelper' , \ Arcanedev \ SeoHelper \ Facades \ SeoHelper :: class ) ; }
|
Register SEO Helper Package .
|
58,034
|
private function registerBreadcrumbsPackage ( ) { $ this -> registerProvider ( BreadcrumbsServiceProvider :: class ) ; $ this -> alias ( 'Breadcrumbs' , \ Arcanedev \ Breadcrumbs \ Facades \ Breadcrumbs :: class ) ; }
|
Register the Breadcrumbs Package .
|
58,035
|
private function registerNotifyPackage ( ) { $ this -> registerProvider ( \ Arcanedev \ Notify \ NotifyServiceProvider :: class ) ; $ this -> alias ( 'Notify' , \ Arcanedev \ Notify \ Facades \ Notify :: class ) ; }
|
Register the Notify Package .
|
58,036
|
private function registerSidebarPackage ( ) { $ this -> registerProvider ( SidebarServiceProvider :: class ) ; $ this -> alias ( 'Sidebar' , \ Arcanesoft \ Sidebar \ Facades \ Sidebar :: class ) ; }
|
Register the Sidebar Package .
|
58,037
|
public function getTime ( ? int $ format = null ) : float { $ result = $ this -> endTime - $ this -> startTime ; return $ this -> formatTime ( $ result , $ format ) ; }
|
Returns the resulting time
|
58,038
|
final protected function filter ( array & $ data , array $ scheme = [ ] ) { if ( empty ( $ scheme ) ) { $ scheme = $ this -> scheme ; } if ( empty ( $ scheme [ 'filter' ] ) ) { return $ data ; } $ filter = [ ] ; foreach ( $ scheme [ 'filter' ] as $ f => $ r ) { $ filter [ $ f ] = $ r ; } if ( empty ( $ filter ) ) { return $ data ; } $ result = filter_var_array ( $ data , $ filter ) ; if ( empty ( $ result ) ) { return $ data ; } foreach ( $ result as $ key => $ value ) { $ data [ $ key ] = $ value ; } return $ data ; }
|
Filters the fields value by using the set filter statements
|
58,039
|
protected function validate ( array & $ data , array $ fields = [ ] , bool $ filter_before_validate = true , array $ skip = [ ] ) { static $ validator ; if ( empty ( $ fields ) ) { if ( empty ( $ this -> scheme [ 'fields' ] ) ) { return $ data ; } $ fields = $ this -> scheme [ 'fields' ] ; } if ( empty ( $ fields ) ) { return $ data ; } foreach ( $ data as $ key => $ val ) { if ( in_array ( $ key , $ skip ) ) { continue ; } if ( $ filter_before_validate && ! empty ( $ fields [ $ key ] [ 'filter' ] ) ) { if ( ! is_array ( $ fields [ $ key ] [ 'filter' ] ) ) { $ fields [ $ key ] [ 'filter' ] = ( array ) $ fields [ $ key ] [ 'filter' ] ; } foreach ( $ fields [ $ key ] [ 'filter' ] as $ filter ) { $ options = [ ] ; if ( is_array ( $ filter ) ) { $ options = $ filter [ 1 ] ; $ filter = $ filter [ 0 ] ; } $ result = filter_var ( $ val , $ filter , $ options ) ; if ( $ result === false ) { $ this -> addError ( $ key , sprintf ( $ this -> app -> language -> get ( 'validator.filter' ) , $ filter ) ) ; } else { $ data [ $ key ] = $ result ; } } } if ( empty ( $ fields [ $ key ] [ 'validate' ] ) ) { continue ; } if ( empty ( $ validator ) ) { $ validator = new Validator ( ) ; } if ( ! is_array ( $ fields [ $ key ] [ 'validate' ] ) ) { $ fields [ $ key ] [ 'validate' ] = ( array ) $ fields [ $ key ] [ 'validate' ] ; } $ validator -> setValue ( $ val ) ; foreach ( $ fields [ $ key ] [ 'validate' ] as $ rule ) { $ validator -> parseRule ( $ rule ) ; $ validator -> validate ( ) ; if ( ! $ validator -> isValid ( ) ) { $ result = $ validator -> getResult ( ) ; if ( is_array ( $ result ) ) { $ result = vsprintf ( $ this -> app -> language -> get ( $ result [ 0 ] ) , $ result [ 1 ] ) ; } else { $ result = $ this -> app -> language -> get ( $ result ) ; } $ this -> errors [ $ key ] [ ] = $ result ; } } } return $ data ; }
|
Validates data against the set validation rules
|
58,040
|
protected function paramsToString ( ) { $ out = "" ; foreach ( $ this -> attributes as $ name => $ value ) { $ out .= " {$name}=\"{$value}\"" ; } return $ this -> standalone ? $ out . " /" : $ out ; }
|
transforms all params to their string form
|
58,041
|
public static function set ( array & $ values , $ path , $ value ) { if ( is_array ( $ path ) ) { $ segments = $ path ; } else { $ path = ( string ) $ path ; $ path = ltrim ( $ path , sprintf ( '%s ' , static :: PATH_DELIMITER ) ) ; $ path = rtrim ( $ path , sprintf ( '%s %s' , static :: PATH_DELIMITER , static :: PATH_WILDCARD ) ) ; $ segments = explode ( static :: PATH_DELIMITER , $ path ) ; } while ( count ( $ segments ) > 1 ) { $ key = array_shift ( $ segments ) ; if ( ! array_key_exists ( $ key , $ values ) || ! is_array ( $ values [ $ key ] ) ) { $ values [ $ key ] = [ ] ; } $ values = & $ values [ $ key ] ; } $ values [ array_shift ( $ segments ) ] = $ value ; }
|
Set an array value using dot notation .
|
58,042
|
public static function arrayWalkRecursiveDelete ( & $ values , Closure $ callback , $ data = null ) { foreach ( $ values as $ key => & $ value ) { if ( is_array ( $ value ) ) { $ value = static :: arrayWalkRecursiveDelete ( $ value , $ callback , $ data ) ; } if ( $ callback ( $ value , $ key , $ data ) ) { unset ( $ values [ $ key ] ) ; } } return $ values ; }
|
Remove any elements where the callback returns true .
|
58,043
|
public static function mergeUnique ( array $ first , array $ second , $ preserveNumericKeys = false ) { foreach ( $ second as $ key => $ value ) { if ( $ value instanceof MergeReplaceKeyInterface ) { $ first [ $ key ] = $ value -> getData ( ) ; } elseif ( array_key_exists ( $ key , $ first ) ) { if ( $ value instanceof MergeRemoveKey ) { unset ( $ first [ $ key ] ) ; } elseif ( ! $ preserveNumericKeys && is_int ( $ key ) ) { if ( ! is_scalar ( $ value ) || ! in_array ( $ value , $ first , true ) ) { $ first [ ] = $ value ; } } elseif ( is_array ( $ value ) && is_array ( $ first [ $ key ] ) ) { $ first [ $ key ] = static :: merge ( $ first [ $ key ] , $ value , $ preserveNumericKeys ) ; } else { $ first [ $ key ] = $ value ; } } else { if ( ! ( $ value instanceof MergeRemoveKey ) ) { $ first [ $ key ] = $ value ; } } } return $ first ; }
|
Merge two arrays together . If an integer key exists in both arrays and preserveNumericKeys is false the value from the second array will be appended to the first array if it does not exists . If both values are arrays they are merged together else the value of the second array overwrites the one of the first array .
|
58,044
|
public function process ( ServerRequestInterface $ request , RequestHandlerInterface $ handler ) : ResponseInterface { try { return $ handler -> handle ( $ request ) ; } catch ( Throwable $ e ) { throw new HttpException ( $ e ) ; } }
|
Proxy the given handler and wrap any exception in a http exception .
|
58,045
|
final public function add ( $ capability , $ specUrl , $ specVersion ) { if ( array_key_exists ( $ capability , $ this -> rpc_capabilities ) ) { $ this -> logger -> warning ( "Cannot add capability $capability: duplicate entry" ) ; return false ; } else { $ this -> rpc_capabilities [ $ capability ] = array ( 'specUrl' => $ specUrl , 'specVersion' => $ specVersion ) ; $ this -> logger -> debug ( "Added capability $capability" ) ; return true ; } }
|
Add a capability
|
58,046
|
final public function delete ( $ capability ) { if ( array_key_exists ( $ capability , $ this -> rpc_capabilities ) ) { unset ( $ this -> rpc_capabilities [ $ capability ] ) ; $ this -> logger -> debug ( "Deleted capability $capability" ) ; return true ; } else { $ this -> logger -> warning ( "Cannot delete capability $capability: entry not found" ) ; return false ; } }
|
Delete a capability
|
58,047
|
public function addGroupBy ( $ field ) { $ this -> groupByFields = array_merge ( $ this -> groupByFields , is_array ( $ field ) ? $ field : func_get_args ( ) ) ; return $ this ; }
|
Add a GROUP BY clause to the query
|
58,048
|
public function parameter ( $ value ) { if ( is_array ( $ value ) ) { if ( count ( $ value ) === 1 ) { $ value = current ( $ value ) ; } else { return $ this -> parameters ( $ value ) ; } } $ this -> parameters [ ] = $ value ; return '?' ; }
|
Insert a parameter placeholder into the query
|
58,049
|
public function getByPrimaryKey ( $ primaryKeys ) { if ( is_array ( $ primaryKeys ) && empty ( $ primaryKeys ) ) { return [ ] ; } $ records = $ this -> getByField ( $ this -> entity -> getPrimaryKey ( ) , $ primaryKeys ) ; if ( ! is_array ( $ primaryKeys ) ) { return current ( $ records ) ; } return $ records ; }
|
Get one or multiple records by primary key
|
58,050
|
public function getByField ( $ fieldName , $ keys ) { $ keys = ( array ) $ keys ; if ( empty ( $ keys ) ) { return [ ] ; } $ table = $ this -> entity -> getTable ( ) ; if ( ! empty ( $ this -> with ) ) { if ( strpos ( $ fieldName , '.' ) === false ) { $ fieldName = $ this -> getTableAlias ( $ table ) . '.' . $ fieldName ; } } $ this -> manager -> commit ( ) ; return $ this -> process ( $ this -> getSelectQuery ( $ table , $ this -> getFields ( $ table ) , $ fieldName , $ keys ) -> query ( $ this -> parameters ) ) ; }
|
Get one or multiple records by a specific field
|
58,051
|
public function getSingleByField ( $ fieldName , $ key ) { $ record = $ this -> setMaxResults ( 1 ) -> getByField ( $ fieldName , $ key ) ; return reset ( $ record ) ; }
|
Fetch a single record from the database by field
|
58,052
|
public function delete ( $ parameters = [ ] ) { if ( ! is_array ( $ parameters ) ) { if ( func_num_args ( ) !== 1 ) { $ parameters = func_get_args ( ) ; } $ this -> deleteByPrimaryKey ( $ parameters ) ; return ; } $ relations = $ this -> entity -> getRelations ( ) ; if ( empty ( $ relations ) ) { $ this -> manager -> postPendingQuery ( new PendingQuery ( $ this -> entity , PendingQuery :: TYPE_UPDATE , $ this -> applyFilters ( $ this -> queryBuilder -> delete ( $ this -> entity -> getTable ( ) ) ) , $ this -> parameters ) ) ; } else { $ this -> deleteRecords ( $ this -> with ( array_keys ( $ relations ) ) -> get ( array_merge ( $ this -> parameters , $ parameters ) ) ) ; } }
|
Delete selected records
|
58,053
|
public function count ( array $ parameters = [ ] ) { $ this -> manager -> commit ( ) ; $ count = $ this -> applyFilters ( $ this -> queryBuilder -> select ( 'count(*) as count' ) -> from ( $ this -> entity -> getTable ( ) , $ this -> alias ) ) -> query ( array_merge ( $ this -> parameters , $ parameters ) ) -> fetch ( ) ; return $ count [ 'count' ] ; }
|
Count selected records
|
58,054
|
private function validateAddress ( $ ip_address ) { return filter_var ( $ ip_address , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) || filter_var ( $ ip_address , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) ; }
|
Validate IP address .
|
58,055
|
public function verifyAssertion ( $ assertion ) { $ postdata = 'assertion=' . urlencode ( $ assertion ) . '&audience=' . $ this -> guessAudience ( ) ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , "https://verifier.login.persona.org/verify" ) ; curl_setopt ( $ ch , CURLOPT_POST , true ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ postdata ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , false ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYHOST , 2 ) ; $ response = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; return json_decode ( $ response ) ; }
|
Verify the validity of the assertion received from the user
|
58,056
|
public function parseString ( $ string ) { $ lines = preg_split ( '(\r\n|\r|\n)' , $ string ) ; $ lineCount = count ( $ lines ) ; $ diffs = array ( ) ; $ diff = null ; $ collected = array ( ) ; for ( $ i = 0 ; $ i < $ lineCount ; ++ $ i ) { if ( preg_match ( '(^---\\s+(?P<file>\\S+))' , $ lines [ $ i ] , $ fromMatch ) && preg_match ( '(^\\+\\+\\+\\s+(?P<file>\\S+))' , $ lines [ $ i + 1 ] , $ toMatch ) ) { if ( $ diff !== null ) { $ this -> parseFileDiff ( $ diff , $ collected ) ; $ diffs [ ] = $ diff ; $ collected = array ( ) ; } $ diff = new \ Arbit \ VCSWrapper \ Diff \ Collection ( $ fromMatch [ 'file' ] , $ toMatch [ 'file' ] ) ; ++ $ i ; } else { $ collected [ ] = $ lines [ $ i ] ; } } if ( count ( $ collected ) && ( $ diff !== null ) ) { $ this -> parseFileDiff ( $ diff , $ collected ) ; $ diffs [ ] = $ diff ; } return $ diffs ; }
|
Parse diff string
|
58,057
|
protected function parseFileDiff ( \ Arbit \ VCSWrapper \ Diff \ Collection $ diff , array $ lines ) { $ chunks = array ( ) ; while ( count ( $ lines ) ) { while ( ! preg_match ( '(^@@\\s+-(?P<start>\\d+)(?:,\\s*(?P<startrange>\\d+))?\\s+\\+(?P<end>\\d+)(?:,\\s*(?P<endrange>\\d+))?\\s+@@)' , $ last = array_shift ( $ lines ) , $ match ) ) { if ( $ last === null ) { break 2 ; } } $ chunk = new \ Arbit \ VCSWrapper \ Diff \ Chunk ( $ match [ 'start' ] , ( isset ( $ match [ 'startrange' ] ) ? max ( 1 , $ match [ 'startrange' ] ) : 1 ) , $ match [ 'end' ] , ( isset ( $ match [ 'endrange' ] ) ? max ( 1 , $ match [ 'endrange' ] ) : 1 ) ) ; $ diffLines = array ( ) ; $ last = null ; while ( count ( $ lines ) && ( preg_match ( '(^(?P<type>[+ -])(?P<line>.*))' , $ last = array_shift ( $ lines ) , $ match ) || ( strpos ( $ last , '\\ No newline at end of file' ) === 0 ) ) ) { if ( count ( $ match ) ) { $ diffLines [ ] = new \ Arbit \ VCSWrapper \ Diff \ Line ( ( $ match [ 'type' ] === '+' ? \ Arbit \ VCSWrapper \ Diff \ Line :: ADDED : ( $ match [ 'type' ] === '-' ? \ Arbit \ VCSWrapper \ Diff \ Line :: REMOVED : \ Arbit \ VCSWrapper \ Diff \ Line :: UNCHANGED ) ) , $ match [ 'line' ] ) ; } } $ chunk -> lines = $ diffLines ; $ chunks [ ] = $ chunk ; if ( $ last !== null ) { array_unshift ( $ lines , $ last ) ; } } $ diff -> chunks = $ chunks ; }
|
Parse the diff of one file
|
58,058
|
public function build ( ) { $ pageNumber = - 1 ; $ count = 0 ; while ( $ count < count ( $ this -> posts ) ) { $ i = 0 ; $ pageNumber ++ ; if ( $ pageNumber == 0 ) $ pagination = new Pagination ( $ pageNumber , '/index.html' ) ; else $ pagination = new Pagination ( $ pageNumber , '/index' . $ pageNumber . '.html' ) ; while ( $ i < $ this -> config [ 'config' ] [ 'pagination' ] && $ count < count ( $ this -> posts ) ) { $ pagination -> setPost ( $ this -> posts [ $ count ] ) ; $ i ++ ; $ count ++ ; } if ( isset ( $ this -> paginations [ $ pageNumber - 1 ] ) ) { $ pagination -> setPreviousPage ( $ this -> paginations [ $ pageNumber - 1 ] ) ; $ this -> paginations [ $ pageNumber - 1 ] -> setNextPage ( $ pagination ) ; } $ this -> paginations [ ] = $ pagination ; } }
|
Create an array of pagination
|
58,059
|
public function updateNavCLasses ( $ sorted_menu_items , $ args ) { $ object_post_type = get_post_type ( ) ; if ( ! get_post_type ( ) ) { return $ sorted_menu_items ; } $ page_ids = $ this -> get_page_ids ( ) ; if ( ! isset ( $ page_ids [ $ object_post_type ] ) ) { return $ sorted_menu_items ; } foreach ( $ sorted_menu_items as & $ item ) { if ( $ item -> type === 'post_type' && $ item -> object === 'page' && intval ( $ item -> object_id ) === intval ( $ page_ids [ $ object_post_type ] ) ) { if ( is_singular ( $ object_post_type ) ) { $ item -> classes [ ] = 'current-menu-ancestor' ; $ item -> current_item_ancestor = true ; } if ( is_post_type_archive ( $ object_post_type ) ) { $ item -> classes [ ] = 'current-menu-item' ; $ item -> current_item = true ; } } } return $ sorted_menu_items ; }
|
Set nav classes
|
58,060
|
protected function get_page_ids ( ) { $ page_ids = array ( ) ; foreach ( get_post_types ( array ( ) , 'objects' ) as $ post_type ) { if ( ! $ post_type -> has_archive ) { continue ; } if ( ! get_option ( "page_for_{$post_type->name}" ) ) { continue ; } $ page_ids [ $ post_type -> name ] = get_option ( "page_for_{$post_type->name}" ) ; } return $ page_ids ; }
|
Return array with page for post type Ids
|
58,061
|
public function putComposerJsonAction ( Request $ request ) { $ content = $ request -> getContent ( ) ; try { $ errors = $ this -> checkComposerJson ( $ content ) ; } catch ( \ Exception $ e ) { $ errors = [ 'errors' => [ [ 'line' => 0 , 'msg' => 'Invalid payload' ] ] , 'warnings' => [ ] , ] ; } if ( ! empty ( $ errors [ 'errors' ] ) ) { $ errors [ 'status' ] = 'ERROR' ; } else { $ errors [ 'status' ] = 'OK' ; $ file = $ this -> get ( 'tenside.composer_json' ) ; $ file -> load ( $ content ) ; $ file -> save ( ) ; } return new JsonResponse ( $ errors ) ; }
|
Update the composer . json with the given data if it is valid .
|
58,062
|
private function checkComposerJson ( $ content ) { $ tempFile = $ this -> getTensideDataDir ( ) . '/composer.json.tmp' ; file_put_contents ( $ tempFile , $ content ) ; $ validator = new ConfigValidator ( new BufferIO ( ) ) ; list ( $ errors , $ publishErrors , $ warnings ) = $ validator -> validate ( $ tempFile ) ; unlink ( $ tempFile ) ; $ errors = array_merge ( $ errors , $ publishErrors ) ; $ errors = str_replace ( dirname ( $ tempFile ) , '' , $ errors ) ; $ warnings = str_replace ( dirname ( $ tempFile ) , '' , $ warnings ) ; $ lineMapper = function ( $ str ) { if ( preg_match ( '#Parse error on line (\d+)#' , $ str , $ match ) ) { return [ 'line' => $ match [ 1 ] , 'msg' => $ str ] ; } return [ 'line' => 0 , 'msg' => $ str ] ; } ; return [ 'errors' => array_map ( $ lineMapper , $ errors ) , 'warnings' => array_map ( $ lineMapper , $ warnings ) , ] ; }
|
Check the json contents and return the error array .
|
58,063
|
public function generateEntityClass ( EntityMetadata $ meta ) { $ placeholders = array ( '<namespace>' , '<classAnnotations>' , '<className>' , '<implements>' , '<traits>' ) ; $ replacements = array ( $ this -> namespace , $ this -> generateClassAnnotations ( $ meta -> getTraits ( ) ) , $ meta -> getClassName ( ) , $ this -> generateImplements ( $ meta -> getInterfaces ( ) ) , $ this -> generateTraitStatements ( $ meta -> getTraits ( ) ) ) ; $ code = str_replace ( $ placeholders , $ replacements , self :: $ template ) ; return str_replace ( '<spaces>' , self :: $ spaces , $ code ) ; }
|
Generates a Doctrine 2 entity class from the given EntityMetadata instance
|
58,064
|
public function getColumnFlex ( $ size = 'phone' ) { $ flex = [ ] ; foreach ( $ this -> _cells as $ column ) { $ flex [ $ column -> id ] = $ column -> getFlex ( $ size ) ; } arsort ( $ flex , SORT_NUMERIC ) ; return $ flex ; }
|
Get column flex .
|
58,065
|
public function getDistributionColumns ( $ size = null ) { $ auto = [ ] ; foreach ( $ this -> _cells as $ cell ) { if ( $ cell -> getColumns ( $ size ) === 'auto' ) { $ auto [ $ cell -> id ] = $ cell ; } } return $ auto ; }
|
Get distribution columns .
|
58,066
|
public function getColumnCount ( ) { $ columnCount = 0 ; foreach ( $ this -> _cells as $ item ) { if ( $ item -> columns === 'auto' ) { continue ; } $ columnCount += $ item -> columns ; } return $ columnCount ; }
|
Get column count .
|
58,067
|
public function checkSecret ( $ secret ) { if ( in_array ( OAuth2 :: GRANT_TYPE_CLIENT_CREDENTIALS , $ this -> getAllowedGrantTypes ( ) ) ) { return array ( 'scope' => 'API_USER' ) ; } return ( null === $ this -> secret || $ secret === $ this -> secret ) ; }
|
Check secret if client credential grant flow set scope
|
58,068
|
public function action ( $ method = 'GET' ) { return isset ( $ this -> actions [ $ method ] ) ? $ this -> actions [ $ method ] : null ; }
|
Retrieves the registered internal state for a certain action . Not really used at the moment but might come in handy sometimes .
|
58,069
|
public function any ( $ state ) : State { foreach ( [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'HEAD' , 'OPTIONS' ] as $ verb ) { $ this -> addCallback ( $ verb , $ state ) ; } return $ this ; }
|
Add a response for _any_ supported HTTP verb .
|
58,070
|
public function get ( $ state ) : State { $ this -> addCallback ( 'GET' , $ state ) ; if ( ! isset ( $ this -> actions [ 'POST' ] ) ) { $ this -> addCallback ( 'POST' , $ state ) ; } return $ this ; }
|
Add a response for the GET verb . If no POST handler was defined this response also doubles for a POST .
|
58,071
|
private function addCallback ( string $ method , $ state ) : void { $ state = $ this -> makeCallable ( $ state ) ; $ this -> actions [ $ method ] = $ state ; }
|
Add a state callback for an method . If the state is something non - callable it is auto - wrapped in a Closure .
|
58,072
|
private function makeCallable ( $ state ) : callable { if ( is_callable ( $ state ) ) { return $ state ; } return function ( ) use ( $ state ) { if ( is_string ( $ state ) && class_exists ( $ state ) ) { $ state = new $ state ; } return $ state ; } ; }
|
Helper method to wrap a state in a callback if it is not callable yet .
|
58,073
|
private function parseArguments ( callable $ call , array $ matches ) : array { if ( is_object ( $ call ) && method_exists ( $ call , '__invoke' ) ) { $ reflection = new ReflectionMethod ( $ call , '__invoke' ) ; } elseif ( is_array ( $ call ) && method_exists ( $ call [ 0 ] , $ call [ 1 ] ) ) { $ reflection = new ReflectionMethod ( $ call [ 0 ] , $ call [ 1 ] ) ; } else { $ reflection = new ReflectionFunction ( $ call ) ; } $ parameters = $ reflection -> getParameters ( ) ; $ arguments = [ ] ; $ request = 'Psr\Http\Message\RequestInterface' ; foreach ( $ parameters as $ value ) { if ( $ class = $ value -> getClass ( ) and $ class -> implementsInterface ( $ request ) ) { $ arguments [ $ value -> name ] = $ this -> request ; } elseif ( $ value -> isCallable ( ) ) { $ arguments [ $ value -> name ] = isset ( $ this -> actions [ $ value -> name ] ) ? $ this -> actions [ $ value -> name ] : new EmptyResponse ( 405 ) ; } else { $ arguments [ $ value -> name ] = null ; } } $ remove = [ ] ; $ args = isset ( $ matches ) ? $ matches : [ ] ; $ justMatched = false ; foreach ( $ args as $ key => $ value ) { if ( is_numeric ( $ key ) && $ justMatched ) { $ remove [ ] = $ key ; } $ justMatched = false ; if ( is_string ( $ key ) && array_key_exists ( $ key , $ arguments ) ) { $ arguments [ $ key ] = $ value ; $ remove [ ] = $ key ; $ justMatched = true ; } } foreach ( $ remove as $ key ) { unset ( $ args [ $ key ] ) ; } array_walk ( $ arguments , function ( & $ value ) use ( & $ args ) { if ( is_null ( $ value ) && $ args ) { $ value = array_shift ( $ args ) ; } } ) ; $ args = [ ] ; foreach ( $ arguments as $ arg ) { if ( isset ( $ arg ) ) { $ args [ ] = $ arg ; } } array_walk ( $ args , function ( & $ value ) { if ( is_string ( $ value ) ) { $ value = preg_replace ( "@/$@" , '' , $ value ) ; } } ) ; return $ args ; }
|
Internal helper to parse arguments for a callable inject the correct values if found and remove unused parameters .
|
58,074
|
public function setAncestorId ( $ id , $ relatedId ) { $ model = $ this -> get ( $ id ) ; if ( $ model === null ) { return new NotFound ( [ 'message' => 'Lineage not found.' ] ) ; } if ( $ this -> doSetAncestorId ( $ model , $ relatedId ) ) { $ this -> dispatch ( LineageEvent :: PRE_ANCESTOR_UPDATE , $ model ) ; $ this -> dispatch ( LineageEvent :: PRE_SAVE , $ model ) ; $ model -> save ( ) ; $ this -> dispatch ( LineageEvent :: POST_ANCESTOR_UPDATE , $ model ) ; $ this -> dispatch ( LineageEvent :: POST_SAVE , $ model ) ; return Updated ( [ 'model' => $ model ] ) ; } return NotUpdated ( [ 'model' => $ model ] ) ; }
|
Sets the Ancestor id
|
58,075
|
protected function doSetAncestorId ( Lineage $ model , $ relatedId ) { if ( $ model -> getAncestorId ( ) !== $ relatedId ) { $ model -> setAncestorId ( $ relatedId ) ; return true ; } return false ; }
|
Internal mechanism to set the Ancestor id
|
58,076
|
public function set_temporal_properties ( $ stamp , $ timestamp_end_col , $ timestamp_start_col ) { $ this -> timestamp = $ stamp ; $ this -> timestamp_end_col = $ timestamp_end_col ; $ this -> timestamp_start_col = $ timestamp_start_col ; return $ this ; }
|
Sets the timestamp to be used on joins . If set to null the latest revision is used .
|
58,077
|
protected function modify_join_result ( $ join_result , $ name ) { if ( ! is_null ( $ this -> timestamp ) and is_subclass_of ( $ join_result [ $ name ] [ 'model' ] , '\Orm\Model_Temporal' ) ) { $ table = $ join_result [ $ name ] [ 'table' ] [ 1 ] ; $ query_time = \ DB :: escape ( $ this -> timestamp ) ; $ join_result [ $ name ] [ 'join_on' ] [ ] = array ( "$table.$this->timestamp_start_col" , '<=' , $ query_time ) ; $ join_result [ $ name ] [ 'join_on' ] [ ] = array ( "$table.$this->timestamp_end_col" , '>=' , $ query_time ) ; } return $ join_result ; }
|
Adds extra where conditions when temporal filtering is needed .
|
58,078
|
private function checkException ( $ response ) { if ( ( true === $ this -> getThrowExceptions ( ) ) and ( $ this -> isErroneousResponse ( $ response ) ) ) { throw new ClientException ( $ response -> detail , $ response -> status ) ; } return $ response ; }
|
Check if exception should be thrown
|
58,079
|
private function isErroneousResponse ( $ response ) { return ( isset ( $ response -> type ) and isset ( $ response -> title ) and isset ( $ response -> status ) and isset ( $ response -> detail ) ) ; }
|
is erroneous reponse
|
58,080
|
public function resolve ( $ name , $ args = array ( ) ) { if ( $ this -> container -> has ( $ name ) ) { return $ this -> container -> get ( $ name ) ; } if ( ! class_exists ( $ name ) ) { throw new \ InvalidArgumentException ( "$name is not a defined class or container service name." ) ; } $ reflection = new \ ReflectionClass ( $ name ) ; $ constructor = $ reflection -> getConstructor ( ) ; if ( is_null ( $ constructor ) ) { return $ reflection -> newInstanceWithoutConstructor ( ) ; } $ params = $ constructor -> getParameters ( ) ; $ classes = array ( ) ; foreach ( $ params as $ param ) { $ class = $ param -> getClass ( ) ; $ arg = null ; if ( is_null ( $ class ) ) { if ( isset ( $ args [ $ param -> name ] ) ) { $ arg = $ args [ $ param -> name ] ; } } else { $ arg = $ this -> container -> get ( $ class -> name ) ; } $ classes [ ] = $ arg ; } return $ reflection -> newInstanceArgs ( $ classes ) ; }
|
Takes a class name and extra named args and returns an instance of the class injected its dependencies resolved from the container as well as the extra arguments passed in .
|
58,081
|
public static function convertToPascalCase ( $ word ) { $ word = str_replace ( '_' , ' ' , $ word ) ; $ word = strtolower ( $ word ) ; $ word = ucwords ( $ word ) ; return str_replace ( ' ' , '' , $ word ) ; }
|
Convert any string to PascalCase
|
58,082
|
protected function sortHandlers ( string $ eventType ) : void { $ this -> sorted [ $ eventType ] = [ ] ; if ( isset ( $ this -> handlers [ $ eventType ] ) ) { krsort ( $ this -> handlers [ $ eventType ] ) ; $ this -> sorted [ $ eventType ] = call_user_func_array ( 'array_merge' , $ this -> handlers [ $ eventType ] ) ; } }
|
Sorts event handlers by priority
|
58,083
|
private function getRouteAsMiddleware ( ResultInterface $ result ) : MiddlewareInterface { $ callback = $ result -> getRoute ( ) -> getCallback ( ) ; if ( is_string ( $ callback ) ) { $ callback = ( $ this -> container ? $ this -> container -> get ( $ callback ) : null ) ; } if ( is_array ( $ callback ) && count ( $ callback ) === 2 ) { list ( $ class , $ method ) = $ callback ; $ callback = ( $ this -> container ? function ( $ request , $ response ) use ( $ class , $ method ) { $ class = $ this -> container -> get ( $ class ) ; return $ class -> $ method ( $ request , $ response ) ; } : null ) ; } if ( $ callback instanceof MiddlewareInterface ) { return $ callback ; } if ( is_callable ( $ callback ) ) { return new Route ( $ callback ) ; } throw new CannotExecuteRouteException ( 'Dispatch doesn\'t know how to handle the callback' ) ; }
|
Get the route as a middleware
|
58,084
|
protected function setAsInteger ( $ field , $ value ) { if ( in_array ( $ field , $ this -> getColumns ( ) ) && ( ! array_key_exists ( $ field , $ this -> object ) || $ this -> object [ $ field ] !== $ value ) ) { $ this -> dirtyFields [ $ field ] = true ; } $ this -> object [ $ field ] = ( int ) $ value ; return $ this ; }
|
Set the given field with the given value typecasted as an integer
|
58,085
|
protected function setAsFloat ( $ field , $ value ) { if ( in_array ( $ field , $ this -> getColumns ( ) ) && ( ! array_key_exists ( $ field , $ this -> object ) || $ this -> object [ $ field ] !== $ value ) ) { $ this -> dirtyFields [ $ field ] = true ; } $ this -> object [ $ field ] = ( float ) $ value ; return $ this ; }
|
Set the given field with the given value typecasted as a float
|
58,086
|
protected function setAsBoolean ( $ field , $ value ) { if ( in_array ( $ field , $ this -> getColumns ( ) ) && ( ! array_key_exists ( $ field , $ this -> object ) || $ this -> object [ $ field ] !== $ value ) ) { $ this -> dirtyFields [ $ field ] = true ; } $ this -> object [ $ field ] = ( bool ) $ value ; return $ this ; }
|
Set the given field with the given value typecasted as a boolean
|
58,087
|
protected function setAsString ( $ field , $ value ) { if ( in_array ( $ field , $ this -> getColumns ( ) ) && ( ! array_key_exists ( $ field , $ this -> object ) || $ this -> object [ $ field ] !== $ value ) ) { $ this -> dirtyFields [ $ field ] = true ; } $ this -> object [ $ field ] = ( string ) $ value ; return $ this ; }
|
Set the given field with the given value typecasted as a string
|
58,088
|
protected function render ( ResponseInterface $ response ) { $ stream = new Stream ( 'php://memory' , 'rw+' ) ; $ content = $ this -> getEngine ( ) -> parse ( $ this -> getTemplate ( ) ) -> process ( $ this -> getData ( ) ) ; $ stream -> write ( $ content ) ; $ response = $ response -> withBody ( $ stream ) ; return $ response ; }
|
Processes and renders the response
|
58,089
|
protected function getEngine ( ) { Template :: addPath ( dirname ( __DIR__ ) . '/templates' ) ; $ template = new Template ( ) ; $ template -> addExtension ( HtmlExtension :: class ) ; return $ template -> initialize ( ) ; }
|
Creates the engine for this rendering
|
58,090
|
public function addDmsRow ( $ column , $ value , $ foreignID ) { $ tableGateway = $ this -> tableGateway ; $ trData = array ( 'model' => get_class ( $ tableGateway ) , 'foreign_key' => $ foreignID , 'field' => $ column , 'content' => $ value ) ; $ dmsTable = $ this -> getDmsTable ( ) ; $ dmsTable -> insert ( $ trData ) ; }
|
Add Dms data for a row with specific primary key
|
58,091
|
public function createNew ( string $ name , string $ event , bool $ running , bool $ success , string $ message ) : array { return $ this -> sendPost ( sprintf ( '/profiles/%s/processes/%s/tasks' , $ this -> userName , $ this -> processId ) , [ ] , [ 'name' => $ name , 'event' => $ event , 'running' => $ running , 'success' => $ success , 'message' => $ message ] ) ; }
|
Creates a new task for the given user .
|
58,092
|
public function listAll ( array $ filters = [ ] ) : array { return $ this -> sendGet ( sprintf ( '/profiles/%s/processes/%s/tasks' , $ this -> userName , $ this -> processId ) , $ filters ) ; }
|
Lists all tasks .
|
58,093
|
public function getOne ( int $ taskId ) : array { return $ this -> sendGet ( sprintf ( '/profiles/%s/processes/%s/tasks/%s' , $ this -> userName , $ this -> processId , $ taskId ) ) ; }
|
Retrieves a task given its slug .
|
58,094
|
public function updateOne ( int $ taskId , string $ name , string $ event , bool $ running , bool $ success , string $ message ) : array { return $ this -> sendPatch ( sprintf ( '/profiles/%s/processes/%s/tasks/%s' , $ this -> userName , $ this -> processId , $ taskId ) , [ ] , [ 'name' => $ name , 'event' => $ event , 'running' => $ running , 'success' => $ success , 'message' => $ message ] ) ; }
|
Updates a task given its slug .
|
58,095
|
public function getTimestampDifference ( $ time = null ) { $ time = ( is_null ( $ time ) ) ? $ this -> getCurrentTimestamp ( ) : $ time ; return ( $ time - $ this -> initialTimestamp ) ; }
|
Returns difference between provided timestamp and initial timestamp . If null is provided the current timestamp is used .
|
58,096
|
public function setInitialTimestamp ( $ time = null ) { $ time = ( is_null ( $ time ) ) ? $ this -> getCurrentTimestamp ( ) : $ time ; $ this -> initialTimestamp = $ time ; return $ this ; }
|
Adds manipulation for initial timestamp . If null is provided the current timestamp is used .
|
58,097
|
public function fromReflectionClass ( ClassInterface $ reflectionClass ) { $ reflectionClass -> addAnnotationAlias ( Controller :: ANNOTATION , Controller :: __getClass ( ) ) ; $ reflectionClass -> addAnnotationAlias ( RequestMapping :: ANNOTATION , RequestMapping :: __getClass ( ) ) ; parent :: fromReflectionClass ( $ reflectionClass ) ; $ baseMapping = null ; if ( $ reflectionClass -> hasAnnotation ( RequestMapping :: ANNOTATION ) ) { $ baseMapping = $ reflectionClass -> getAnnotation ( RequestMapping :: ANNOTATION ) ; } $ mappings = array ( ) ; foreach ( $ reflectionClass -> getMethods ( \ ReflectionMethod :: IS_PUBLIC ) as $ reflectionMethod ) { $ reflectionMethod -> addAnnotationAlias ( RequestMapping :: ANNOTATION , RequestMapping :: __getClass ( ) ) ; if ( $ reflectionMethod -> hasAnnotation ( RequestMapping :: ANNOTATION ) ) { $ methodMapping = $ reflectionMethod -> getAnnotation ( RequestMapping :: ANNOTATION ) ; } } return $ this ; }
|
Initializes the controller descriptor instance from the passed reflection class instance .
|
58,098
|
private function setHeader ( ) { ob_get_clean ( ) ; header ( "Content-Type: video/mp4" ) ; header ( "Cache-Control: max-age=2592000, public" ) ; header ( "Expires: " . gmdate ( 'D, d M Y H:i:s' , time ( ) + 2592000 ) . ' GMT' ) ; header ( "Last-Modified: " . gmdate ( 'D, d M Y H:i:s' , @ filemtime ( $ this -> path ) ) . ' GMT' ) ; $ this -> start = 0 ; $ this -> size = filesize ( $ this -> path ) ; $ this -> end = $ this -> size - 1 ; header ( "Accept-Ranges: 0-" . $ this -> end ) ; if ( isset ( $ _SERVER [ 'HTTP_RANGE' ] ) ) { $ c_start = $ this -> start ; $ c_end = $ this -> end ; list ( , $ range ) = explode ( '=' , $ _SERVER [ 'HTTP_RANGE' ] , 2 ) ; if ( strpos ( $ range , ',' ) !== false ) { header ( 'HTTP/1.1 416 Requested Range Not Satisfiable' ) ; header ( "Content-Range: bytes $this->start-$this->end/$this->size" ) ; exit ; } if ( $ range == '-' ) { $ c_start = $ this -> size - substr ( $ range , 1 ) ; } else { $ range = explode ( '-' , $ range ) ; $ c_start = $ range [ 0 ] ; $ c_end = ( isset ( $ range [ 1 ] ) && is_numeric ( $ range [ 1 ] ) ) ? $ range [ 1 ] : $ c_end ; } $ c_end = ( $ c_end > $ this -> end ) ? $ this -> end : $ c_end ; if ( $ c_start > $ c_end || $ c_start > $ this -> size - 1 || $ c_end >= $ this -> size ) { header ( 'HTTP/1.1 416 Requested Range Not Satisfiable' ) ; header ( "Content-Range: bytes $this->start-$this->end/$this->size" ) ; exit ; } $ this -> start = $ c_start ; $ this -> end = $ c_end ; $ length = $ this -> end - $ this -> start + 1 ; fseek ( $ this -> stream , $ this -> start ) ; header ( 'HTTP/1.1 206 Partial Content' ) ; header ( "Content-Length: " . $ length ) ; header ( "Content-Range: bytes $this->start-$this->end/" . $ this -> size ) ; } else header ( "Content-Length: " . $ this -> size ) ; }
|
Set proper header to serve the video content
|
58,099
|
private function stream ( ) { $ i = $ this -> start ; set_time_limit ( 0 ) ; while ( ! feof ( $ this -> stream ) && $ i <= $ this -> end ) { $ bytesToRead = $ this -> buffer ; if ( ( $ i + $ bytesToRead ) > $ this -> end ) $ bytesToRead = $ this -> end - $ i + 1 ; $ data = fread ( $ this -> stream , $ bytesToRead ) ; echo $ data ; flush ( ) ; $ i += $ bytesToRead ; } }
|
perform the streaming of calculated range
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.