idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
57,300
private static function rmdirRecursive ( $ path ) { $ files = scandir ( $ path ) ; array_shift ( $ files ) ; array_shift ( $ files ) ; foreach ( $ files as $ file ) { $ file = $ path . DIRECTORY_SEPARATOR . $ file ; if ( is_dir ( $ file ) ) { self :: rmdirRecursive ( $ file ) ; } else { unlink ( $ file ) ; } } rmdir ( ...
Removes files and folders recursively at provided path .
57,301
public function iRunBehat ( $ argumentsString = '' ) { $ argumentsString = strtr ( $ argumentsString , [ '\'' => '"' ] ) ; if ( '/' === DIRECTORY_SEPARATOR ) { $ argumentsString .= ' 2>&1' ; } exec ( $ command = sprintf ( '%s %s %s --no-time' , BEHAT_PHP_BIN_PATH , escapeshellarg ( BEHAT_BIN_PATH ) , $ argumentsString ...
Runs behat command with provided parameters .
57,302
private function formatDuration ( $ milliseconds ) { $ hours = floor ( $ milliseconds / 1000 / 3600 ) ; $ milliseconds -= ( $ hours * 3600 * 1000 ) ; $ minutes = floor ( $ milliseconds / 1000 / 60 ) ; $ milliseconds -= ( $ minutes * 60 * 1000 ) ; $ seconds = floor ( $ milliseconds / 1000 ) ; $ milliseconds -= ( $ secon...
Method to format duration to human readable format .
57,303
private function formatMemory ( $ bytes ) { $ units = [ 'B' , 'KiB' , 'MiB' , 'GiB' ] ; $ mod = 1024 ; $ power = ( $ bytes > 0 ) ? ( int ) floor ( log ( $ bytes , $ mod ) ) : 0 ; return sprintf ( '%01.2f %s' , $ bytes / pow ( $ mod , $ power ) , $ units [ $ power ] ) ; }
Method to format memory usage to human readable format .
57,304
private function _getScenarios ( $ featurePath ) { $ scenarios = [ ] ; $ featureNodes = $ this -> container -> get ( 'gherkin' ) -> load ( $ featurePath ) ; foreach ( $ featureNodes as $ featureNode ) { foreach ( $ featureNode -> getScenarios ( ) as $ scenario ) { $ file = $ scenario -> getFile ( ) ; $ lines = [ $ scen...
Returns an array of absolute feature file paths and scenarios line numbers .
57,305
public function getStoresForFrontend ( ) { $ collection = $ this -> stockistsCollectionFactory -> create ( ) -> addFieldToSelect ( '*' ) -> addFieldToFilter ( 'store_id' , $ this -> getStoreId ( ) ) -> addFieldToFilter ( 'status' , Stores :: STATUS_ENABLED ) -> setOrder ( 'name' , 'ASC' ) ; return $ collection ; }
return stockists collection
57,306
public function getLocationSettings ( ) : int { return ( int ) $ this -> _scopeConfig -> getValue ( self :: ASK_LOCATION_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; }
get location settings from configuration
57,307
public function getZoomSettings ( ) : int { return ( int ) $ this -> _scopeConfig -> getValue ( self :: ZOOM_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; }
get zoom settings from configuration
57,308
public function getSliderSettings ( ) : int { return ( int ) $ this -> _scopeConfig -> getValue ( self :: SLIDER_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; }
get slider settings from configuration
57,309
public function getOtherStoresSettings ( ) : int { return ( int ) $ this -> _scopeConfig -> getValue ( self :: OTHER_STORES_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; }
get other stores settings from configuration
57,310
public function getZoomIndividualSettings ( ) : int { return ( int ) $ this -> _scopeConfig -> getValue ( self :: ZOOM_INDIVIDUAL_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; }
get individual zoom settings from configuration for store details page
57,311
public function getLatitudeSettings ( ) : float { return ( float ) $ this -> _scopeConfig -> getValue ( self :: LATITUDE_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; }
get latitude settings from configuration
57,312
public function getLongitudeSettings ( ) : float { return ( float ) $ this -> _scopeConfig -> getValue ( self :: LONGITUDE_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; }
get longitude settings from configuration
57,313
public function getRadiusSettings ( ) : float { return ( float ) $ this -> _scopeConfig -> getValue ( self :: RADIUS_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; }
get radius settings from configuration
57,314
public function getStrokeWeightSettings ( ) : float { return ( float ) $ this -> _scopeConfig -> getValue ( self :: STROKE_WEIGHT_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; }
get stroke weight settings from configuration
57,315
public function getStrokeOpacitySettings ( ) : float { return ( float ) $ this -> _scopeConfig -> getValue ( self :: STROKE_OPACITY_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; }
get stroke opacity settings from configuration
57,316
public function getFillOpacitySettings ( ) : float { return ( float ) $ this -> _scopeConfig -> getValue ( self :: FILL_OPACITY_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; }
get fill opacity settings from configuration
57,317
public function getBaseImageUrl ( ) : string { return $ this -> _storeManager -> getStore ( ) -> getBaseUrl ( \ Magento \ Framework \ UrlInterface :: URL_TYPE_MEDIA ) ; }
get base image url
57,318
public function execute ( ) { try { $ result = $ this -> uploader -> saveFileToTmpDir ( $ this -> getFieldName ( ) ) ; $ result [ 'cookie' ] = [ 'name' => $ this -> _getSession ( ) -> getName ( ) , 'value' => $ this -> _getSession ( ) -> getSessionId ( ) , 'lifetime' => $ this -> _getSession ( ) -> getCookieLifetime ( ...
Upload file controller action
57,319
public function getIndividualStore ( $ url ) { $ collection = $ this -> stockistsCollectionFactory -> create ( ) -> addFieldToSelect ( '*' ) -> addFieldToFilter ( 'status' , Stores :: STATUS_ENABLED ) -> addFieldToFilter ( 'link' , $ url ) -> addStoreFilter ( $ this -> storeManager -> getStore ( ) -> getId ( ) ) -> set...
return stockists collection filtered by url
57,320
public function _beforeDelete ( AbstractModel $ object ) { $ condition = [ 'stockist_id = ?' => ( int ) $ object -> getId ( ) ] ; $ this -> getConnection ( ) -> delete ( $ this -> getTable ( 'limesharp_stockists_stores' ) , $ condition ) ; return parent :: _beforeDelete ( $ object ) ; }
Process stockist data before deleting
57,321
public function _beforeSave ( AbstractModel $ object ) { $ object -> setUpdatedAt ( $ this -> date -> gmtDate ( ) ) ; if ( $ object -> isObjectNew ( ) ) { $ object -> setCreatedAt ( $ this -> date -> gmtDate ( ) ) ; } return parent :: _beforeSave ( $ object ) ; }
before save callback
57,322
public function loadData ( $ printQuery = false , $ logQuery = false ) { if ( ! $ this -> isLoaded ( ) ) { $ searchCriteria = $ this -> getSearchCriteria ( ) ; $ searchResults = $ this -> stockistRepository -> getList ( $ searchCriteria ) ; $ this -> _totalRecords = $ searchResults -> getTotalCount ( ) ; $ stockists = ...
Load customer group collection data from service
57,323
public function filterFileData ( array $ fileHeaders , array $ rawStockistData ) { $ rowCount = 0 ; $ rawDataRows = [ ] ; foreach ( $ rawStockistData as $ rowIndex => $ dataRow ) { if ( $ rowIndex == 0 ) { continue ; } if ( count ( $ dataRow ) <= 1 ) { unset ( $ rawStockistData [ $ rowIndex ] ) ; continue ; } if ( $ ro...
Filter data so that it will skip empty rows and headers
57,324
public function saveUrlRewrite ( $ link , $ id , $ storeIds ) { $ moduleUrl = $ this -> stockistsConfig -> getModuleUrlSettings ( ) ; $ getCustomUrlRewrite = $ moduleUrl . "/" . $ link ; $ stockistId = $ moduleUrl . "-" . $ id ; $ storeIds = explode ( "," , $ storeIds ) ; foreach ( $ storeIds as $ storeId ) { $ filterD...
Saves the url rewrite for that specific store
57,325
public function afterSave ( ) { $ storeId = $ this -> storeManager -> getStore ( ) -> getId ( ) ; if ( $ this -> hasDataChanges ( ) ) { $ getCustomUrlRewrite = $ this -> _data [ "groups" ] [ "stockist_content" ] [ "fields" ] [ "url" ] [ "value" ] ; foreach ( $ this -> _data as $ key => $ value ) { if ( $ key == "field"...
after save callback
57,326
public function setBaseFile ( $ file ) { $ this -> isBaseFilePlaceholder = false ; if ( $ file && 0 !== strpos ( $ file , '/' , 0 ) ) { $ file = '/' . $ file ; } $ baseDir = $ this -> uploader -> getBasePath ( ) ; if ( $ file ) { if ( ! $ this -> fileExists ( $ baseDir . $ file ) || ! $ this -> checkMemory ( $ baseDir ...
Set filenames for base file and new file
57,327
public function setWatermark ( $ file , $ position = null , $ size = null , $ width = null , $ height = null , $ opacity = null ) { if ( $ this -> isBaseFilePlaceholder ) { return $ this ; } if ( $ file ) { $ this -> setWatermarkFile ( $ file ) ; } else { return $ this ; } if ( $ position ) { $ this -> setWatermarkPosi...
Add watermark to image size param in format 100x200
57,328
public function getWatermarkFilePath ( ) { $ filePath = false ; if ( ! ( $ file = $ this -> getWatermarkFile ( ) ) ) { return $ filePath ; } $ baseDir = $ this -> uploader -> getBasePath ( ) ; $ candidates = [ $ baseDir . '/watermark/stores/' . $ this -> storeManager -> getStore ( ) -> getId ( ) . $ file , $ baseDir . ...
Get relative watermark file path or false if file not found
57,329
public function setWatermarkSize ( $ size ) { if ( is_array ( $ size ) ) { $ this -> setWatermarkWidth ( $ size [ 'width' ] ) -> setWatermarkHeight ( $ size [ 'height' ] ) ; } return $ this ; }
Set watermark size
57,330
public function fileExists ( $ filename ) { if ( $ this -> mediaDirectory -> isFile ( $ filename ) ) { return true ; } else { return $ this -> coreFileStorageDatabase -> saveFileToFilesystem ( $ this -> mediaDirectory -> getAbsolutePath ( $ filename ) ) ; } }
First check this file on FS If it doesn t exist - try to download it from DB
57,331
public function getResizedImageInfo ( ) { $ fileInfo = null ; if ( $ this -> newFile === true ) { $ asset = $ this -> assetRepo -> createAsset ( "Limesharp_Stockists::images/" . $ this -> entityCode . "/placeholder/{$this->getDestinationSubdir()}.jpg" ) ; $ img = $ asset -> getSourceFile ( ) ; $ fileInfo = getimagesize...
Return resized image information
57,332
public function _initStockist ( ) { $ stockistId = $ this -> getRequest ( ) -> getParam ( 'stockist_id' ) ; $ this -> coreRegistry -> register ( RegistryConstants :: CURRENT_STOCKIST_ID , $ stockistId ) ; return $ stockistId ; }
Initialize current stockist and set it in the registry .
57,333
public function execute ( ) { $ stockistId = $ this -> _initStockist ( ) ; $ resultPage = $ this -> resultPageFactory -> create ( ) ; $ resultPage -> setActiveMenu ( 'Limesharp_Stockists::stores' ) ; $ resultPage -> getConfig ( ) -> getTitle ( ) -> prepend ( __ ( 'Stockists' ) ) ; $ resultPage -> addBreadcrumb ( __ ( '...
Edit or create stockist
57,334
public function getButtonData ( ) { $ data = [ ] ; if ( $ this -> getStockistId ( ) ) { $ data = [ 'label' => __ ( 'Delete Store' ) , 'class' => 'delete' , 'on_click' => 'deleteConfirm(\'' . __ ( 'Are you sure you want to do this?' ) . '\', \'' . $ this -> getDeleteUrl ( ) . '\')' , 'sort_order' => 20 , ] ; } return $ ...
get button data
57,335
private function getAttributeList ( ) { if ( ! $ this -> attributeList ) { $ this -> attributeList = \ Magento \ Framework \ App \ ObjectManager :: getInstance ( ) -> get ( \ Limesharp \ Stockists \ Api \ Data \ Stockist \ CustomAttributeListInterface :: class ) ; } return $ this -> attributeList ; }
Get new AttributeList dependency for application code .
57,336
public function execute ( ) { $ resultRedirect = $ this -> resultRedirectFactory -> create ( ) ; try { $ content = '' ; $ content .= '"store_id",' ; $ content .= '"name",' ; $ content .= '"address",' ; $ content .= '"city",' ; $ content .= '"country",' ; $ content .= '"postcode",' ; $ content .= '"region",' ; $ content...
Export data grid to CSV format
57,337
public function moveFileFromTmp ( $ name ) { $ baseTmpPath = $ this -> getBaseTmpPath ( ) ; $ basePath = $ this -> getBasePath ( ) ; $ baseFilePath = $ this -> getFilePath ( $ basePath , $ name ) ; $ baseTmpFilePath = $ this -> getFilePath ( $ baseTmpPath , $ name ) ; try { $ this -> coreFileStorageDatabase -> copyFile...
Checking file for moving and move it
57,338
public function saveFileToTmpDir ( $ fileId ) { $ baseTmpPath = $ this -> getBaseTmpPath ( ) ; $ uploader = $ this -> uploaderFactory -> create ( [ 'fileId' => $ fileId ] ) ; $ uploader -> setAllowedExtensions ( $ this -> getAllowedExtensions ( ) ) ; $ uploader -> setAllowRenameFiles ( true ) ; $ uploader -> setFilesDi...
Checking file for save and save it to tmp dir
57,339
public function getStockistId ( ) { try { return $ this -> stockistRepository -> getById ( $ this -> context -> getRequest ( ) -> getParam ( 'stockist_id' ) ) -> getId ( ) ; } catch ( NoSuchEntityException $ e ) { return null ; } }
Return Stockist page ID
57,340
public function save ( StockistInterface $ stockist ) { if ( $ stockist -> getStoreId ( ) == "" ) { $ storeId = $ this -> storeManager -> getStore ( ) -> getId ( ) ; $ stockist -> setStoreId ( $ storeId ) ; } try { $ this -> resource -> save ( $ stockist ) ; } catch ( \ Exception $ exception ) { throw new CouldNotSaveE...
Save page .
57,341
public function getById ( $ stockistId ) { if ( ! isset ( $ this -> instances [ $ stockistId ] ) ) { $ stockist = $ this -> stockistInterfaceFactory -> create ( ) ; $ this -> resource -> load ( $ stockist , $ stockistId ) ; if ( ! $ stockist -> getId ( ) ) { throw new NoSuchEntityException ( __ ( 'Requested stockist do...
Retrieve Stockist .
57,342
public function getList ( SearchCriteriaInterface $ searchCriteria ) { $ searchResults = $ this -> searchResultsFactory -> create ( ) ; $ searchResults -> setSearchCriteria ( $ searchCriteria ) ; $ collection = $ this -> stockistCollectionFactory -> create ( ) ; foreach ( $ searchCriteria -> getFilterGroups ( ) as $ gr...
Retrieve pages matching the specified criteria .
57,343
public function delete ( StockistInterface $ stockist ) { $ id = $ stockist -> getId ( ) ; try { unset ( $ this -> instances [ $ id ] ) ; $ this -> resource -> delete ( $ stockist ) ; } catch ( ValidatorException $ e ) { throw new CouldNotSaveException ( __ ( $ e -> getMessage ( ) ) ) ; } catch ( \ Exception $ e ) { th...
Delete stockist .
57,344
public function addFilterGroupToCollection ( FilterGroup $ filterGroup , Collection $ collection ) { $ fields = [ ] ; $ conditions = [ ] ; foreach ( $ filterGroup -> getFilters ( ) as $ filter ) { $ condition = $ filter -> getConditionType ( ) ? $ filter -> getConditionType ( ) : 'eq' ; $ fields [ ] = $ filter -> getFi...
Helper function that adds a FilterGroup to the collection .
57,345
public function load ( $ resource , $ type = null ) : void { $ path = $ this -> locator -> locate ( $ resource ) ; $ content = $ this -> loadFile ( $ path ) ; $ this -> container -> fileExists ( $ path ) ; if ( $ content === null ) { return ; } $ this -> privatesCaller -> callPrivateMethod ( $ this , 'parseImports' , $...
Same as parent just merging parameters instead overriding them
57,346
private function getUniqueKernelKey ( ) : string { if ( $ this -> undescoredKernelName !== null ) { return $ this -> undescoredKernelName ; } $ classParts = explode ( '\\' , self :: class ) ; $ bareClassName = array_pop ( $ classParts ) ; $ bareClassNameWithoutSuffix = Strings :: substring ( $ bareClassName , 0 , - str...
E . g . TokenRunnerKernel = > token_runner
57,347
private function cleanExtraCommandArgument ( Command $ command ) : void { $ arguments = $ command -> getDefinition ( ) -> getArguments ( ) ; if ( ! isset ( $ arguments [ 'command' ] ) ) { return ; } unset ( $ arguments [ 'command' ] ) ; $ command -> getDefinition ( ) -> setArguments ( $ arguments ) ; }
Sometimes there is command argument not really needed on fail of missing argument
57,348
private function filterOutAbstractDefinitions ( array $ definitions ) : array { foreach ( $ definitions as $ key => $ definition ) { if ( $ definition -> isAbstract ( ) ) { unset ( $ definitions [ $ key ] ) ; } } return $ definitions ; }
Abstract definitions cannot be the target of references
57,349
static public function shouldColorize ( $ colored = null ) { return self :: $ _enabled === true || ( self :: $ _enabled !== false && ( $ colored === true || ( $ colored !== false && Streams :: isTty ( ) ) ) ) ; }
Check if we should colorize output based on local flags and shell type .
57,350
static public function color ( $ color ) { if ( ! is_array ( $ color ) ) { $ color = compact ( 'color' ) ; } $ color += array ( 'color' => null , 'style' => null , 'background' => null ) ; if ( $ color [ 'color' ] == 'reset' ) { return "\033[0m" ; } $ colors = array ( ) ; foreach ( array ( 'color' , 'style' , 'backgrou...
Set the color .
57,351
static public function cacheString ( $ passed , $ colorized , $ deprecated = null ) { self :: $ _string_cache [ md5 ( $ passed ) ] = array ( 'passed' => $ passed , 'colorized' => $ colorized , 'decolorized' => self :: decolorize ( $ passed ) , ) ; }
Cache the original colorized and decolorized versions of a string .
57,352
static public function pad ( $ string , $ length , $ pre_colorized = false , $ encoding = false , $ pad_type = STR_PAD_RIGHT ) { $ real_length = self :: width ( $ string , $ pre_colorized , $ encoding ) ; $ diff = strlen ( $ string ) - $ real_length ; $ length += $ diff ; return str_pad ( $ string , $ length , ' ' , $ ...
Pad the string to a certain display length .
57,353
public function display ( $ finish = false ) { $ msg = $ this -> _message ; $ idx = $ this -> _iteration ++ % strlen ( $ this -> _chars ) ; $ char = $ this -> _chars [ $ idx ] ; $ speed = number_format ( round ( $ this -> speed ( ) ) ) ; $ elapsed = $ this -> formatTime ( $ this -> elapsed ( ) ) ; Streams :: out_padded...
Prints the current spinner position to STDOUT with the time elapsed and tick speed .
57,354
public function estimated ( ) { $ speed = $ this -> speed ( ) ; if ( ! $ speed || ! $ this -> elapsed ( ) ) { return 0 ; } $ estimated = round ( $ this -> _total / $ speed ) ; return $ estimated ; }
Calculates the estimated total time for the tick count to reach the total ticks given .
57,355
public function increment ( $ increment = 1 ) { $ this -> _current = min ( $ this -> _total , $ this -> _current + $ increment ) ; }
Increments are tick counter by the given amount . If no amount is provided the ticker is incremented by 1 .
57,356
public function exploded ( ) { $ exploded = array ( ) ; for ( $ i = strlen ( $ this -> _argument ) ; $ i > 0 ; $ i -- ) { array_push ( $ exploded , $ this -> _argument [ $ i - 1 ] ) ; } $ this -> _argument = array_pop ( $ exploded ) ; $ this -> _raw = '-' . $ this -> _argument ; return $ exploded ; }
Returns all but the first character of the argument removing them from the objects representation at the same time .
57,357
protected function checkRow ( array $ row ) { foreach ( $ row as $ column => $ str ) { $ width = Colors :: width ( $ str , $ this -> isAsciiPreColorized ( $ column ) ) ; if ( ! isset ( $ this -> _width [ $ column ] ) || $ width > $ this -> _width [ $ column ] ) { $ this -> _width [ $ column ] = $ width ; } } return $ r...
Loops through the row and sets the maximum width for each column .
57,358
public function getDisplayLines ( ) { $ this -> _renderer -> setWidths ( $ this -> _width , $ fallback = true ) ; $ border = $ this -> _renderer -> border ( ) ; $ out = array ( ) ; if ( isset ( $ border ) ) { $ out [ ] = $ border ; } $ out [ ] = $ this -> _renderer -> row ( $ this -> _headers ) ; if ( isset ( $ border ...
Get the table lines to output .
57,359
private function isAsciiPreColorized ( $ column ) { if ( $ this -> _renderer instanceof Ascii ) { return $ this -> _renderer -> isPreColorized ( $ column ) ; } return false ; }
Is a column in an Ascii table pre - colorized?
57,360
public function rewind ( ) { $ this -> _shift ( ) ; if ( $ this -> _first ) { $ this -> _index = 0 ; $ this -> _first = false ; } }
Move forward 1 element and if the method hasn t been called before reset the cursor s position to 0 .
57,361
public function render ( array $ tree , $ level = 0 ) { $ output = '' ; foreach ( $ tree as $ label => $ next ) { if ( is_string ( $ next ) ) { $ label = $ next ; } $ output .= sprintf ( "%s- %s\n" , str_repeat ( ' ' , $ level * $ this -> _padding ) , $ label ) ; if ( is_array ( $ next ) ) { $ output .= $ this -> rende...
Renders the tree
57,362
public function border ( ) { if ( ! isset ( $ this -> _border ) ) { $ this -> _border = $ this -> _characters [ 'corner' ] ; foreach ( $ this -> _widths as $ width ) { $ this -> _border .= str_repeat ( $ this -> _characters [ 'line' ] , $ width + 2 ) ; $ this -> _border .= $ this -> _characters [ 'corner' ] ; } } retur...
Render a border for the top and bottom and separating the headers from the table rows .
57,363
public function isPreColorized ( $ column ) { if ( is_bool ( $ this -> _pre_colorized ) ) { return $ this -> _pre_colorized ; } if ( is_array ( $ this -> _pre_colorized ) && isset ( $ this -> _pre_colorized [ $ column ] ) ) { return $ this -> _pre_colorized [ $ column ] ; } return false ; }
Is a column pre - colorized?
57,364
public function display ( $ finish = false ) { $ _percent = $ this -> percent ( ) ; $ percent = str_pad ( floor ( $ _percent * 100 ) , 3 ) ; $ msg = $ this -> _message ; $ msg = Streams :: render ( $ this -> _formatMessage , compact ( 'msg' , 'percent' ) ) ; $ estimated = $ this -> formatTime ( $ this -> estimated ( ) ...
Prints the progress bar to the screen with percent complete elapsed time and estimated total time .
57,365
public function tick ( $ increment = 1 , $ msg = null ) { if ( $ msg ) { $ this -> _message = $ msg ; } Notify :: tick ( $ increment ) ; }
This method augments the base definition from cli \ Notify to optionally allow passing a new message .
57,366
static public function columns ( ) { static $ columns ; if ( getenv ( 'PHP_CLI_TOOLS_TEST_SHELL_COLUMNS_RESET' ) ) { $ columns = null ; } if ( null === $ columns ) { if ( function_exists ( 'exec' ) ) { if ( self :: is_windows ( ) ) { if ( ( $ shell = getenv ( 'SHELL' ) ) && preg_match ( '/(?:bash|zsh)(?:\.exe)?$/' , $ ...
Returns the number of columns the current shell has for display .
57,367
public function reset ( ) { $ this -> _current = 0 ; $ this -> _first = true ; $ this -> _start = null ; $ this -> _timer = null ; }
Reset the notifier state so the same instance can be used in multiple loops .
57,368
public function shouldUpdate ( ) { $ now = microtime ( true ) * 1000 ; if ( empty ( $ this -> _timer ) ) { $ this -> _start = ( int ) ( ( $ this -> _timer = $ now ) / 1000 ) ; return true ; } if ( ( $ now - $ this -> _timer ) > $ this -> _interval ) { $ this -> _timer = $ now ; return true ; } return false ; }
Determines whether the display should be updated or not according to our interval setting .
57,369
public function tick ( $ increment = 1 ) { $ this -> increment ( $ increment ) ; if ( $ this -> shouldUpdate ( ) ) { Streams :: out ( "\r" ) ; $ this -> display ( ) ; } }
This method is the meat of all Notifiers . First we increment the ticker and then update the display if enough time has passed since our last tick .
57,370
public function display ( $ finish = false ) { $ repeat = $ this -> _dots ; if ( ! $ finish ) { $ repeat = $ this -> _iteration ++ % $ repeat ; } $ msg = $ this -> _message ; $ dots = str_pad ( str_repeat ( '.' , $ repeat ) , $ this -> _dots ) ; $ speed = number_format ( round ( $ this -> speed ( ) ) ) ; $ elapsed = $ ...
Prints the correct number of dots to STDOUT with the time elapsed and tick speed .
57,371
public static function err ( $ msg = '' ) { $ args = array_merge ( func_get_args ( ) , array ( '' ) ) ; $ args [ 0 ] .= "\n" ; fwrite ( static :: $ err , self :: _call ( 'render' , $ args ) ) ; }
Shortcut for printing to STDERR . The message and parameters are passed through sprintf before output .
57,372
public static function prompt ( $ question , $ default = null , $ marker = ': ' , $ hide = false ) { if ( $ default && strpos ( $ question , '[' ) === false ) { $ question .= ' [' . $ default . ']' ; } while ( true ) { self :: out ( $ question . $ marker ) ; $ line = self :: input ( null , $ hide ) ; if ( trim ( $ line...
Displays an input prompt . If no default value is provided the prompt will continue displaying until input is received .
57,373
public function isStackable ( $ flag ) { $ settings = $ this -> getFlag ( $ flag ) ; return isset ( $ settings ) && ( true === $ settings [ 'stackable' ] ) ; }
Returns true if the given flag is stackable .
57,374
public function parse ( ) { $ this -> _invalid = array ( ) ; $ this -> _parsed = array ( ) ; $ this -> _lexer = new Lexer ( $ this -> _input ) ; $ this -> _applyDefaults ( ) ; foreach ( $ this -> _lexer as $ argument ) { if ( $ this -> _parseFlag ( $ argument ) ) { continue ; } if ( $ this -> _parseOption ( $ argument ...
Parses the argument list with the given options . The returned argument list will use either the first long name given or the first name in the list if a long name is not given .
57,375
private function _applyDefaults ( ) { foreach ( $ this -> _flags as $ flag => $ settings ) { $ this [ $ flag ] = $ settings [ 'default' ] ; } foreach ( $ this -> _options as $ option => $ settings ) { if ( ! empty ( $ settings [ 'default' ] ) || $ settings [ 'default' ] === 0 ) { $ this [ $ option ] = $ settings [ 'def...
This applies the default values if any of all of the flags and options so that if there is a default value it will be available .
57,376
private function do_raise_php_limits ( ) { $ php_limits = array ( 'memory_limit' => $ this -> memory_limit , 'max_execution_time' => $ this -> max_execution_time , 'pcre.backtrack_limit' => $ this -> pcre_backtrack_limit , 'pcre.recursion_limit' => $ this -> pcre_recursion_limit ) ; foreach ( $ php_limits as $ name => ...
Try to configure PHP to use at least the suggested minimum settings
57,377
public function config ( ) { $ config = config ( 'packer' ) ; if ( empty ( $ config [ 'environment' ] ) ) { $ config [ 'environment' ] = app ( ) -> environment ( ) ; } if ( empty ( $ config [ 'public_path' ] ) ) { $ config [ 'public_path' ] = public_path ( ) ; } if ( empty ( $ config [ 'asset' ] ) ) { $ config [ 'asset...
Get the base settings from config file
57,378
protected function registerNamespaces ( ) { $ themes = app ( 'caffeinated.themes' ) -> all ( ) ; foreach ( $ themes as $ theme ) { $ namespace = $ theme -> get ( 'slug' ) ; $ hint = app ( 'caffeinated.themes' ) -> path ( 'resources/views' , $ theme -> get ( 'slug' ) ) ; app ( 'view' ) -> addNamespace ( $ namespace , $ ...
Register the theme namespaces .
57,379
protected function replacePlaceholders ( $ contents , $ options ) { $ find = [ 'DummyNamespace' , 'DummyEscapedNamespace' , 'DummyName' , 'DummySlug' , 'DummyVersion' , 'DummyDescription' , 'DummyPackageName' , 'DummyAuthor' , ] ; $ replace = [ $ options [ 'namespace' ] , $ options [ 'escaped_namespace' ] , $ options [...
Replace placeholders with actual content .
57,380
public function set ( $ theme ) { list ( $ theme , $ parent ) = $ this -> resolveTheme ( $ theme ) ; if ( ! $ this -> isCurrently ( $ theme -> get ( 'slug' ) ) and ( ! is_null ( $ this -> getCurrent ( ) ) ) ) { $ this -> removeRegisteredLocation ( ) ; } $ this -> setCurrent ( $ theme -> get ( 'slug' ) ) ; $ this -> reg...
Register and set the currently active theme .
57,381
public function path ( $ file = '' , $ theme = null ) { if ( is_null ( $ theme ) ) { $ theme = $ this -> getCurrent ( ) ; } $ theme = $ this -> format ( $ theme ) ; return base_path ( "themes/{$theme}/{$file}" ) ; }
Get the path of the given theme file .
57,382
protected function symlinkPublicDirectory ( ) { if ( ! file_exists ( public_path ( 'themes/' . $ this -> getCurrent ( ) ) ) ) { if ( ! file_exists ( public_path ( 'themes' ) ) ) { app ( ) -> make ( 'files' ) -> makeDirectory ( public_path ( 'themes' ) ) ; } app ( ) -> make ( 'files' ) -> link ( $ this -> path ( 'public...
Symlink the themes public directory so its accesible by the web .
57,383
protected function registerAutoload ( $ theme ) { $ composer = require ( base_path ( 'vendor/autoload.php' ) ) ; $ class = 'Themes\\' . $ theme . '\\' ; $ path = $ this -> path ( 'src/' ) ; if ( ! array_key_exists ( $ class , $ composer -> getClassMap ( ) ) ) { $ composer -> addPsr4 ( $ class , $ path ) ; } }
Register the themes path as a PSR - 4 reference .
57,384
protected function resolveTheme ( $ theme ) { $ theme = $ this -> where ( 'slug' , $ theme ) -> first ( ) ; $ parent = null ; if ( $ theme -> has ( 'parent' ) ) { $ parent = $ this -> where ( 'slug' , $ theme -> get ( 'parent' ) ) -> first ( ) ; } return [ $ theme , $ parent ] ; }
Resolve and return the primary and parent themes .
57,385
protected function removeRegisteredLocation ( ) { $ current = $ this -> where ( 'slug' , $ this -> getCurrent ( ) ) -> first ( ) ; $ currentLocation = $ this -> path ( 'resources/views' ) ; app ( 'view.finder' ) -> removeLocation ( $ currentLocation ) ; if ( $ current -> has ( 'parent' ) ) { $ parent = $ this -> where ...
Remove the primary and parent theme from the view finder .
57,386
protected function addRegisteredLocation ( $ theme , $ parent ) { if ( ! is_null ( $ parent ) ) { $ parentLocation = $ this -> path ( 'resources/views' ) ; app ( 'view.finder' ) -> prependLocation ( $ parentLocation ) ; } $ themeLocation = $ this -> path ( 'resources/views' ) ; app ( 'view.finder' ) -> prependLocation ...
Register the primary and parent theme with the view finder .
57,387
public function save ( ) { if ( file_exists ( $ this -> getPath ( ) ) ) { $ this -> setContent ( $ this -> encode ( ) ) ; file_put_contents ( $ this -> getPath ( ) , $ this -> getContent ( ) ) ; return ; } }
Save the manifest file content .
57,388
public function removeLocation ( string $ location ) { $ key = array_search ( $ location , $ this -> paths ) ; if ( $ key ) { unset ( $ this -> paths [ $ key ] ) ; } }
Remove a location from the finder .
57,389
protected function addThemeNamespaceHints ( $ namespace ) { $ theme = Theme :: getCurrent ( ) ; $ hints = array_reverse ( $ this -> hints [ $ namespace ] ) ; $ hints [ ] = Theme :: path ( 'resources/views/vendor/' . $ namespace ) ; if ( class_exists ( \ Caffeinated \ Modules \ ModulesServiceProvider :: class ) ) { $ hi...
Add namespace hints for the currently set theme .
57,390
public function authenticate ( $ url = null , $ stateOptions = [ ] ) { $ loginURL = $ url === null ? $ this -> credentials [ 'loginURL' ] : $ url ; $ stateOptions [ 'loginUrl' ] = $ loginURL ; $ state = '&state=' . urlencode ( json_encode ( $ stateOptions ) ) ; $ parameters = $ this -> settings [ 'parameters' ] ; $ log...
Call this method to redirect user to login page and initiate the Web Server OAuth Authentication Flow .
57,391
public function callback ( ) { $ code = $ this -> input -> get ( 'code' ) ; $ stateOptions = json_decode ( urldecode ( $ this -> input -> get ( 'state' ) ) , true ) ; $ loginURL = $ stateOptions [ 'loginUrl' ] ; $ this -> stateRepo -> put ( $ stateOptions ) ; $ tokenURL = $ loginURL . '/services/oauth2/token' ; $ jsonR...
When settings up your callback route you will need to call this method to acquire an authorization token . This token will be used for the API requests .
57,392
public function refresh ( ) { $ refreshToken = $ this -> refreshTokenRepo -> get ( ) ; $ tokenURL = $ this -> getLoginURL ( ) ; $ tokenURL .= '/services/oauth2/token' ; $ response = $ this -> httpClient -> request ( 'post' , $ tokenURL , [ 'form_params' => [ 'refresh_token' => $ refreshToken , 'grant_type' => 'refresh_...
Refresh authentication token .
57,393
public function refresh ( ) { $ tokenURL = $ this -> credentials [ 'loginURL' ] . '/services/oauth2/token' ; $ authToken = $ this -> getAuthToken ( $ tokenURL ) ; $ this -> tokenRepo -> put ( $ authToken ) ; }
Refresh authentication token by re - authenticating .
57,394
public function getTokenData ( ) { if ( ! $ this -> has ( 'token' ) ) { throw new MissingTokenException ( sprintf ( 'No token available in \'' . Config :: get ( 'forrest.storage.type' ) . '\' storage' ) ) ; } $ token = $ this -> get ( 'token' ) ; return Crypt :: decrypt ( $ token ) ; }
Get token from the session and decrypt it .
57,395
public function request ( $ url , $ options ) { $ this -> url = $ url ; $ this -> options = array_replace_recursive ( $ this -> settings [ 'defaults' ] , $ options ) ; try { return $ this -> handleRequest ( ) ; } catch ( TokenExpiredException $ e ) { $ this -> refresh ( ) ; return $ this -> handleRequest ( ) ; } }
Try requesting token if token expired try refreshing token .
57,396
private function sendRequest ( $ path , $ requestBody , $ options , $ method ) { $ url = $ this -> instanceURLRepo -> get ( ) ; $ url .= '/' . trim ( $ path , "/\t\n\r\0\x0B" ) ; $ options [ 'method' ] = $ method ; if ( ! empty ( $ requestBody ) ) { $ options [ 'body' ] = $ requestBody ; } return $ this -> request ( $ ...
Prepares options and sends the request .
57,397
public function identity ( $ options = [ ] ) { $ token = $ this -> tokenRepo -> get ( ) ; $ accessToken = $ token [ 'access_token' ] ; $ url = $ token [ 'id' ] ; $ options [ 'headers' ] [ 'Authorization' ] = "OAuth $accessToken" ; $ identity = $ this -> request ( $ url , $ options ) ; return $ identity ; }
Returns information about the logged - in user .
57,398
public function limits ( $ options = [ ] ) { $ url = $ this -> getBaseUrl ( ) ; $ url .= '/limits' ; $ limits = $ this -> request ( $ url , $ options ) ; return $ limits ; }
Lists information about organizational limits . Available for API version 29 . 0 and later . Returns limits for daily API calls Data storage etc .
57,399
public function describe ( $ object_name = null , $ options = [ ] ) { $ url = sprintf ( '%s/sobjects' , $ this -> getBaseUrl ( ) ) ; if ( ! empty ( $ object_name ) ) { $ url .= sprintf ( '/%s/describe' , $ object_name ) ; } return $ this -> request ( $ url , $ options ) ; }
Describes all global objects available in the organization .