idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
2,100
|
public function getLegend ( ) { return ( isset ( $ this -> fieldsets [ $ this -> current ] ) ) ? $ this -> fieldsets [ $ this -> current ] -> getLegend ( ) : null ; }
|
Method to get the legend of the current fieldset
|
2,101
|
public function setLegend ( $ legend ) { if ( isset ( $ this -> fieldsets [ $ this -> current ] ) ) { $ this -> fieldsets [ $ this -> current ] -> setLegend ( $ legend ) ; } return $ this ; }
|
Method to set the legend of the current fieldset
|
2,102
|
public function addFieldFromConfig ( $ name , $ field ) { $ this -> addField ( Fields :: create ( $ name , $ field ) ) ; return $ this ; }
|
Method to add a form field from a config
|
2,103
|
public function addFieldsFromConfig ( array $ config ) { $ i = 1 ; foreach ( $ config as $ name => $ field ) { if ( is_numeric ( $ name ) && ! isset ( $ field [ $ name ] [ 'type' ] ) ) { $ fields = [ ] ; foreach ( $ field as $ n => $ f ) { $ fields [ $ n ] = Fields :: create ( $ n , $ f ) ; } if ( $ i > 1 ) { $ this -> fieldsets [ $ this -> current ] -> createGroup ( ) ; } $ this -> fieldsets [ $ this -> current ] -> addFields ( $ fields ) ; $ i ++ ; } else { $ this -> addField ( Fields :: create ( $ name , $ field ) ) ; } } return $ this ; }
|
Method to add form fields from config
|
2,104
|
public function addFieldsetsFromConfig ( array $ fieldsets , $ container = null ) { foreach ( $ fieldsets as $ legend => $ config ) { if ( ! is_numeric ( $ legend ) ) { $ this -> createFieldset ( $ legend , $ container ) ; } else { $ this -> createFieldset ( null , $ container ) ; } $ this -> addFieldsFromConfig ( $ config ) ; } return $ this ; }
|
Method to add form fieldsets from config
|
2,105
|
public function insertFieldBefore ( $ name , Element \ AbstractElement $ field ) { foreach ( $ this -> fieldsets as $ fieldset ) { if ( $ fieldset -> hasField ( $ name ) ) { $ fieldset -> insertFieldBefore ( $ name , $ field ) ; break ; } } return $ this ; }
|
Method to insert a field before another one
|
2,106
|
public function count ( ) { $ count = 0 ; foreach ( $ this -> fieldsets as $ fieldset ) { $ count += $ fieldset -> count ( ) ; } return $ count ; }
|
Method to get the count of elements in the form
|
2,107
|
public function getFields ( ) { $ fields = [ ] ; foreach ( $ this -> fieldsets as $ fieldset ) { $ fields = array_merge ( $ fields , $ fieldset -> getAllFields ( ) ) ; } return $ fields ; }
|
Method to get field element objects
|
2,108
|
public function removeField ( $ field ) { foreach ( $ this -> fieldsets as $ fieldset ) { if ( $ fieldset -> hasField ( $ field ) ) { unset ( $ fieldset [ $ field ] ) ; } } return $ this ; }
|
Method to remove a form field
|
2,109
|
public function filterValue ( $ value ) { if ( $ value instanceof Element \ AbstractElement ) { $ name = $ value -> getName ( ) ; $ type = $ value -> getType ( ) ; $ realValue = $ value -> getValue ( ) ; } else { $ type = null ; $ name = null ; $ realValue = $ value ; } foreach ( $ this -> filters as $ filter ) { if ( ( ( null === $ type ) || ( ! in_array ( $ type , $ filter [ 'excludeByType' ] ) ) ) && ( ( null === $ name ) || ( ! in_array ( $ name , $ filter [ 'excludeByName' ] ) ) ) ) { if ( is_array ( $ realValue ) ) { foreach ( $ realValue as $ k => $ v ) { $ params = array_merge ( [ $ v ] , $ filter [ 'params' ] ) ; $ realValue [ $ k ] = call_user_func_array ( $ filter [ 'call' ] , $ params ) ; } } else { $ params = array_merge ( [ $ realValue ] , $ filter [ 'params' ] ) ; $ realValue = call_user_func_array ( $ filter [ 'call' ] , $ params ) ; } } } if ( ( $ value instanceof Element \ AbstractElement ) && ( null !== $ realValue ) && ( $ realValue != '' ) ) { $ value -> setValue ( $ realValue ) ; } return $ realValue ; }
|
Filter value with the filters in the form object
|
2,110
|
public function filterValues ( array $ values = null ) { if ( null === $ values ) { $ values = $ this -> getFields ( ) ; } foreach ( $ values as $ key => $ value ) { $ values [ $ key ] = $ this -> filterValue ( $ value ) ; } return $ values ; }
|
Filter values with the filters in the form object
|
2,111
|
public function isValid ( ) { $ result = true ; $ fields = $ this -> getFields ( ) ; foreach ( $ fields as $ field ) { if ( $ field -> validate ( ) == false ) { $ result = false ; } } return $ result ; }
|
Determine whether or not the form object is valid
|
2,112
|
public function getErrors ( $ name ) { $ field = $ this -> getField ( $ name ) ; $ errors = ( null !== $ field ) ? $ field -> getErrors ( ) : [ ] ; return $ errors ; }
|
Get form element errors for a field .
|
2,113
|
public function getAllErrors ( ) { $ errors = [ ] ; $ fields = $ this -> getFields ( ) ; foreach ( $ fields as $ name => $ field ) { if ( $ field -> hasErrors ( ) ) { $ errors [ str_replace ( '[]' , '' , $ field -> getName ( ) ) ] = $ field -> getErrors ( ) ; } } return $ errors ; }
|
Get all form element errors
|
2,114
|
public function reset ( ) { $ fields = $ this -> getFields ( ) ; foreach ( $ fields as $ field ) { $ field -> resetValue ( ) ; } return $ this ; }
|
Method to reset and clear any form field values
|
2,115
|
public function clearTokens ( ) { if ( session_id ( ) == '' ) { session_start ( ) ; } if ( isset ( $ _SESSION [ 'pop_csrf' ] ) ) { unset ( $ _SESSION [ 'pop_csrf' ] ) ; } if ( isset ( $ _SESSION [ 'pop_captcha' ] ) ) { unset ( $ _SESSION [ 'pop_captcha' ] ) ; } return $ this ; }
|
Method to clear any security tokens
|
2,116
|
public function prepare ( ) { if ( null === $ this -> getAttribute ( 'id' ) ) { $ this -> setAttribute ( 'id' , 'pop-form' ) ; } if ( null === $ this -> getAttribute ( 'class' ) ) { $ this -> setAttribute ( 'class' , 'pop-form' ) ; } if ( count ( $ this -> columns ) > 0 ) { foreach ( $ this -> columns as $ class => $ fieldsets ) { $ column = new Child ( 'div' ) ; $ column -> setAttribute ( 'class' , $ class ) ; foreach ( $ fieldsets as $ i ) { if ( isset ( $ this -> fieldsets [ $ i ] ) ) { $ fieldset = $ this -> fieldsets [ $ i ] ; $ fieldset -> prepare ( ) ; $ column -> addChild ( $ fieldset ) ; } } $ this -> addChild ( $ column ) ; } } else { foreach ( $ this -> fieldsets as $ fieldset ) { $ fieldset -> prepare ( ) ; $ this -> addChild ( $ fieldset ) ; } } return $ this ; }
|
Prepare form object for rendering
|
2,117
|
public function prepareForView ( ) { $ formData = [ ] ; foreach ( $ this -> fieldsets as $ fieldset ) { $ formData = array_merge ( $ formData , $ fieldset -> prepareForView ( ) ) ; } return $ formData ; }
|
Prepare form object for rendering with a view
|
2,118
|
public function render ( $ depth = 0 , $ indent = null , $ inner = false ) { if ( ! ( $ this -> hasChildren ( ) ) ) { $ this -> prepare ( ) ; } foreach ( $ this -> fieldsets as $ fieldset ) { foreach ( $ fieldset -> getAllFields ( ) as $ field ) { if ( $ field instanceof Element \ Input \ File ) { $ this -> setAttribute ( 'enctype' , 'multipart/form-data' ) ; break ; } } } return parent :: render ( $ depth , $ indent , $ inner ) ; }
|
Render the form object
|
2,119
|
public static function isGroup ( array $ value ) { return $ value === array_values ( $ value ) || ( isset ( $ value [ self :: _OR ] ) && count ( $ value ) === 1 ) ; }
|
Is it filter with groups?
|
2,120
|
public static function validate ( Reflection $ reflection , array $ filter ) { if ( self :: isGroup ( $ filter ) ) { foreach ( $ filter as $ modifier => $ item ) { if ( ! is_array ( $ item ) || empty ( $ item ) ) { throw new Exception \ FilterException ( "Invalid filter group structure!" ) ; } self :: validate ( $ reflection , $ item ) ; } } else { foreach ( $ filter as $ name => $ item ) { if ( ! is_array ( $ item ) || ! is_string ( $ name ) ) { throw new Exception \ FilterException ( "Invalid filter structure!" ) ; } if ( ! $ reflection -> hasProperty ( $ name ) ) { throw new Exception \ FilterException ( "Undefined property name '" . $ name . "' used in filter!" ) ; } $ property = $ reflection -> getProperty ( $ name ) ; foreach ( $ item as $ modifier => $ value ) { if ( ! in_array ( $ modifier , self :: $ modifiers , true ) ) { throw new Exception \ FilterException ( "Invalid filter modifier '" . $ modifier . "'!" ) ; } if ( $ property -> hasOption ( Assoc :: KEY ) || $ property -> hasOption ( Computed :: KEY ) || ( $ property -> hasOption ( Reflection \ Property \ Option \ Map :: KEY ) && ! $ property -> getOption ( Reflection \ Property \ Option \ Map :: KEY ) ) || $ property -> getType ( ) === Reflection \ Property :: TYPE_COLLECTION || $ property -> getType ( ) === Reflection \ Property :: TYPE_ENTITY ) { throw new Exception \ FilterException ( "Filter can not be used with computed, collections, entities and disabled mapping!" ) ; } try { if ( is_array ( $ value ) && $ property -> getType ( ) !== Reflection \ Property :: TYPE_ARRAY && in_array ( $ modifier , [ self :: EQUAL , self :: NOT ] , true ) ) { foreach ( $ value as $ index => $ valueItem ) { $ property -> validateValueType ( $ valueItem ) ; } } else { $ property -> validateValueType ( $ value ) ; } } catch ( Exception \ InvalidArgumentException $ e ) { throw new Exception \ FilterException ( $ e -> getMessage ( ) ) ; } } } } }
|
Merge two filters
|
2,121
|
public function setData ( $ data ) { $ this -> originalData = $ data ; if ( $ data instanceof \ Iterator ) { $ this -> iterator = $ data ; } elseif ( is_array ( $ data ) ) { $ this -> iterator = new \ ArrayIterator ( $ data ) ; } else { $ this -> iterator = new \ ArrayIterator ( array ( $ data ) ) ; } }
|
Assigns data to the aggregate .
|
2,122
|
public function put ( $ path , $ contents , $ lock = false ) { if ( ! $ this -> exists ( dirname ( $ path ) ) ) { mkdir ( dirname ( $ path ) , 0775 , true ) ; } return file_put_contents ( $ path , $ contents , $ lock ? LOCK_EX : 0 ) ; }
|
Put contents to a given file . Create the file if doesn t exist .
|
2,123
|
public function get ( $ decodeOptions = [ ] ) { $ media = $ this -> _classes [ 'media' ] ; $ format = $ this -> format ( ) ; return $ format ? $ media :: decode ( $ format , $ this -> _stream -> toString ( ) , $ decodeOptions , $ this ) : $ this -> _stream -> toString ( ) ; }
|
Gets the body of this message .
|
2,124
|
public function to ( $ format , $ options = [ ] ) { $ media = $ this -> _classes [ 'media' ] ; if ( ! $ media :: get ( $ format ) ) { throw new InvalidArgumentException ( "Unsupported format `{$format}`." ) ; } return $ media :: decode ( $ format , $ this -> body ( ) , $ options , $ this ) ; }
|
Exports a Message body to specific format .
|
2,125
|
public function toString ( ) { $ headers = $ this -> headers ( ) ; if ( $ headers [ 'Transfer-Encoding' ] -> value ( ) === 'chunked' ) { return $ this -> toChunks ( ) ; } return $ this -> _stream -> toString ( ) ; }
|
Magic method convert the instance body into a string .
|
2,126
|
public function toChunks ( $ size = null ) { $ body = '' ; $ size = $ size > 0 ? $ size : $ this -> chunkSize ( ) ; $ stream = $ this -> stream ( ) ; while ( $ chunk = $ stream -> read ( $ size ) ) { $ readed = strlen ( $ chunk ) ; if ( ! $ readed ) { break ; } $ body .= dechex ( $ readed ) . "\r\n" . $ chunk . "\r\n" ; } $ body .= "0\r\n\r\n" ; if ( $ stream -> isSeekable ( ) ) { $ stream -> rewind ( ) ; } return $ body ; }
|
Flush the content of a Message chunk by chunk .
|
2,127
|
protected function _setContentLength ( ) { $ headers = $ this -> headers ( ) ; if ( $ headers [ 'Transfer-Encoding' ] -> value ( ) === 'chunked' ) { return ; } $ length = $ this -> stream ( ) -> length ( ) ; if ( $ length === null ) { throw new NetException ( "A Content-Length header is required but the request stream has a `null` length." ) ; } $ headers [ 'Content-Length' ] = $ this -> stream ( ) -> length ( ) ; }
|
Auto adds a Content - Length header if necessary .
|
2,128
|
public static function getTime ( $ ts = 'now' , $ format = 'U' , $ tz = null ) { if ( ! Util :: isValidTimezone ( $ tz ) ) { $ tz = Util :: getClientTimezone ( ) ; } $ dt = new DateTime ( null , new DateTimeZone ( $ tz ) ) ; ( is_int ( $ ts ) ) ? $ dt -> setTimestamp ( $ ts ) : $ dt -> modify ( $ ts ) ; $ time = $ dt -> format ( 'H' ) * self :: SECONDS_IN_AN_HOUR ; $ time += $ dt -> format ( 'i' ) * self :: SECONDS_IN_A_MINUTE ; $ time += $ dt -> format ( 's' ) ; return $ dt -> setTimestamp ( $ time ) -> format ( $ format ) ; }
|
Extracts time of the day timestamp
|
2,129
|
public static function getWeekdays ( ) { return array ( self :: MONDAY , self :: TUESDAY , self :: WEDNESDAY , self :: THURSDAY , self :: FRIDAY , self :: SATURDAY , self :: SUNDAY , ) ; }
|
Returns an array of weekdays
|
2,130
|
function getRepeatFrequencies ( ) { return array ( Util :: FREQUENCY_DAILY => elgg_echo ( 'events_ui:repeat:daily' ) , Util :: FREQUENCY_WEEKDAY => elgg_echo ( 'events_ui:repeat:weekday' ) , Util :: FREQUENCY_WEEKDAY_ODD => elgg_echo ( 'events_ui:repeat:dailymwf' ) , Util :: FREQUENCY_WEEKDAY_EVEN => elgg_echo ( 'events_ui:repeat:dailytt' ) , Util :: FREQUENCY_WEEKLY => elgg_echo ( 'events_ui:repeat:weekly' ) , Util :: FREQUENCY_MONTHLY => elgg_echo ( 'events_ui:repeat:monthly' ) , Util :: FREQUENCY_YEARLY => elgg_echo ( 'events_ui:repeat:yearly' ) , ) ; }
|
Returns repeat frequencies
|
2,131
|
public static function getTimezonesByCountry ( ) { $ timezones = array ( ) ; $ tz_ids = array_keys ( self :: getTimezones ( true , false , 'now' , self :: TIMEZONE_SORT_OFFSET ) ) ; foreach ( $ tz_ids as $ tz_id ) { if ( $ tz_id == Util :: UTC ) { continue ; } $ info = Util :: getTimezoneInfo ( $ tz_id ) ; $ cc = $ info -> country_code ; $ abbr = $ info -> abbr ; if ( ! isset ( $ timezones [ $ cc ] ) ) { $ timezones [ $ cc ] = array ( ) ; } $ timezones [ $ cc ] [ ] = $ info ; } ksort ( $ timezones ) ; return $ timezones ; }
|
Returns an array of timezones by country
|
2,132
|
public static function getTimezoneInfo ( $ tz_id ) { $ tz = new \ DateTimeZone ( $ tz_id ) ; $ location = $ tz -> getLocation ( ) ; $ country_code = $ location [ 'country_code' ] ; $ dt = new DateTime ( null , $ tz ) ; $ region = explode ( '/' , $ tz_id ) ; if ( sizeof ( $ region ) > 1 ) { array_shift ( $ region ) ; } $ region = str_replace ( '_' , ' ' , implode ( ', ' , $ region ) ) ; $ tzinfo = new stdClass ( ) ; $ tzinfo -> id = $ tz_id ; $ tzinfo -> abbr = $ dt -> format ( 'T' ) ; $ tzinfo -> country_code = $ country_code ; $ tzinfo -> country = elgg_echo ( "timezone:country:$country_code" ) ; $ tzinfo -> region = $ region ; $ tzinfo -> offset = $ dt -> getOffset ( ) ; $ tzinfo -> gmt = $ dt -> format ( '\(\G\M\TP\)' ) ; $ name = "timezone:name:$tzinfo->country_code:$tzinfo->abbr" ; $ name_tr = elgg_echo ( $ name ) ; $ tzinfo -> name = ( $ name == $ name_tr ) ? $ tzinfo -> abbr : $ name_tr ; $ tzinfo -> label = "$tzinfo->gmt $tzinfo->name - $tzinfo->region" ; return $ tzinfo ; }
|
Expands timezone ID into a usable source of data about the timezone
|
2,133
|
public static function getTimezoneLabel ( $ tz_id , $ format = false , $ ts = 'now' ) { if ( self :: isValidTimezone ( $ tz_id ) && $ format ) { $ dt = new DateTime ( null , new DateTimeZone ( $ tz_id ) ) ; ( is_int ( $ ts ) ) ? $ dt -> setTimestamp ( $ ts ) : $ dt -> modify ( $ ts ) ; return $ dt -> format ( $ format ) ; } return elgg_echo ( $ tz_id ) ; }
|
Returns a label for a timezone
|
2,134
|
public static function compareTimezonesByOffset ( $ a , $ b ) { $ dta = new DateTime ( null , new DateTimeZone ( $ a ) ) ; $ dtb = new DateTime ( null , new DateTimeZone ( $ b ) ) ; if ( $ dta -> getOffset ( ) == $ dtb -> getOffset ( ) ) { return ( strcmp ( $ a , $ b ) < 0 ) ? - 1 : 1 ; } return ( $ dta -> getOffset ( ) < $ dtb -> getOffset ( ) ) ? - 1 : 1 ; }
|
Sorting callback function for comparing timezones by offset
|
2,135
|
public static function getClientTimezone ( $ user = null ) { if ( isset ( self :: $ timezone ) ) { return self :: $ timezone ; } $ preferred = array ( ) ; $ preferred [ ] = get_input ( 'timezone' ) ; if ( $ user == null ) { $ user = elgg_get_logged_in_user_entity ( ) ; } if ( $ user ) { $ preferred [ ] = $ user -> timezone ; } if ( defined ( 'ELGG_SITE_TIMEZONE' ) ) { $ preferred [ ] = ELGG_SITE_TIMEZONE ; } $ preferred [ ] = date ( 'e' ) ; foreach ( $ preferred as $ id ) { if ( self :: isValidTimezone ( $ id ) ) { self :: $ timezone = $ id ; return $ id ; } } return Util :: UTC ; }
|
Returns display timezone
|
2,136
|
public function masqueradeAsUser ( $ user ) { if ( Auth :: check ( ) ) { session ( [ 'masquerading_user' => Auth :: user ( ) ] ) ; Auth :: logout ( ) ; Auth :: login ( $ user ) ; return true ; } return false ; }
|
Allows a logged - in user to masquerade as the passed User . Returns true on success or false otherwise .
|
2,137
|
public function stopMasquerading ( ) { if ( $ this -> isMasquerading ( ) ) { Auth :: logout ( ) ; Auth :: login ( session ( 'masquerading_user' ) ) ; session ( [ 'masquerading_user' => null ] ) ; return true ; } return false ; }
|
Stops masquerading as another user if we are currently masquerading . Returns true on success or false otherwise .
|
2,138
|
public function newCollector ( ) { $ collector = new Collector ( $ this -> getDispatcher ( ) ) ; $ collector -> setCollections ( $ this -> _collections ) -> setLogger ( $ this -> getLogger ( ) ) -> setQueue ( $ this -> getQueue ( ) ) -> setTimeout ( $ this -> _timeout ) -> setLimit ( $ this -> _limit ) ; return $ collector ; }
|
Returns a Collector object that the Indexer class injects itself as a service into .
|
2,139
|
public function normalizeField ( IndexField $ field ) { $ id = $ field -> getId ( ) ; $ value = $ field -> getValue ( ) ; $ log = $ this -> getLogger ( ) ; $ context = array ( 'field' => $ id ) ; if ( isset ( $ this -> _fieldTypes [ $ id ] ) ) { if ( $ this -> _searchEngine -> hasNormalizer ( $ this -> _fieldTypes [ $ id ] ) ) { $ normalizer = $ this -> _searchEngine -> getNormalizer ( $ this -> _fieldTypes [ $ id ] ) ; $ context [ 'normalizer' ] = get_class ( $ normalizer ) ; $ value = $ normalizer -> normalize ( $ value ) ; $ log -> debug ( 'Normalizer applied to field' , $ context ) ; } } else { $ log -> debug ( 'Data type could not be determined for field' , $ context ) ; } return $ value ; }
|
Apply the serivce specific normalizers to a field s value .
|
2,140
|
public function indexQueuedItems ( ) { $ dispatcher = $ this -> getDispatcher ( ) ; $ log = $ this -> getLogger ( ) ; $ context = array ( 'engine' => get_class ( $ this -> _searchEngine ) ) ; $ log -> info ( 'Indexing operation started' , $ context ) ; try { $ this -> getSchema ( ) ; $ dispatcher -> addSubscriber ( $ this -> _searchEngine ) ; $ event = new SearchEngineEvent ( $ this ) ; $ this -> dispatchEvent ( SearchEvents :: SEARCH_ENGINE_PRE_INDEX , $ event ) ; $ consumer = new QueueConsumer ( $ this ) ; foreach ( $ consumer as $ message ) { $ context [ 'item' ] = $ message -> getBody ( ) ; $ log -> debug ( 'Consumed item scheduled for indexing from queue' , $ context ) ; $ this -> indexQueuedItem ( $ message ) ; } unset ( $ context [ 'item' ] ) ; $ this -> dispatchEvent ( SearchEvents :: SEARCH_ENGINE_POST_INDEX , $ event ) ; $ dispatcher -> removeSubscriber ( $ this -> _searchEngine ) ; } catch ( Exception $ e ) { $ dispatcher -> removeSubscriber ( $ this -> _searchEngine ) ; throw $ e ; } $ context [ 'indexed' ] = count ( $ consumer ) ; $ log -> info ( 'Indexing operation completed' , $ context ) ; }
|
Indexes the items that are queued for indexing into the search engine .
|
2,141
|
public function indexQueuedItem ( QueueMessage $ message ) { $ log = $ this -> getLogger ( ) ; $ context = array ( 'engine' => get_class ( $ this -> _searchEngine ) , 'item' => $ message -> getBody ( ) , ) ; $ collection = $ message -> getCollection ( ) ; $ data = $ collection -> loadSourceData ( $ message ) ; if ( $ data ) { $ context [ 'collection' ] = $ collection -> getId ( ) ; $ log -> debug ( 'Data fetched from source' , $ context ) ; $ document = $ this -> _searchEngine -> newDocument ( $ this ) ; $ collection -> buildDocument ( $ document , $ data ) ; $ log -> debug ( 'Document prepared for indexing' , $ context ) ; $ event = new IndexDocumentEvent ( $ this , $ document , $ data ) ; $ this -> dispatchEvent ( SearchEvents :: DOCUMENT_PRE_INDEX , $ event ) ; $ this -> _searchEngine -> indexDocument ( $ collection , $ document ) ; $ this -> dispatchEvent ( SearchEvents :: DOCUMENT_POST_INDEX , $ event ) ; $ log -> debug ( 'Document processed for indexing' , $ context ) ; } else { $ log -> critical ( 'Data could not be loaded from source' , $ context ) ; } }
|
Indexes an item that is queued for indexing into the search engine .
|
2,142
|
public function generate ( FilesystemAdapter $ filesystemAdapter , $ extension , $ path = null ) { $ hash = sha1 ( time ( ) + microtime ( ) ) ; $ exists = $ filesystemAdapter -> exists ( $ path . '/' . $ hash . '.' . $ extension ) ; if ( $ exists ) { $ this -> generate ( $ filesystemAdapter , $ extension , $ path ) ; } return $ hash ; }
|
Generates unique filename
|
2,143
|
protected function injectContentTemplate ( MvcEvent $ event ) { $ model = $ event -> getResult ( ) ; if ( ! $ model instanceof ViewModel ) { return $ this ; } if ( $ model -> getTemplate ( ) ) { return $ this ; } $ routeMatch = $ event -> getRouteMatch ( ) ; $ themeName = $ this -> getThemeName ( ) ; $ themeOptions = $ this -> getThemeOptions ( ) ; $ options = [ ] ; if ( isset ( $ themeOptions [ static :: $ side ] ) ) { $ options = $ themeOptions [ static :: $ side ] ; } if ( isset ( $ options [ 'templates' ] ) ) { $ templatesPath = rtrim ( $ options [ 'templates' ] , '/' ) . '/' ; } else { $ templatesPath = str_replace ( [ '{theme}' , '{side}' ] , [ $ themeName , static :: $ side ] , self :: DefaultTemplatesPath ) ; } $ controller = $ event -> getTarget ( ) ; if ( $ controller ) { $ controller = get_class ( $ controller ) ; } else { $ controller = $ routeMatch -> getParam ( 'controller' , '' ) ; } $ controller = $ this -> deriveControllerClass ( $ controller ) ; $ template = $ templatesPath . $ this -> inflectName ( $ controller ) ; $ action = $ routeMatch -> getParam ( 'action' ) ; if ( null !== $ action ) { $ template .= '/' . $ this -> inflectName ( $ action ) ; } $ model -> setTemplate ( $ template ) ; return $ this ; }
|
Inject a template into the content view model if none present
|
2,144
|
protected function injectLayoutTemplate ( MvcEvent $ event ) { $ model = $ event -> getResult ( ) ; if ( ! $ model instanceof ViewModel ) { return $ this ; } if ( $ model -> terminate ( ) ) { return $ this ; } $ viewManager = $ this -> getViewManager ( ) ; $ renderer = $ viewManager -> getRenderer ( ) ; $ themeName = $ this -> getThemeName ( ) ; $ themeOptions = $ this -> getThemeOptions ( ) ; $ options = [ ] ; if ( isset ( $ themeOptions [ static :: $ side ] ) ) { $ options = $ themeOptions [ static :: $ side ] ; } if ( isset ( $ options [ 'layouts' ] ) ) { $ layoutsPath = rtrim ( $ options [ 'layouts' ] , '/' ) . '/' ; } else { $ layoutsPath = str_replace ( [ '{theme}' , '{side}' ] , [ $ themeName , static :: $ side ] , self :: DefaultLayoutsPath ) ; } $ layout = $ event -> getViewModel ( ) ; if ( $ layout && 'layout/layout' !== $ layout -> getTemplate ( ) ) { $ layout -> setTemplate ( str_replace ( '{layouts}' , $ layoutsPath , $ layout -> getTemplate ( ) ) ) ; return $ this ; } $ defaultLayout = self :: DefaultLayout ; if ( isset ( $ options [ 'default_layout' ] ) ) { $ defaultLayout = $ options [ 'default_layout' ] ; } $ renderer -> layout ( ) -> setTemplate ( $ layoutsPath . $ defaultLayout ) ; return $ this ; }
|
Inject a template into the layout view model if none present
|
2,145
|
protected function formatAble ( & $ object ) { if ( ! is_object ( $ object ) || is_array ( $ object ) ) { throw new InvalidArgumentException ( 'The given argument is not an object/array.' ) ; } if ( ! is_object ( $ object ) && $ object instanceof FormatAble ) { return ; } $ object = new FormatAbleObject ( clone ( $ object ) ) ; }
|
Make an object formatAble .
|
2,146
|
public function regex ( $ array = [ ] ) { $ filtered = [ ] ; foreach ( $ array as $ key => $ value ) { if ( $ this -> isRegex ( $ key ) ) { $ filtered [ $ key ] = $ value ; } } return $ filtered ; }
|
Filter an array where the key is a regex string .
|
2,147
|
protected function getRegexProperty ( $ matches , $ value ) { foreach ( $ matches as $ index => $ match ) { if ( is_numeric ( $ index ) && $ index != 0 ) { $ value = str_replace ( '$' . $ index , $ match , $ value ) ; } } return $ value ; }
|
Get regex property .
|
2,148
|
protected function pregMatchArray ( $ input , $ rules , $ flags = 0 ) { if ( ! is_array ( $ rules ) ) { return false ; } foreach ( $ rules as $ rule => $ value ) { if ( preg_match ( $ rule , $ input , $ matches , $ flags ) ) { return array_merge ( $ matches , [ 'value' => $ value ] ) ; } } return false ; }
|
Applies the regular expressions stored in the keys of the given array to the given input string . Returns the first match including the matching value .
|
2,149
|
public function addField ( $ id , $ value , $ name = null ) { $ field = $ this -> _service -> newField ( $ id , $ value , $ name ) ; return $ this -> attachField ( $ field ) ; }
|
Instantiates and attaches a field to this document .
|
2,150
|
public function attachField ( IndexField $ field ) { $ id = $ field -> getId ( ) ; $ this -> _fields [ $ id ] = $ field ; return $ this ; }
|
Adds a field to the document .
|
2,151
|
public function getField ( $ id ) { if ( ! isset ( $ this -> _fields [ $ id ] ) ) { $ this -> $ id = '' ; } return $ this -> _fields [ $ id ] ; }
|
Returns a field that is attached to this document .
|
2,152
|
public function setPermissions ( $ permissions ) { if ( is_string ( $ permissions ) ) { $ permissions = '0' . ltrim ( $ permissions , '0' ) ; $ permissions = octdec ( $ permissions ) ; } return chmod ( $ this -> path , $ permissions ) ; }
|
Sets the permissions
|
2,153
|
public static function reset ( $ namespace = null , array $ extensions = array ( ) ) { self :: $ functions = array ( ) ; foreach ( $ extensions as $ extension ) { foreach ( \ get_extension_funcs ( $ extension ) as $ name ) { self :: evaluate ( $ namespace , $ name ) ; } } }
|
Sets all custom function properties to null .
|
2,154
|
public static function parseToIndex ( $ input ) { if ( ( $ input [ 0 ] == '{' || $ input [ 0 ] == '[' ) ) { return Arc2JsonLdConverter :: jsonLdToIndex ( $ input ) ; } else { $ parser = \ ARC2 :: getRDFParser ( ) ; $ parser -> parse ( '' , $ input ) ; return $ parser -> getSimpleIndex ( false ) ; } }
|
Parses the given input and returns an ARC2 index . If the input is JsonLD the JsonLD parser is used otherwise ARC2 is used .
|
2,155
|
protected function getExtensions ( ) { if ( file_exists ( realpath ( __DIR__ . '/../../../../../config/twig.php' ) ) ) { $ this -> config = require realpath ( __DIR__ . '/../../../../../config/twig.php' ) ; } else { $ this -> config = require realpath ( __DIR__ . '/../../config/twig.php' ) ; } return isset ( $ this -> config [ 'extensions' ] ) ? $ this -> config [ 'extensions' ] : [ ] ; }
|
Get extensions defined by application developer .
|
2,156
|
private function registerExtension ( \ Twig_Environment $ twig ) { $ extensions = $ this -> getExtensions ( ) ; if ( count ( $ extensions ) ) { foreach ( $ extensions as $ key => $ extension ) { $ this -> load ( $ twig , $ key , $ extension ) ; } } }
|
Register twig extensions .
|
2,157
|
public static function once ( $ function ) { $ called = false ; $ value = null ; return function ( ) use ( $ function , & $ called , & $ value ) { if ( ! $ called ) { $ args = func_get_args ( ) ; $ value = call_user_func_array ( $ function , $ args ) ; $ called = true ; } return $ value ; } ; }
|
Creates a version of the function that can only be called one time .
|
2,158
|
public static function partial ( $ function , $ arg ) { $ bound = func_get_args ( ) ; array_shift ( $ bound ) ; $ placeholder = static :: p ( ) ; return function ( ) use ( $ function , $ bound , $ placeholder ) { $ inject = func_get_args ( ) ; $ args = [ ] ; foreach ( $ bound as $ value ) { if ( $ value === $ placeholder ) { $ args [ ] = array_shift ( $ inject ) ; } else { $ args [ ] = $ value ; } } $ args = array_merge ( $ args , $ inject ) ; return call_user_func_array ( $ function , $ args ) ; } ; }
|
Partially apply a function by filling in any number of its arguments .
|
2,159
|
public static function wrap ( $ function , $ wrapper ) { return function ( ) use ( $ function , $ wrapper ) { $ args = func_get_args ( ) ; array_unshift ( $ args , $ function ) ; return call_user_func_array ( $ wrapper , $ args ) ; } ; }
|
Wraps the first function inside of the wrapper function passing it as the first argument .
|
2,160
|
public static function throttle ( $ function , $ wait , array $ options = [ ] ) { $ options += [ 'leading' => true , ] ; $ previous = 0 ; $ callback = function ( ) use ( $ function , $ wait , & $ previous ) { $ now = floor ( microtime ( true ) * 1000 ) ; if ( ( $ wait - ( $ now - $ previous ) ) <= 0 ) { $ args = func_get_args ( ) ; call_user_func_array ( $ function , $ args ) ; $ previous = $ now ; } } ; if ( $ options [ 'leading' ] !== false ) { $ callback ( ) ; } return $ callback ; }
|
Creates and returns a new throttled version of the passed function .
|
2,161
|
public static function before ( $ count , $ function ) { $ memo = null ; return function ( ) use ( $ function , & $ count , & $ memo ) { if ( -- $ count > 0 ) { $ args = func_get_args ( ) ; $ memo = call_user_func_array ( $ function , $ args ) ; } return $ memo ; } ; }
|
Creates a version of the function that can be called no more than count times .
|
2,162
|
public function loadImage ( $ image ) { $ imageLibrary = ucfirst ( $ this -> imageLibrary ) ; $ functionName = 'loadWith' . $ imageLibrary ; $ this -> image = $ image ; if ( ! method_exists ( $ this , $ functionName ) ) { throw new IcrRuntimeException ( 'Wrong image library name provided!' ) ; } return call_user_func ( [ $ this , $ functionName ] ) ; }
|
Loads image from data string with imagine based on the driver name
|
2,163
|
public function openImage ( $ path ) { $ imageLibrary = ucfirst ( $ this -> imageLibrary ) ; $ functionName = 'openWith' . $ imageLibrary ; $ this -> path = $ path ; if ( ! method_exists ( $ this , $ functionName ) ) { throw new IcrRuntimeException ( 'Wrong image library name provided!' ) ; } return call_user_func ( [ $ this , $ functionName ] ) ; }
|
Open image from path with imagine library
|
2,164
|
public function create ( $ variables = null , $ options = null ) { $ viewModel = new ViewModel ( $ variables , $ options ) ; $ viewModel -> setTerminal ( $ this -> isTerminal ( ) ) ; $ viewModel -> setVariable ( 'isTerminal' , $ viewModel -> terminate ( ) ) ; return $ viewModel ; }
|
Create ViewModel instance and set terminal mode by HttpRequest
|
2,165
|
public function run ( ) { $ this -> say ( "Building library folder " . $ this -> libName ) ; if ( ! file_exists ( $ this -> source ) ) { $ this -> say ( "Folder " . $ this -> source . " does not exist!" ) ; return true ; } $ this -> prepareDirectory ( ) ; $ tar = $ this -> target ; if ( ! $ this -> hasComponent ) { $ tar = $ this -> target . "/libraries/" . $ this -> libName ; } $ files = $ this -> copyTarget ( $ this -> source , $ tar ) ; $ lib = $ this -> libName ; if ( substr ( $ this -> libName , 0 , 3 ) != "lib" ) { $ lib = 'lib_' . $ this -> libName ; } $ media = $ this -> buildMedia ( "media/" . $ lib , $ lib ) ; $ media -> run ( ) ; $ this -> addFiles ( 'media' , $ media -> getResultFiles ( ) ) ; $ language = $ this -> buildLanguage ( $ lib ) ; $ language -> run ( ) ; $ this -> createInstaller ( $ files ) ; return true ; }
|
Runs the library build tasks just copying files currently
|
2,166
|
private function createInstaller ( $ files ) { $ this -> say ( "Creating library installer" ) ; $ xmlFile = $ this -> target . "/" . $ this -> libName . ".xml" ; $ this -> replaceInFile ( $ xmlFile ) ; $ f = $ this -> generateFileList ( $ files ) ; $ this -> taskReplaceInFile ( $ xmlFile ) -> from ( '##LIBRARYFILES##' ) -> to ( $ f ) -> run ( ) ; $ f = $ this -> generateLanguageFileList ( $ this -> getFiles ( 'backendLanguage' ) ) ; $ this -> taskReplaceInFile ( $ xmlFile ) -> from ( '##BACKEND_LANGUAGE_FILES##' ) -> to ( $ f ) -> run ( ) ; $ f = $ this -> generateLanguageFileList ( $ this -> getFiles ( 'frontendLanguage' ) ) ; $ this -> taskReplaceInFile ( $ xmlFile ) -> from ( '##FRONTEND_LANGUAGE_FILES##' ) -> to ( $ f ) -> run ( ) ; $ f = $ this -> generateFileList ( $ this -> getFiles ( 'media' ) ) ; $ this -> taskReplaceInFile ( $ xmlFile ) -> from ( '##MEDIA_FILES##' ) -> to ( $ f ) -> run ( ) ; }
|
Generate the installer xml file for the library
|
2,167
|
public function add ( ProcessableComponentInterface $ component ) { switch ( get_class ( $ component ) ) { case "IP1\RESTClient\Recipient\Contact" : $ response = $ this -> sendRequest ( "api/contacts" , "POST" , json_encode ( $ component ) ) ; return RecipientFactory :: createProcessedContactFromJSON ( $ response ) ; case "IP1\RESTClient\Recipient\Group" : $ response = $ this -> sendRequest ( "api/groups" , "POST" , json_encode ( $ component ) ) ; return RecipientFactory :: createProcessedGroupFromJSON ( $ response ) ; case "IP1\RESTClient\Recipient\Membership" : $ response = $ this -> sendRequest ( "api/memberships" , "POST" , json_encode ( $ component ) ) ; return RecipientFactory :: createProcessedMembershipFromJSON ( $ response ) ; case "IP1\RESTClient\SMS\OutGoingSMS" : $ response = $ this -> sendRequest ( "api/sms/send" , "POST" , json_encode ( $ component ) ) ; return RecipientFactory :: createProcessedOutGoingSMSFromJSONArray ( $ response ) ; case "IP1\RESTClient\Recipient\BlacklistEntry" : $ response = $ this -> sendRequest ( "api/blacklist" , "POST" , json_encode ( $ component ) ) ; $ stdResponse = json_decode ( $ response ) ; $ created = new \ DateTime ( $ stdResponse -> Created ) ; return new ProcessedBlacklistEntry ( $ stdResponse -> Phone , $ stdResponse -> ID , $ created ) ; default : throw new \ InvalidArgumentException ( "Given JsonSerializable not supported." ) ; } }
|
Adds the param to the API and returns the response as the corresponding object .
|
2,168
|
public function remove ( ProcessedComponentInterface $ component ) : ProcessedComponentInterface { switch ( get_class ( $ component ) ) { case "IP1\RESTClient\Recipient\ProcessedContact" : $ response = $ this -> sendRequest ( "api/contacts/" . $ component -> getID ( ) , "DELETE" ) ; return RecipientFactory :: createProcessedContactFromJSON ( $ response ) ; case "IP1\RESTClient\Recipient\ProcessedGroup" : $ response = $ this -> sendRequest ( "api/groups/" . $ component -> getID ( ) , "DELETE" ) ; return RecipientFactory :: createProcessedGroupFromJSON ( $ response ) ; case "IP1\RESTClient\Recipient\ProcessedMembership" : $ response = $ this -> sendRequest ( "api/memberships/" . $ component -> getID ( ) , "DELETE" ) ; return RecipientFactory :: createProcessedMembershipFromJSON ( $ response ) ; case "IP1\RESTClient\Recipient\ProcessedBlacklistEntry" : $ response = $ this -> sendRequest ( "api/blacklist/" . $ component -> getID ( ) , "DELETE" ) ; $ stdResponse = json_decode ( $ response ) ; $ created = new \ DateTime ( $ stdResponse -> Created ) ; return new ProcessedBlacklistEntry ( $ stdResponse -> Phone , $ stdResponse -> ID , $ created ) ; default : throw new \ InvalidArgumentException ( "Given JsonSerializable not supported." ) ; } }
|
Removes the param to the API and returns the response as the corresponding object .
|
2,169
|
public function edit ( UpdatableComponentInterface $ component ) : UpdatableComponentInterface { switch ( get_class ( $ component ) ) { case "IP1\RESTClient\Recipient\ProcessedContact" : $ response = $ this -> sendRequest ( "api/contacts/" . $ component -> getID ( ) , "PUT" , json_encode ( $ component ) ) ; return RecipientFactory :: createProcessedContactFromJSON ( $ response ) ; case "IP1\RESTClient\Recipient\ProcessedGroup" : $ response = $ this -> sendRequest ( "api/groups/" . $ component -> getID ( ) , "PUT" , json_encode ( $ component ) ) ; return RecipientFactory :: createProcessedGroupFromJSON ( $ response ) ; default : throw new \ InvalidArgumentException ( "Given JsonSerializable not supported." ) ; } }
|
Edits the param to the API and returns the response as the corresponding object .
|
2,170
|
public function post ( string $ endPoint , \ JsonSerializable $ content ) : string { $ parsedEndPoint = self :: parseEndPoint ( $ endPoint ) ; return $ this -> sendRequest ( $ parsedEndPoint , "POST" , json_encode ( $ content ) ) ; }
|
Adds the content object to the endpoint and returns a processed version of given object .
|
2,171
|
public function delete ( string $ endPoint ) : string { $ parsedEndPoint = self :: parseEndPoint ( $ endPoint ) ; return $ this -> sendRequest ( $ parsedEndPoint , "DELETE" ) ; }
|
Deletes the object at the given endpoint
|
2,172
|
private static function parseEndPoint ( string $ endPoint ) { $ endPoint = trim ( $ endPoint , '/' ) ; $ endPointArray = explode ( '/' , $ endPoint ) ; if ( $ endPointArray [ 0 ] == "api" ) { return $ endPoint ; } array_unshift ( $ endPointArray , "api" ) ; return implode ( '/' , array_filter ( $ endPointArray ) ) ; }
|
Turns the given endPoint string into a usable .
|
2,173
|
private function sendRequest ( string $ endPoint , string $ method , string $ content = "" , bool $ https = true ) : Response { $ url = ( $ https ? "https://" : "http://" ) . self :: DOMAIN . "/" . $ endPoint ; $ request = \ Httpful \ Request :: init ( $ method , 'application/json' ) ; $ request -> basicAuth ( $ this -> accountToken , $ this -> apiToken ) -> addHeader ( 'User-Agent' , 'iP1sms/indev' ) -> expectsJson ( ) -> Uri ( $ url ) -> body ( $ content , 'application/json' ) -> neverSerialize ( ) ; $ response = $ request -> send ( ) ; if ( $ response -> hasErrors ( ) ) { $ this -> errorResponses [ ] = $ response ; } return $ response ; }
|
Sends a HTTP request to the RESTful API and returns the result as a JSON string .
|
2,174
|
public function isSpecific ( ) { foreach ( $ this -> modelDevices as $ modelDevice ) { if ( $ modelDevice -> specific === true || $ modelDevice -> actualDeviceRoot === true ) { return true ; } } return false ; }
|
Device is a specific or actual WURFL device as defined by its capabilities
|
2,175
|
public function getCapability ( $ capabilityName ) { if ( empty ( $ capabilityName ) ) { throw new \ InvalidArgumentException ( 'capability name must not be empty' ) ; } if ( ! $ this -> getRootDevice ( ) -> isCapabilityDefined ( $ capabilityName ) ) { throw new \ InvalidArgumentException ( 'no capability named [' . $ capabilityName . '] is present in wurfl.' ) ; } foreach ( $ this -> modelDevices as $ modelDevice ) { $ capabilityValue = $ modelDevice -> getCapability ( $ capabilityName ) ; if ( $ capabilityValue !== null ) { return $ capabilityValue ; } } return null ; }
|
Returns the value of a given capability name for the current device
|
2,176
|
public function render ( $ depth = 0 , $ indent = null , $ inner = false ) { return parent :: render ( $ depth , $ indent , $ inner ) . $ this -> datalist -> render ( $ depth , $ indent , $ inner ) ; }
|
Render the datalist element
|
2,177
|
function process ( $ id , $ language = null ) { if ( ! $ language && defined ( 'CONTENTFUL_DEFAULT_LANGUAGE' ) ) { $ language = CONTENTFUL_DEFAULT_LANGUAGE ; } else { $ language = 'en-US' ; } $ this -> requestDecorator -> setId ( $ id . '/files/' . $ language . '/process' ) ; $ result = $ this -> client -> put ( $ this -> requestDecorator -> makeResource ( ) , $ this -> requestDecorator -> makePayload ( ) , $ this -> requestDecorator -> makeHeaders ( ) ) ; $ this -> refresh ( ) ; return $ result ; }
|
Process an asset .
|
2,178
|
public function getInputValue ( $ key = null , $ default = null ) { $ input = $ this -> getInputSource ( ) -> all ( ) + $ this -> query -> all ( ) ; return ArrayHelper :: get ( $ input , $ key , $ default ) ; }
|
Get an input item from the request .
|
2,179
|
public function get ( $ key , $ default = null , $ includeCookies = true ) { if ( $ includeCookies ) { if ( $ this !== $ result = $ this -> cookies -> get ( $ key , $ this ) ) { return $ result ; } } return parent :: get ( $ key , $ default ) ; }
|
Gets a parameter value from any bag . You can include the cookies bag . It is included by default .
|
2,180
|
private function addPortToUri ( UriInterface $ uri ) : UriInterface { $ requestPort = $ this -> request -> getUri ( ) -> getPort ( ) ; if ( ! in_array ( $ requestPort , [ 80 , 443 ] ) ) { $ uri = $ uri -> withPort ( $ requestPort ) ; } return $ uri ; }
|
Adds port to URI if it is needed .
|
2,181
|
private function buildRouteUri ( RouteContract $ route , array $ variables = [ ] , array $ query = [ ] ) : UriInterface { $ uri = $ this -> uri -> withScheme ( $ route -> scheme ( ) ? : $ this -> request -> getUri ( ) -> getScheme ( ) ) -> withHost ( $ route -> host ( ) ? : $ this -> request -> getUri ( ) -> getHost ( ) ) -> withPath ( $ route -> compilePath ( $ variables ) ) ; if ( $ query ) { $ uri = $ uri -> withQuery ( http_build_query ( $ query ) ) ; } return $ this -> addPortToUri ( $ uri ) ; }
|
Builds URI for provided route instance .
|
2,182
|
protected static function hasStaleCacheFile ( ) { $ composerTravisLintCache = getcwd ( ) . DIRECTORY_SEPARATOR . self :: CTL_CACHE ; $ travisConfiguration = getcwd ( ) . DIRECTORY_SEPARATOR . self :: TRAVIS_CONFIGURATION ; if ( file_exists ( $ composerTravisLintCache ) && file_exists ( $ travisConfiguration ) ) { $ travisConfigurationContent = trim ( file_get_contents ( $ travisConfiguration ) ) ; $ composerTravisLintCacheContent = trim ( file_get_contents ( $ composerTravisLintCache ) ) ; if ( md5 ( $ travisConfigurationContent ) === $ composerTravisLintCacheContent ) { return false ; } } return true ; }
|
Check if composer travis lint cache is stale .
|
2,183
|
public static function lint ( Event $ event , Api $ api = null ) { $ composerTravisLintCache = getcwd ( ) . DIRECTORY_SEPARATOR . self :: CTL_CACHE ; $ io = $ event -> getIO ( ) ; if ( ! file_exists ( self :: TRAVIS_CONFIGURATION ) ) { $ io -> writeError ( "Travis CI configuration doesn't exist." ) ; return false ; } if ( self :: hasStaleCacheFile ( ) === false ) { $ message = 'Travis CI configuration has not ' . 'changed since the last lint run and is therefore valid.' ; $ io -> write ( $ message ) ; return true ; } $ travisConfigContent = trim ( file_get_contents ( realpath ( self :: TRAVIS_CONFIGURATION ) ) ) ; if ( $ api === null ) { $ api = new Api ( ) ; } try { $ result = $ api -> post ( $ travisConfigContent ) ; if ( $ result -> isSuccessful ( ) ) { $ message = 'Travis CI configuration is valid.' ; $ bytesWritten = file_put_contents ( $ composerTravisLintCache , md5 ( $ travisConfigContent ) . "\n" ) ; if ( $ bytesWritten > 0 ) { $ message .= PHP_EOL . "Created '" . self :: CTL_CACHE . "' file." ; } $ io -> write ( $ message ) ; return true ; } $ errorMessage = $ result -> getFailure ( ) ; if ( file_exists ( $ composerTravisLintCache ) ) { unlink ( $ composerTravisLintCache ) ; $ errorMessage .= PHP_EOL . "Deleted '" . self :: CTL_CACHE . "' file." ; } $ io -> writeError ( $ errorMessage ) ; return false ; } catch ( ConnectivityFailure $ f ) { $ io -> writeError ( $ f -> getMessage ( ) ) ; return false ; } catch ( NonExpectedReponseStructure $ n ) { $ io -> writeError ( $ n -> getMessage ( ) ) ; return false ; } }
|
The Composer script to lint a Travis CI configuration file .
|
2,184
|
public static function header ( $ data ) { if ( empty ( $ data [ 'response' ] ) ) { throw new NetException ( "Can't create Authorization headers from an empty response." ) ; } if ( ! isset ( $ data [ 'nonce' ] ) ) { return "Basic " . $ data [ 'response' ] ; } $ defaults = [ 'realm' => 'app' , 'method' => 'GET' , 'uri' => '/' , 'username' => null , 'qop' => 'auth' , 'nonce' => null , 'opaque' => null , 'cnonce' => md5 ( time ( ) ) , 'nc' => static :: $ nc ] ; $ data += $ defaults ; $ auth = "username=\"{$data['username']}\", response=\"{$data['response']}\", " ; $ auth .= "uri=\"{$data['uri']}\", realm=\"{$data['realm']}\", " ; $ auth .= "qop=\"{$data['qop']}\", nc={$data['nc']}, cnonce=\"{$data['cnonce']}\", " ; $ auth .= "nonce=\"{$data['nonce']}\", opaque=\"{$data['opaque']}\"" ; return "Digest " . $ auth ; }
|
Returns the proper header string . Accepts the data from the encode method .
|
2,185
|
public static function encode ( $ username , $ password , $ data = [ ] ) { if ( ! isset ( $ data [ 'nonce' ] ) ) { $ response = base64_encode ( "{$username}:{$password}" ) ; return compact ( 'username' , 'response' ) ; } $ defaults = [ 'realm' => 'app' , 'method' => 'GET' , 'uri' => '/' , 'qop' => null , 'cnonce' => md5 ( time ( ) ) , 'nc' => static :: $ nc ] ; $ data = array_filter ( $ data ) + $ defaults ; $ part1 = md5 ( "{$username}:{$data['realm']}:{$password}" ) ; $ part2 = "{$data['nonce']}:{$data['nc']}:{$data['cnonce']}:{$data['qop']}" ; $ part3 = md5 ( $ data [ 'method' ] . ':' . $ data [ 'uri' ] ) ; $ response = md5 ( "{$part1}:{$part2}:{$part3}" ) ; return compact ( 'username' , 'response' ) + $ data ; }
|
Encodes the data with username and password to create the proper response . Returns an array containing the username and encoded response .
|
2,186
|
public static function decode ( $ header ) { $ data = [ 'realm' => null , 'username' => null , 'uri' => null , 'nonce' => null , 'opaque' => null , 'qop' => null , 'cnonce' => null , 'nc' => null , 'response' => null ] ; $ keys = implode ( '|' , array_keys ( $ data ) ) ; $ regex = '~(' . $ keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))~' ; preg_match_all ( $ regex , $ header , $ matches , PREG_SET_ORDER ) ; foreach ( $ matches as $ m ) { $ data [ $ m [ 1 ] ] = $ m [ 3 ] ? $ m [ 3 ] : $ m [ 4 ] ; } return $ data ; }
|
Takes the header string and parses out the params needed for a digest authentication .
|
2,187
|
public function setRoot ( $ root ) { if ( ! $ path = realpath ( $ root ) ) { throw new \ Exception ( 'Location does not exist: ' . $ root ) ; } $ this -> root = $ path ; }
|
Sets a root restriction
|
2,188
|
public function addPaths ( array $ paths , $ clearCache = true , $ group = '__DEFAULT__' ) { array_map ( [ $ this , 'addPath' ] , $ paths , [ [ $ clearCache , $ group ] ] ) ; }
|
Adds paths to look in
|
2,189
|
public function removePaths ( array $ paths , $ clearCache = true , $ group = '__DEFAULT__' ) { array_map ( [ $ this , 'removePath' ] , $ paths , [ [ $ clearCache , $ group ] ] ) ; }
|
Removes paths to look in
|
2,190
|
public function removePathCache ( $ path ) { foreach ( $ this -> cache as $ key => $ cache ) { if ( in_array ( $ path , $ cache [ 'used' ] ) ) { unset ( $ this -> cache [ $ key ] ) ; } } }
|
Removes path cache
|
2,191
|
public function normalizePath ( $ path ) { $ path = rtrim ( $ path , '/\\' ) . DIRECTORY_SEPARATOR ; $ path = realpath ( $ path ) . DIRECTORY_SEPARATOR ; if ( $ this -> root and strpos ( $ path , $ this -> root ) !== 0 ) { throw new \ Exception ( 'Cannot access path outside: ' . $ this -> root . '. Trying to access: ' . $ path ) ; } return $ path ; }
|
Normalizes a path
|
2,192
|
public function getPaths ( $ group = '__DEFAULT__' ) { if ( ! isset ( $ this -> paths [ $ group ] ) ) { return [ ] ; } return array_values ( $ this -> paths [ $ group ] ) ; }
|
Returns the paths set up to look in
|
2,193
|
public function setPaths ( array $ paths , $ clearCache = true , $ group = '__DEFAULT__' ) { $ this -> paths [ $ group ] = [ ] ; $ this -> addPaths ( $ paths , false , $ group ) ; if ( $ clearCache ) { $ this -> cache = [ ] ; } }
|
Replaces all the paths
|
2,194
|
public function findCached ( $ scope , $ name , $ reversed ) { $ cacheKey = $ this -> makeCacheKey ( $ scope , $ name , $ reversed ) ; if ( isset ( $ this -> cache [ $ cacheKey ] ) ) { return $ this -> cache [ $ cacheKey ] [ 'result' ] ; } }
|
Retrieves a location from cache
|
2,195
|
public function cache ( $ scope , $ name , $ reversed , $ result , $ pathsUsed = [ ] ) { $ cacheKey = $ this -> makeCacheKey ( $ scope , $ name , $ reversed ) ; $ this -> cache [ $ cacheKey ] = [ 'result' => $ result , 'used' => $ pathsUsed , ] ; }
|
Caches a find result
|
2,196
|
public function makeCacheKey ( $ scope , $ name , $ reversed ) { $ cacheKey = $ scope . '::' . $ name ; if ( $ reversed ) { $ cacheKey .= '::reversed' ; } return $ cacheKey ; }
|
Generates a cache key
|
2,197
|
public function negotiate ( $ request ) { $ media = $ this -> _classes [ 'media' ] ; foreach ( $ request -> accepts ( ) as $ mime => $ value ) { if ( $ format = $ media :: suitable ( $ request , $ mime ) ) { $ this -> format ( $ format ) ; return ; } } $ mimes = join ( '", "' , array_keys ( $ request -> accepts ( ) ) ) ; throw new NetException ( "Unsupported Media Type: [\"{$mimes}\"]." , 415 ) ; }
|
Performs a format negotiation from a Request object by iterating over the accepted content types in sequence from most preferred to least .
|
2,198
|
public function dump ( ) { $ this -> _setContentLength ( ) ; header ( $ this -> line ( ) ) ; $ headers = $ this -> headers ( ) ; foreach ( $ headers as $ header ) { header ( $ header -> to ( 'header' ) ) ; } if ( $ headers [ 'Transfer-Encoding' ] -> value ( ) === 'chunked' ) { return ; } if ( $ this -> _stream -> isSeekable ( ) ) { $ this -> _stream -> rewind ( ) ; } while ( ! $ this -> _stream -> eof ( ) ) { echo $ this -> _stream -> read ( ) ; if ( connection_status ( ) !== CONNECTION_NORMAL ) { break ; } } }
|
Renders a response by writing headers and output .
|
2,199
|
public function push ( $ data , $ atomic = true , $ options = [ ] ) { $ headers = $ this -> headers ( ) ; if ( $ headers [ 'Transfer-Encoding' ] -> value ( ) !== 'chunked' ) { throw new NetException ( "Pushing is only supported in chunked transfer." ) ; } $ defaults = [ 'cast' => true , 'atomic' => true , 'stream' => [ ] , 'encode' => [ ] ] ; $ options += $ defaults ; if ( $ data instanceof StreamInterface ) { $ stream = $ data ; } else { if ( $ options [ 'cast' ] ) { $ media = $ this -> _classes [ 'media' ] ; $ format = $ this -> format ( ) ; if ( ! $ format && ! is_string ( $ data ) ) { throw new NetException ( "The data must be a string when no format is defined." ) ; } $ data = $ media :: encode ( $ format , $ data , $ options [ 'encode' ] , $ this ) ; } $ stream = new Part ( [ 'data' => $ data ] + $ options [ 'stream' ] ) ; } $ length = $ options [ 'atomic' ] && $ stream -> isSeekable ( ) ? $ stream -> length ( ) : $ this -> chunkSize ( ) ; if ( $ stream -> isSeekable ( ) ) { $ stream -> rewind ( ) ; } while ( ! $ stream -> eof ( ) ) { $ chunk = $ stream -> read ( $ length ) ; $ readed = strlen ( $ chunk ) ; if ( ! $ readed ) { break ; } echo dechex ( $ readed ) . "\r\n" . $ chunk . "\r\n" ; if ( connection_status ( ) !== CONNECTION_NORMAL ) { break ; } } $ stream -> close ( ) ; }
|
Push additionnal data to a chunked response .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.