idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
9,700
public function search ( $ params , $ class , $ usernameField ) { $ query = $ class :: find ( ) ; $ dataProvider = new ActiveDataProvider ( [ 'query' => $ query , ] ) ; if ( ! ( $ this -> load ( $ params ) && $ this -> validate ( ) ) ) { return $ dataProvider ; } $ query -> andFilterWhere ( [ 'like' , $ usernameField , $ this -> username ] ) ; return $ dataProvider ; }
Create data provider for Assignment model .
9,701
function fields ( ) : array { $ this -> checkFormIsBuilt ( ) ; return collect ( $ this -> fields ) -> map ( function ( $ field ) { return $ field -> toArray ( ) ; } ) -> keyBy ( "key" ) -> all ( ) ; }
Get the SharpFormField array representation .
9,702
function findFieldByKey ( string $ key ) { $ this -> checkFormIsBuilt ( ) ; $ fields = collect ( $ this -> fields ) ; if ( strpos ( $ key , "." ) !== false ) { list ( $ key , $ itemKey ) = explode ( "." , $ key ) ; $ listField = $ fields -> where ( "key" , $ key ) -> first ( ) ; return $ listField -> findItemFormFieldByKey ( $ itemKey ) ; } return $ fields -> where ( "key" , $ key ) -> first ( ) ; }
Find a field by its key .
9,703
protected function getFormListFieldsConfiguration ( ) { return collect ( $ this -> fields ) -> filter ( function ( $ field ) { return $ field instanceof SharpFormListField && $ field -> isSortable ( ) ; } ) -> map ( function ( $ listField ) { return [ "key" => $ listField -> key ( ) , "orderAttribute" => $ listField -> orderAttribute ( ) ] ; } ) -> keyBy ( "key" ) ; }
Get all List fields which are sortable and their orderAttribute configuration to be used by EloquentModelUpdater for automatic ordering .
9,704
public function update ( $ entityKey ) { sharp_check_ability ( "update" , $ entityKey ) ; $ list = $ this -> getListInstance ( $ entityKey ) ; $ list -> buildListConfig ( ) ; $ list -> reorderHandler ( ) -> reorder ( request ( "instances" ) ) ; return response ( ) -> json ( [ "ok" => true ] ) ; }
Call for reorder instances .
9,705
protected function parseClassname ( $ class , $ additionalNamespace = null ) { if ( preg_match ( '([^A-Za-z0-9_/\\\\])' , $ class ) ) { throw new InvalidArgumentException ( 'Class name contains invalid characters.' ) ; } $ class = trim ( str_replace ( '/' , '\\' , $ class ) , '\\' ) ; if ( ! Str :: startsWith ( $ class , $ rootNamespace = $ this -> laravel -> getNamespace ( ) ) ) { $ namespace = $ rootNamespace . ( $ additionalNamespace ? trim ( str_replace ( '/' , '\\' , $ additionalNamespace ) , '\\' ) . '\\' : '' ) ; $ class = $ namespace . $ class ; } return $ class ; }
Get the fully - qualified class name .
9,706
public function compose ( View $ view ) { $ strategy = $ this -> getValidatedStrategyFromConfig ( ) ; $ output = [ ] ; foreach ( ( array ) config ( "sharp.extensions.assets" ) as $ position => $ paths ) { foreach ( ( array ) $ paths as $ assetPath ) { if ( ! isset ( $ output [ $ position ] ) ) { $ output [ $ position ] = [ ] ; } if ( ends_with ( $ assetPath , $ this -> assetTypes ) ) { $ template = array_get ( $ this -> renderTemplates , $ this -> getAssetFileType ( $ assetPath ) ) ; $ resolvedAssetPath = $ this -> getAssetPathWithStrategyApplied ( $ strategy , $ assetPath ) ; $ output [ $ position ] [ ] = sprintf ( $ template , $ resolvedAssetPath ) ; } } } $ toBind = [ ] ; foreach ( ( array ) $ output as $ position => $ toOutput ) { $ toBind [ $ position ] = implode ( '' , $ toOutput ) ; } $ view -> with ( 'injectedAssets' , $ toBind ) ; }
Bind data to the view
9,707
protected function getValidatedStrategyFromConfig ( ) : string { $ strategy = config ( 'sharp.extensions.assets.strategy' , 'raw' ) ; if ( ! is_string ( $ strategy ) ) { throw new SharpInvalidAssetRenderStrategy ( 'The asset strategy defined at sharp.extensions.assets.strategy is not a string' ) ; } if ( ! in_array ( $ strategy , $ this -> renderStrategies ) ) { throw new SharpInvalidAssetRenderStrategy ( "The asset strategy [$strategy] is not raw, asset, or mix" ) ; } return $ strategy ; }
Get the strategy to render the assets
9,708
protected function validate ( array $ properties ) { $ validator = Validator :: make ( $ properties , [ 'key' => 'required' , 'type' => 'required' , ] + $ this -> validationRules ( ) ) ; if ( $ validator -> fails ( ) ) { throw new SharpWidgetValidationException ( $ validator -> errors ( ) ) ; } }
Throw an exception in case of invalid attribute value .
9,709
function formLayout ( ) : array { if ( ! $ this -> layoutBuilt ) { $ this -> buildFormLayout ( ) ; $ this -> layoutBuilt = true ; } return [ "tabbed" => $ this -> tabbed , "tabs" => collect ( $ this -> tabs ) -> map ( function ( $ tab ) { return $ tab -> toArray ( ) ; } ) -> all ( ) ] ; }
Return the form fields layout .
9,710
function instance ( $ id ) : array { return collect ( $ this -> find ( $ id ) ) -> only ( $ this -> getDataKeys ( ) ) -> all ( ) ; }
Return the entity instance as an array .
9,711
public function newInstance ( ) { $ data = collect ( $ this -> create ( ) ) -> only ( $ this -> getDataKeys ( ) ) -> all ( ) ; return sizeof ( $ data ) ? $ data : null ; }
Return a new entity instance as an array .
9,712
public function create ( ) : array { $ attributes = collect ( $ this -> getDataKeys ( ) ) -> flip ( ) -> map ( function ( ) { return null ; } ) -> all ( ) ; return $ this -> transform ( new class ( $ attributes ) extends \ stdClass { public function __construct ( $ attributes ) { $ this -> attributes = $ attributes ; foreach ( $ attributes as $ name => $ value ) { $ this -> $ name = $ value ; } } public function toArray ( ) { return $ this -> attributes ; } } ) ; }
Pack new Model data as JSON .
9,713
function dataContainers ( ) : array { $ this -> checkListIsBuilt ( ) ; return collect ( $ this -> containers ) -> map ( function ( EntityListDataContainer $ container ) { return $ container -> toArray ( ) ; } ) -> keyBy ( "key" ) -> all ( ) ; }
Get the SharpListDataContainer array representation .
9,714
function listLayout ( ) : array { if ( ! $ this -> layoutBuilt ) { $ this -> buildListLayout ( ) ; $ this -> layoutBuilt = true ; } return collect ( $ this -> columns ) -> map ( function ( EntityListLayoutColumn $ column ) { return $ column -> toArray ( ) ; } ) -> all ( ) ; }
Return the list fields layout .
9,715
function listConfig ( ) : array { $ config = [ "instanceIdAttribute" => $ this -> instanceIdAttribute , "multiformAttribute" => $ this -> multiformAttribute , "displayMode" => $ this -> displayMode , "searchable" => $ this -> searchable , "paginated" => $ this -> paginated , "reorderable" => ! is_null ( $ this -> reorderHandler ) , "defaultSort" => $ this -> defaultSort , "defaultSortDir" => $ this -> defaultSortDir , ] ; $ this -> appendFiltersToConfig ( $ config ) ; $ this -> appendEntityStateToConfig ( $ config ) ; $ this -> appendCommandsToConfig ( $ config ) ; return $ config ; }
Return the data config values .
9,716
protected function addDataContainer ( EntityListDataContainer $ container ) { $ this -> containers [ ] = $ container ; $ this -> listBuilt = false ; return $ this ; }
Add a data container .
9,717
function transform ( $ models ) { if ( $ this instanceof SharpForm || $ this instanceof Command ) { return $ this -> applyFormatters ( $ this -> applyTransformers ( $ models ) ) ; } if ( $ models instanceof LengthAwarePaginatorContract ) { return new LengthAwarePaginator ( $ this -> transform ( $ models -> items ( ) ) , $ models -> total ( ) , $ models -> perPage ( ) , $ models -> currentPage ( ) ) ; } return collect ( $ models ) -> map ( function ( $ model ) { return $ this -> applyTransformers ( $ model ) ; } ) -> all ( ) ; }
Transforms a model or a models collection into an array .
9,718
public function compose ( View $ view ) { $ menuItems = new Collection ; foreach ( config ( "sharp.menu" , [ ] ) as $ menuItemConfig ) { if ( $ menuItem = MenuItem :: parse ( $ menuItemConfig ) ) { $ menuItems -> push ( $ menuItem ) ; } } $ view -> with ( 'sharpMenu' , ( object ) [ "name" => config ( "sharp.name" , "Sharp" ) , "user" => sharp_user ( ) -> { config ( "sharp.auth.display_attribute" , "name" ) } , "menuItems" => $ menuItems , "currentEntity" => isset ( $ view -> entityKey ) ? explode ( ':' , $ view -> entityKey ) [ 0 ] : ( $ view -> dashboardKey ?? null ) ] ) ; $ view -> with ( 'hasGlobalFilters' , sizeof ( config ( 'sharp.global_filters' ) ?? [ ] ) > 0 ) ; }
Build the menu and bind it to the view .
9,719
public function validate ( array $ params , array $ rules , array $ messages = [ ] ) { $ validator = app ( Validator :: class ) -> make ( $ params , $ rules , $ messages ) ; if ( $ validator -> fails ( ) ) { throw new ValidationException ( $ validator , new JsonResponse ( $ validator -> errors ( ) -> getMessages ( ) , 422 ) ) ; } }
Validates the request in a form case .
9,720
protected function appendCommandsToConfig ( array & $ config ) { collect ( $ this -> entityCommandHandlers ) -> merge ( collect ( $ this -> instanceCommandHandlers ) ) -> each ( function ( $ handler , $ commandName ) use ( & $ config ) { $ formFields = $ handler -> form ( ) ; $ formLayout = $ formFields ? $ handler -> formLayout ( ) : null ; $ hasFormInitialData = $ formFields ? is_method_implemented_in_concrete_class ( $ handler , 'initialData' ) : false ; $ config [ "commands" ] [ $ handler -> type ( ) ] [ $ handler -> groupIndex ( ) ] [ ] = [ "key" => $ commandName , "label" => $ handler -> label ( ) , "description" => $ handler -> description ( ) , "type" => $ handler -> type ( ) , "confirmation" => $ handler -> confirmationText ( ) ? : null , "form" => $ formFields ? [ "fields" => $ formFields , "layout" => $ formLayout ] : null , "fetch_initial_data" => $ hasFormInitialData , "authorization" => $ handler -> getGlobalAuthorization ( ) ] ; } ) ; }
Append the commands to the config returned to the front .
9,721
protected function addWidget ( SharpWidget $ widget ) { $ this -> widgets [ ] = $ widget ; $ this -> dashboardBuilt = false ; return $ this ; }
Add a widget .
9,722
protected function addFullWidthWidget ( string $ widgetKey ) { $ this -> layoutBuilt = false ; $ this -> addRow ( function ( DashboardLayoutRow $ row ) use ( $ widgetKey ) { $ row -> addWidget ( 12 , $ widgetKey ) ; } ) ; return $ this ; }
Add a new row with a single widget .
9,723
protected function addRow ( \ Closure $ callback ) { $ row = new DashboardLayoutRow ( ) ; $ callback ( $ row ) ; $ this -> rows [ ] = $ row ; return $ this ; }
Add a new row .
9,724
function widgetsLayout ( ) : array { if ( ! $ this -> layoutBuilt ) { $ this -> buildWidgetsLayout ( ) ; $ this -> layoutBuilt = true ; } return [ "rows" => collect ( $ this -> rows ) -> map ( function ( DashboardLayoutRow $ row ) { return $ row -> toArray ( ) ; } ) -> all ( ) ] ; }
Return the dashboard widgets layout .
9,725
protected function process_response ( $ response_json ) { $ response = json_decode ( $ response_json ) ; $ this -> catch_json_last_error ( ) ; $ this -> last_results_raw = $ response ; if ( isset ( $ response -> meta -> rc ) ) { if ( $ response -> meta -> rc === 'ok' ) { $ this -> last_error_message = null ; if ( is_array ( $ response -> data ) ) { return $ response -> data ; } return true ; } elseif ( $ response -> meta -> rc === 'error' ) { if ( isset ( $ response -> meta -> msg ) ) { $ this -> last_error_message = $ response -> meta -> msg ; } if ( $ this -> debug ) { trigger_error ( 'Debug: Last error message: ' . $ this -> last_error_message ) ; } } } return false ; }
Process regular responses where output is the content of the data array
9,726
private function check_base_url ( ) { $ url_valid = filter_var ( $ this -> baseurl , FILTER_VALIDATE_URL ) ; if ( ! $ url_valid ) { trigger_error ( 'The URL provided is incomplete or invalid!' ) ; return false ; } $ base_url_components = parse_url ( $ this -> baseurl ) ; if ( empty ( $ base_url_components [ 'port' ] ) ) { trigger_error ( 'The URL provided does not have a port suffix, normally this is :8443' ) ; return false ; } return true ; }
Check the submitted base URL
9,727
protected function get_curl_obj ( ) { $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_POST , true ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , $ this -> curl_ssl_verify_peer ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYHOST , $ this -> curl_ssl_verify_host ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_CONNECTTIMEOUT , $ this -> connect_timeout ) ; if ( $ this -> debug ) { curl_setopt ( $ ch , CURLOPT_VERBOSE , true ) ; } if ( $ this -> cookies != '' ) { curl_setopt ( $ ch , CURLOPT_COOKIESESSION , true ) ; curl_setopt ( $ ch , CURLOPT_COOKIE , $ this -> cookies ) ; } return $ ch ; }
Get the cURL object
9,728
protected function parseName ( $ name = null ) { if ( ! $ name ) { $ name = $ this -> name ; } return [ '{{pluralCamel}}' => str_plural ( camel_case ( $ name ) ) , '{{pluralSlug}}' => str_plural ( str_slug ( $ name ) ) , '{{pluralSnake}}' => str_plural ( snake_case ( $ name ) ) , '{{pluralClass}}' => str_plural ( studly_case ( $ name ) ) , '{{singularCamel}}' => str_singular ( camel_case ( $ name ) ) , '{{singularSlug}}' => str_singular ( str_slug ( $ name ) ) , '{{singularSnake}}' => str_singular ( snake_case ( $ name ) ) , '{{singularClass}}' => str_singular ( studly_case ( $ name ) ) , '{{namespace}}' => $ this -> getNamespace ( ) , ] ; }
Parse guard name Get the guard name in different cases .
9,729
public function setCacheDir ( $ cacheDir ) { if ( $ cacheDir !== null ) { if ( ! is_dir ( $ cacheDir ) ) { throw new Exception \ InvalidArgumentException ( "Cache directory '{$cacheDir}' not found or not a directory" ) ; } elseif ( ! is_writable ( $ cacheDir ) ) { throw new Exception \ InvalidArgumentException ( "Cache directory '{$cacheDir}' not writable" ) ; } elseif ( ! is_readable ( $ cacheDir ) ) { throw new Exception \ InvalidArgumentException ( "Cache directory '{$cacheDir}' not readable" ) ; } $ cacheDir = rtrim ( realpath ( $ cacheDir ) , DIRECTORY_SEPARATOR ) ; } else { $ cacheDir = sys_get_temp_dir ( ) ; } $ this -> cacheDir = $ cacheDir ; return $ this ; }
Set cache dir
9,730
public function setDirLevel ( $ dirLevel ) { $ dirLevel = ( int ) $ dirLevel ; if ( $ dirLevel < 0 || $ dirLevel > 16 ) { throw new Exception \ InvalidArgumentException ( "Directory level '{$dirLevel}' must be between 0 and 16" ) ; } $ this -> dirLevel = $ dirLevel ; return $ this ; }
Set dir level
9,731
public function setDirPermission ( $ dirPermission ) { if ( $ dirPermission !== false ) { if ( is_string ( $ dirPermission ) ) { $ dirPermission = octdec ( $ dirPermission ) ; } else { $ dirPermission = ( int ) $ dirPermission ; } if ( ( $ dirPermission & 0700 ) != 0700 ) { throw new Exception \ InvalidArgumentException ( 'Invalid directory permission: need permission to execute, read and write by owner' ) ; } } if ( $ this -> dirPermission !== $ dirPermission ) { $ this -> dirPermission = $ dirPermission ; } return $ this ; }
Set permission to create directories on unix systems
9,732
public function setFilePermission ( $ filePermission ) { if ( $ filePermission !== false ) { if ( is_string ( $ filePermission ) ) { $ filePermission = octdec ( $ filePermission ) ; } else { $ filePermission = ( int ) $ filePermission ; } if ( ( $ filePermission & 0600 ) != 0600 ) { throw new Exception \ InvalidArgumentException ( 'Invalid file permission: need permission to read and write by owner' ) ; } elseif ( $ filePermission & 0111 ) { throw new Exception \ InvalidArgumentException ( "Invalid file permission: Cache files shoudn't be executable" ) ; } } if ( $ this -> filePermission !== $ filePermission ) { $ this -> filePermission = $ filePermission ; } return $ this ; }
Set permission to create files on unix systems
9,733
public function setUmask ( $ umask ) { if ( $ umask !== false ) { if ( is_string ( $ umask ) ) { $ umask = octdec ( $ umask ) ; } else { $ umask = ( int ) $ umask ; } if ( $ umask & 0700 ) { throw new Exception \ InvalidArgumentException ( 'Invalid umask: need permission to execute, read and write by owner' ) ; } $ umask = $ umask & 0777 ; } if ( $ this -> umask !== $ umask ) { $ this -> umask = $ umask ; } return $ this ; }
Set the umask to create files and directories on unix systems
9,734
public function setKeyPattern ( $ keyPattern ) { $ keyPattern = ( string ) $ keyPattern ; if ( $ this -> keyPattern !== $ keyPattern ) { if ( $ keyPattern !== '' ) { ErrorHandler :: start ( E_WARNING ) ; $ result = preg_match ( $ keyPattern , '' ) ; $ error = ErrorHandler :: stop ( ) ; if ( $ result === false ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'Invalid pattern "%s"%s' , $ keyPattern , ( $ error ? ': ' . $ error -> getMessage ( ) : '' ) ) , 0 , $ error ) ; } } $ this -> keyPattern = $ keyPattern ; } return $ this ; }
Set key pattern
9,735
protected function normalizeTtl ( & $ ttl ) { if ( ! is_int ( $ ttl ) ) { $ ttl = ( float ) $ ttl ; if ( $ ttl === ( float ) ( int ) $ ttl ) { $ ttl = ( int ) $ ttl ; } } if ( $ ttl < 0 ) { throw new InvalidArgumentException ( "TTL can't be negative" ) ; } }
Validates and normalize a TTL .
9,736
public static function stop ( $ throw = false ) { $ errorException = null ; if ( static :: $ stack ) { $ errorException = array_pop ( static :: $ stack ) ; if ( ! static :: $ stack ) { restore_error_handler ( ) ; } if ( $ errorException && $ throw ) { throw $ errorException ; } } return $ errorException ; }
Stopping the error handler
9,737
public static function addError ( $ errno , $ errstr = '' , $ errfile = '' , $ errline = 0 ) { $ stack = & static :: $ stack [ count ( static :: $ stack ) - 1 ] ; $ stack = new ErrorException ( $ errstr , 0 , $ errno , $ errfile , $ errline , $ stack ) ; }
Add an error to the stack
9,738
protected function normalizeKey ( & $ key ) { $ key = ( string ) $ key ; if ( $ key === '' ) { throw new InvalidArgumentException ( "An empty key isn't allowed" ) ; } elseif ( ( $ p = $ this -> getOptions ( ) -> getKeyPattern ( ) ) && ! preg_match ( $ p , $ key ) ) { throw new InvalidArgumentException ( "The key '{$key}' doesn't match against pattern '{$p}'" ) ; } }
Validates and normalizes a key
9,739
function makeEncoding ( $ height = 0 , $ width = 0 , $ data = 0 , $ fw = 0 , $ bytes = 0 , $ datablocks = 0 , $ rsblocks = 0 ) { $ t = array ( 'height' => $ height , 'width' => $ width , 'data' => $ data , 'fw' => $ fw , 'bytes' => $ bytes , 'datablocks' => $ datablocks , 'rsblocks' => $ rsblocks ) ; return $ t ; }
from Semafox . Encoding
9,740
function placeBit ( & $ array , $ NR , $ NC , $ r , $ c , $ p , $ b ) { if ( $ r < 0 ) { $ r += $ NR ; $ c += 4 - ( ( $ NR + 4 ) % 8 ) ; } if ( $ c < 0 ) { $ c += $ NC ; $ r += 4 - ( ( $ NC + 4 ) % 8 ) ; } $ array [ $ r * $ NC + $ c ] = ( $ p << 3 ) + $ b ; }
Annex M placement alogorithm low level
9,741
function rs ( & $ binary , $ bytes , $ datablock , $ rsblock ) { $ blocks = floor ( ( $ bytes + 2 ) / $ datablock ) ; $ rs = new ReedSolomon ( $ rsblock ) ; for ( $ b = 0 ; $ b < $ blocks ; $ b ++ ) { $ buf = array ( ) ; $ p = 0 ; for ( $ n = $ b ; $ n < $ bytes ; $ n += $ blocks ) array_push ( $ buf , $ binary [ $ n ] ) ; $ enc = $ rs -> encodeArray ( $ buf ) ; $ p = $ rsblock - 1 ; for ( $ n = $ b ; $ n < $ rsblock * $ blocks ; $ n += $ blocks ) $ binary [ $ bytes + $ n ] = $ enc [ $ p -- ] ; } }
calculate and append ecc code and if necessary interleave
9,742
function asGDImage ( $ text , $ resize = 160 ) { $ barcode = $ this -> encode ( $ text ) ; $ w = $ barcode [ 'width' ] ; $ h = $ barcode [ 'height' ] ; $ bs = 10 ; $ size = $ bs * $ w ; $ img = imagecreatetruecolor ( $ size + 2 * $ bs * 2 , $ size + 2 * $ bs * 2 ) ; $ white = imagecolorallocate ( $ img , 255 , 255 , 255 ) ; $ black = imagecolorallocate ( $ img , 0 , 0 , 0 ) ; imagefill ( $ img , 0 , 0 , $ white ) ; for ( $ j = 0 ; $ j < $ h ; $ j ++ ) { for ( $ i = 0 ; $ i < $ w ; $ i ++ ) { $ x1 = ( $ i * $ bs ) + $ bs * 2 ; $ y1 = ( $ size - ( ( $ j + 1 ) * $ bs ) ) + $ bs * 2 ; $ x2 = $ x1 + $ bs ; $ y2 = $ y1 + $ bs ; if ( $ barcode [ 'data' ] [ $ j * $ w + $ i ] ) { imagefilledrectangle ( $ img , $ x1 , $ y1 , $ x2 , $ y2 , $ black ) ; } else { imagefilledrectangle ( $ img , $ x1 , $ y1 , $ x2 , $ y2 , $ white ) ; } } } if ( $ resize == $ size ) { return $ img ; } $ new = imagecreatetruecolor ( $ resize , $ resize ) ; imagecopyresized ( $ new , $ img , 0 , 0 , 0 , 0 , $ resize , $ resize , $ size + 2 * $ bs * 2 , $ size + 2 * $ bs * 2 ) ; imagedestroy ( $ img ) ; return $ new ; }
returns a libGD image ressource
9,743
protected function internalHasItem ( & $ normalizedKey ) { $ file = $ this -> getFileSpec ( $ normalizedKey ) . '.dat' ; if ( ! file_exists ( $ file ) ) { return false ; } $ ttl = $ this -> getOptions ( ) -> getTtl ( ) ; if ( $ ttl ) { ErrorHandler :: start ( ) ; $ mtime = filemtime ( $ file ) ; $ error = ErrorHandler :: stop ( ) ; if ( ! $ mtime ) { throw new Exception \ RuntimeException ( "Error getting mtime of file '{$file}'" , 0 , $ error ) ; } if ( time ( ) >= ( $ mtime + $ ttl ) ) { return false ; } } return true ; }
Internal method to test if an item exists .
9,744
protected function getFileSpec ( $ normalizedKey ) { $ options = $ this -> getOptions ( ) ; $ namespace = $ options -> getNamespace ( ) ; $ prefix = ( $ namespace === '' ) ? '' : $ namespace . $ options -> getNamespaceSeparator ( ) ; $ path = $ options -> getCacheDir ( ) . DIRECTORY_SEPARATOR ; $ level = $ options -> getDirLevel ( ) ; $ fileSpecId = $ path . $ prefix . $ normalizedKey . '/' . $ level ; if ( $ this -> lastFileSpecId !== $ fileSpecId ) { if ( $ level > 0 ) { $ hash = md5 ( $ normalizedKey ) ; for ( $ i = 0 , $ max = ( $ level * 2 ) ; $ i < $ max ; $ i += 2 ) { $ path .= $ prefix . $ hash [ $ i ] . $ hash [ $ i + 1 ] . DIRECTORY_SEPARATOR ; } } $ this -> lastFileSpecId = $ fileSpecId ; $ this -> lastFileSpec = $ path . $ prefix . $ normalizedKey ; } return $ this -> lastFileSpec ; }
Get file spec of the given key and namespace
9,745
protected function getFileContent ( $ file , $ nonBlocking = false , & $ wouldblock = null ) { $ locking = $ this -> getOptions ( ) -> getFileLocking ( ) ; $ wouldblock = null ; ErrorHandler :: start ( ) ; if ( $ locking ) { $ fp = fopen ( $ file , 'rb' ) ; if ( $ fp === false ) { $ err = ErrorHandler :: stop ( ) ; throw new Exception \ RuntimeException ( "Error opening file '{$file}'" , 0 , $ err ) ; } if ( $ nonBlocking ) { $ lock = flock ( $ fp , LOCK_SH | LOCK_NB , $ wouldblock ) ; if ( $ wouldblock ) { fclose ( $ fp ) ; ErrorHandler :: stop ( ) ; return ; } } else { $ lock = flock ( $ fp , LOCK_SH ) ; } if ( ! $ lock ) { fclose ( $ fp ) ; $ err = ErrorHandler :: stop ( ) ; throw new Exception \ RuntimeException ( "Error locking file '{$file}'" , 0 , $ err ) ; } $ res = stream_get_contents ( $ fp ) ; if ( $ res === false ) { flock ( $ fp , LOCK_UN ) ; fclose ( $ fp ) ; $ err = ErrorHandler :: stop ( ) ; throw new Exception \ RuntimeException ( 'Error getting stream contents' , 0 , $ err ) ; } flock ( $ fp , LOCK_UN ) ; fclose ( $ fp ) ; } else { $ res = file_get_contents ( $ file , false ) ; if ( $ res === false ) { $ err = ErrorHandler :: stop ( ) ; throw new Exception \ RuntimeException ( "Error getting file contents for file '{$file}'" , 0 , $ err ) ; } } ErrorHandler :: stop ( ) ; return $ res ; }
Read a complete file
9,746
public function index ( string $ domain , int $ limit = 100 ) { Assert :: stringNotEmpty ( $ domain ) ; Assert :: range ( $ limit , 1 , 1000 ) ; $ params = [ 'limit' => $ limit , ] ; $ response = $ this -> httpGet ( sprintf ( '/v3/%s/tags' , $ domain ) , $ params ) ; return $ this -> hydrateResponse ( $ response , IndexResponse :: class ) ; }
Returns a list of tags .
9,747
public function update ( string $ domain , string $ tag , string $ description ) { Assert :: stringNotEmpty ( $ domain ) ; Assert :: stringNotEmpty ( $ tag ) ; $ params = [ 'description' => $ description , ] ; $ response = $ this -> httpPut ( sprintf ( '/v3/%s/tags/%s' , $ domain , $ tag ) , $ params ) ; return $ this -> hydrateResponse ( $ response , UpdateResponse :: class ) ; }
Update a tag .
9,748
public function stats ( string $ domain , string $ tag , array $ params ) { Assert :: stringNotEmpty ( $ domain ) ; Assert :: stringNotEmpty ( $ tag ) ; $ response = $ this -> httpGet ( sprintf ( '/v3/%s/tags/%s/stats' , $ domain , $ tag ) , $ params ) ; return $ this -> hydrateResponse ( $ response , StatisticsResponse :: class ) ; }
Returns statistics for a single tag .
9,749
public function show ( string $ url , bool $ rawMessage = false ) { Assert :: notEmpty ( $ url ) ; $ headers = [ ] ; if ( $ rawMessage ) { $ headers [ 'Accept' ] = 'message/rfc2822' ; } $ response = $ this -> httpGet ( $ url , [ ] , $ headers ) ; return $ this -> hydrateResponse ( $ response , ShowResponse :: class ) ; }
Get stored message .
9,750
private function prepareMultipartParameters ( array $ params ) : array { $ postDataMultipart = [ ] ; foreach ( $ params as $ key => $ value ) { foreach ( ( array ) $ value as $ subValue ) { $ postDataMultipart [ ] = [ 'name' => $ key , 'content' => $ subValue , ] ; } } return $ postDataMultipart ; }
Prepare multipart parameters . Make sure each POST parameter is split into an array with name and content keys .
9,751
private function closeResources ( array $ params ) : void { foreach ( $ params as $ param ) { if ( is_array ( $ param ) && array_key_exists ( 'content' , $ param ) && is_resource ( $ param [ 'content' ] ) ) { fclose ( $ param [ 'content' ] ) ; } } }
Close open resources .
9,752
public function index ( bool $ dedicated = false ) { Assert :: boolean ( $ dedicated ) ; $ params = [ 'dedicated' => $ dedicated , ] ; $ response = $ this -> httpGet ( '/v3/ips' , $ params ) ; return $ this -> hydrateResponse ( $ response , IndexResponse :: class ) ; }
Returns a list of IPs .
9,753
public function domainIndex ( string $ domain ) { Assert :: stringNotEmpty ( $ domain ) ; $ response = $ this -> httpGet ( sprintf ( '/v3/domains/%s/ip' , $ domain ) ) ; return $ this -> hydrateResponse ( $ response , IndexResponse :: class ) ; }
Returns a list of IPs assigned to a domain .
9,754
public function show ( string $ ip ) { Assert :: ip ( $ ip ) ; $ response = $ this -> httpGet ( sprintf ( '/v3/ips/%s' , $ ip ) ) ; return $ this -> hydrateResponse ( $ response , ShowResponse :: class ) ; }
Returns a single ip .
9,755
public function assign ( string $ domain , string $ ip ) { Assert :: stringNotEmpty ( $ domain ) ; Assert :: ip ( $ ip ) ; $ params = [ 'id' => $ ip , ] ; $ response = $ this -> httpPost ( sprintf ( '/v3/domains/%s/ips' , $ domain ) , $ params ) ; return $ this -> hydrateResponse ( $ response , UpdateResponse :: class ) ; }
Assign a dedicated IP to the domain specified .
9,756
public function unassign ( string $ domain , string $ ip ) { Assert :: stringNotEmpty ( $ domain ) ; Assert :: ip ( $ ip ) ; $ response = $ this -> httpDelete ( sprintf ( '/v3/domains/%s/ips/%s' , $ domain , $ ip ) ) ; return $ this -> hydrateResponse ( $ response , UpdateResponse :: class ) ; }
Unassign an IP from the domain specified .
9,757
public function pages ( int $ limit = 100 ) { Assert :: range ( $ limit , 1 , 1000 ) ; $ params = [ 'limit' => $ limit , ] ; $ response = $ this -> httpGet ( '/v3/lists/pages' , $ params ) ; return $ this -> hydrateResponse ( $ response , PagesResponse :: class ) ; }
Returns a paginated list of mailing lists on the domain .
9,758
public function create ( string $ address , string $ name = null , string $ description = null , string $ accessLevel = 'readonly' ) { Assert :: stringNotEmpty ( $ address ) ; Assert :: nullOrStringNotEmpty ( $ name ) ; Assert :: nullOrStringNotEmpty ( $ description ) ; Assert :: oneOf ( $ accessLevel , [ 'readonly' , 'members' , 'everyone' ] ) ; $ params = [ 'address' => $ address , 'name' => $ name , 'description' => $ description , 'access_level' => $ accessLevel , ] ; $ response = $ this -> httpPost ( '/v3/lists' , $ params ) ; return $ this -> hydrateResponse ( $ response , CreateResponse :: class ) ; }
Creates a new mailing list on the current domain .
9,759
public function update ( string $ address , array $ parameters = [ ] ) { Assert :: stringNotEmpty ( $ address ) ; Assert :: isArray ( $ parameters ) ; foreach ( $ parameters as $ field => $ value ) { switch ( $ field ) { case 'address' : case 'name' : case 'description' : Assert :: stringNotEmpty ( $ value ) ; break ; case 'access_level' : Assert :: oneOf ( $ value , [ 'readonly' , 'members' , 'everyone' ] ) ; break ; } } $ response = $ this -> httpPut ( sprintf ( '/v3/lists/%s' , $ address ) , $ parameters ) ; return $ this -> hydrateResponse ( $ response , UpdateResponse :: class ) ; }
Updates a mailing list .
9,760
public function validate ( string $ address , bool $ mailboxVerification = false ) { Assert :: stringNotEmpty ( $ address ) ; $ params = [ 'address' => $ address , 'mailbox_verification' => $ mailboxVerification , ] ; $ response = $ this -> httpGet ( '/address/private/validate' , $ params ) ; return $ this -> hydrateResponse ( $ response , ValidateResponse :: class ) ; }
Addresses are validated based off defined checks .
9,761
public function index ( int $ limit = 100 , int $ skip = 0 ) { Assert :: range ( $ limit , 1 , 1000 ) ; $ params = [ 'limit' => $ limit , 'skip' => $ skip , ] ; $ response = $ this -> httpGet ( '/v3/domains' , $ params ) ; return $ this -> hydrateResponse ( $ response , IndexResponse :: class ) ; }
Returns a list of domains on the account .
9,762
public function credentials ( string $ domain , int $ limit = 100 , int $ skip = 0 ) { Assert :: stringNotEmpty ( $ domain ) ; $ params = [ 'limit' => $ limit , 'skip' => $ skip , ] ; $ response = $ this -> httpGet ( sprintf ( '/v3/domains/%s/credentials' , $ domain ) , $ params ) ; return $ this -> hydrateResponse ( $ response , CredentialResponse :: class ) ; }
Returns a list of SMTP credentials for the specified domain .
9,763
public function createCredential ( string $ domain , string $ login , string $ password ) { Assert :: stringNotEmpty ( $ domain ) ; Assert :: stringNotEmpty ( $ login ) ; Assert :: stringNotEmpty ( $ password ) ; Assert :: lengthBetween ( $ password , 5 , 32 , 'SMTP password must be between 5 and 32 characters.' ) ; $ params = [ 'login' => $ login , 'password' => $ password , ] ; $ response = $ this -> httpPost ( sprintf ( '/v3/domains/%s/credentials' , $ domain ) , $ params ) ; return $ this -> hydrateResponse ( $ response , CreateCredentialResponse :: class ) ; }
Create a new SMTP credential pair for the specified domain .
9,764
public function updateCredential ( string $ domain , string $ login , string $ pass ) { Assert :: stringNotEmpty ( $ domain ) ; Assert :: stringNotEmpty ( $ login ) ; Assert :: stringNotEmpty ( $ pass ) ; Assert :: lengthBetween ( $ pass , 5 , 32 , 'SMTP password must be between 5 and 32 characters.' ) ; $ params = [ 'password' => $ pass , ] ; $ response = $ this -> httpPut ( sprintf ( '/v3/domains/%s/credentials/%s' , $ domain , $ login ) , $ params ) ; return $ this -> hydrateResponse ( $ response , UpdateCredentialResponse :: class ) ; }
Update a set of SMTP credentials for the specified domain .
9,765
public function deleteCredential ( string $ domain , string $ login ) { Assert :: stringNotEmpty ( $ domain ) ; Assert :: stringNotEmpty ( $ login ) ; $ response = $ this -> httpDelete ( sprintf ( '/v3/domains/%s/credentials/%s' , $ domain , $ login ) ) ; return $ this -> hydrateResponse ( $ response , DeleteCredentialResponse :: class ) ; }
Remove a set of SMTP credentials from the specified domain .
9,766
public function connection ( string $ domain ) { Assert :: stringNotEmpty ( $ domain ) ; $ response = $ this -> httpGet ( sprintf ( '/v3/domains/%s/connection' , $ domain ) ) ; return $ this -> hydrateResponse ( $ response , ConnectionResponse :: class ) ; }
Returns delivery connection settings for the specified domain .
9,767
public function updateConnection ( string $ domain , ? bool $ requireTLS , ? bool $ noVerify ) { Assert :: stringNotEmpty ( $ domain ) ; $ params = [ ] ; if ( null !== $ requireTLS ) { $ params [ 'require_tls' ] = $ requireTLS ? 'true' : 'false' ; } if ( null !== $ noVerify ) { $ params [ 'skip_verification' ] = $ noVerify ? 'true' : 'false' ; } $ response = $ this -> httpPut ( sprintf ( '/v3/domains/%s/connection' , $ domain ) , $ params ) ; return $ this -> hydrateResponse ( $ response , UpdateConnectionResponse :: class ) ; }
Updates the specified delivery connection settings for the specified domain . If a parameter is passed in as null it will not be updated .
9,768
public function verify ( string $ domain ) { Assert :: stringNotEmpty ( $ domain ) ; $ response = $ this -> httpPut ( sprintf ( '/v3/domains/%s/verify' , $ domain ) ) ; return $ this -> hydrateResponse ( $ response , VerifyResponse :: class ) ; }
Returns a single domain .
9,769
public function index ( string $ address , int $ limit = 100 , bool $ subscribed = null ) { Assert :: stringNotEmpty ( $ address ) ; Assert :: greaterThan ( $ limit , 0 ) ; $ params = [ 'limit' => $ limit , ] ; if ( true === $ subscribed ) { $ params [ 'subscribed' ] = 'yes' ; } elseif ( false === $ subscribed ) { $ params [ 'subscribed' ] = 'no' ; } $ response = $ this -> httpGet ( sprintf ( '/v3/lists/%s/members/pages' , $ address ) , $ params ) ; return $ this -> hydrateResponse ( $ response , IndexResponse :: class ) ; }
Returns a paginated list of members of the mailing list .
9,770
public function show ( string $ routeId ) { Assert :: stringNotEmpty ( $ routeId ) ; $ response = $ this -> httpGet ( sprintf ( '/v3/routes/%s' , $ routeId ) ) ; return $ this -> hydrateResponse ( $ response , ShowResponse :: class ) ; }
Returns a single Route object based on its ID .
9,771
public function create ( string $ expression , array $ actions , string $ description , int $ priority = 0 ) { Assert :: isArray ( $ actions ) ; $ params = [ 'priority' => ( string ) $ priority , 'expression' => $ expression , 'action' => $ actions , 'description' => $ description , ] ; $ response = $ this -> httpPost ( '/v3/routes' , $ params ) ; return $ this -> hydrateResponse ( $ response , CreateResponse :: class ) ; }
Creates a new Route .
9,772
public function update ( string $ routeId , string $ expression = null , array $ actions = [ ] , string $ description = null , int $ priority = null ) { Assert :: stringNotEmpty ( $ routeId ) ; $ params = [ ] ; if ( ! empty ( $ expression ) ) { $ params [ 'expression' ] = trim ( $ expression ) ; } foreach ( $ actions as $ action ) { Assert :: stringNotEmpty ( $ action ) ; $ params [ 'action' ] = isset ( $ params [ 'action' ] ) ? $ params [ 'action' ] : [ ] ; $ params [ 'action' ] [ ] = $ action ; } if ( ! empty ( $ description ) ) { $ params [ 'description' ] = trim ( $ description ) ; } if ( ! empty ( $ priority ) ) { $ params [ 'priority' ] = ( string ) $ priority ; } $ response = $ this -> httpPut ( sprintf ( '/v3/routes/%s' , $ routeId ) , $ params ) ; return $ this -> hydrateResponse ( $ response , UpdateResponse :: class ) ; }
Updates a given Route by ID . All parameters are optional . This API call only updates the specified fields leaving others unchanged .
9,773
public function delete ( string $ routeId ) { Assert :: stringNotEmpty ( $ routeId ) ; $ response = $ this -> httpDelete ( sprintf ( '/v3/routes/%s' , $ routeId ) ) ; return $ this -> hydrateResponse ( $ response , DeleteResponse :: class ) ; }
Deletes a Route based on the ID .
9,774
public function verifyWebhookSignature ( int $ timestamp , string $ token , string $ signature ) : bool { if ( empty ( $ timestamp ) || empty ( $ token ) || empty ( $ signature ) ) { return false ; } $ hmac = hash_hmac ( 'sha256' , $ timestamp . $ token , $ this -> apiKey ) ; if ( function_exists ( 'hash_equals' ) ) { return hash_equals ( $ hmac , $ signature ) ; } else { return $ hmac === $ signature ; } }
This function verifies the webhook signature with your API key to to see if it is authentic .
9,775
public static function createMultiple ( array $ data ) { $ items = [ ] ; foreach ( $ data as $ action ) { $ items [ ] = new self ( $ action ) ; } return $ items ; }
Action Named Constructor to build several Action DTOs provided by an Array .
9,776
protected function handleErrors ( ResponseInterface $ response ) { $ statusCode = $ response -> getStatusCode ( ) ; switch ( $ statusCode ) { case 400 : throw HttpClientException :: badRequest ( $ response ) ; case 401 : throw HttpClientException :: unauthorized ( $ response ) ; case 402 : throw HttpClientException :: requestFailed ( $ response ) ; case 404 : throw HttpClientException :: notFound ( $ response ) ; case 413 : throw HttpClientException :: payloadTooLarge ( $ response ) ; case 500 <= $ statusCode : throw HttpServerException :: serverError ( $ statusCode ) ; default : throw new UnknownErrorException ( ) ; } }
Throw the correct exception for this error .
9,777
protected function httpPost ( string $ path , array $ parameters = [ ] , array $ requestHeaders = [ ] ) : ResponseInterface { return $ this -> httpPostRaw ( $ path , $ this -> createRequestBody ( $ parameters ) , $ requestHeaders ) ; }
Send a POST request with parameters .
9,778
protected function httpPut ( string $ path , array $ parameters = [ ] , array $ requestHeaders = [ ] ) : ResponseInterface { try { $ response = $ this -> httpClient -> sendRequest ( $ this -> requestBuilder -> create ( 'PUT' , $ path , $ requestHeaders , $ this -> createRequestBody ( $ parameters ) ) ) ; } catch ( Psr18 \ NetworkExceptionInterface $ e ) { throw HttpServerException :: networkError ( $ e ) ; } return $ response ; }
Send a PUT request .
9,779
public function getThemeByRoute ( $ path ) { $ text = new Text ( ) ; foreach ( $ this -> themePaths as $ lp => $ layout ) { if ( $ text -> fnmatch ( $ lp , $ path ) ) { return $ layout ; } } return false ; }
This grabs the theme for a particular path if one exists in the themePaths array . Returns an array with the theme handle as the first entry and the wrapper file for views as the second .
9,780
public function getAllImageFormats ( ) { if ( $ this -> allImageFormats === null ) { $ this -> allImageFormats = [ static :: FORMAT_PNG , static :: FORMAT_JPEG , static :: FORMAT_GIF , static :: FORMAT_WBMP , static :: FORMAT_XBM , ] ; } return $ this -> allImageFormats ; }
Get all the image formats .
9,781
public function getFormatMimeType ( $ format ) { $ format = $ this -> normalizeFormat ( $ format ) ; $ result = '' ; switch ( $ format ) { case static :: FORMAT_PNG : case static :: FORMAT_JPEG : case static :: FORMAT_GIF : case static :: FORMAT_XBM : $ result = 'image/' . $ format ; break ; case static :: FORMAT_WBMP : $ result = 'image/vnd.wap.wbmp' ; break ; } return $ result ; }
Get the MIME type for a specific format .
9,782
public function getFormatFromMimeType ( $ mimeType , $ fallback = '' ) { $ mimeType = trim ( strtolower ( ( string ) $ mimeType ) ) ; switch ( $ mimeType ) { case 'image/png' : $ result = static :: FORMAT_PNG ; break ; case 'image/jpeg' : $ result = static :: FORMAT_JPEG ; break ; case 'image/gif' : $ result = static :: FORMAT_GIF ; break ; case 'image/vnd.wap.wbmp' : $ result = static :: FORMAT_WBMP ; break ; case 'image/xbm' : case 'image/x-xbm' : case 'image/x-xbitmap' : $ result = static :: FORMAT_XBM ; break ; default : $ result = $ fallback ; break ; } return $ result ; }
Get the bitmap format corresponding to a specific MIME type .
9,783
public function getFormatImagineSaveOptions ( $ format ) { $ format = $ this -> normalizeFormat ( $ format ) ; $ result = [ 'format' => $ format , ] ; switch ( $ format ) { case static :: FORMAT_PNG : $ result [ 'png_compression_level' ] = $ this -> getDefaultPngCompressionLevel ( ) ; break ; case static :: FORMAT_JPEG : $ result [ 'jpeg_quality' ] = $ this -> getDefaultJpegQuality ( ) ; break ; } return $ result ; }
Get the Imagine save options for the specified image format .
9,784
public function setDefaultJpegQuality ( $ value ) { if ( $ this -> valn -> integer ( $ value , 0 , 100 ) ) { $ value = ( int ) $ value ; $ this -> config -> set ( 'concrete.misc.default_jpeg_image_compression' , $ value ) ; $ this -> config -> save ( 'concrete.misc.default_jpeg_image_compression' , $ value ) ; } return $ this ; }
Set the default JPEG quality .
9,785
public function getDefaultJpegQuality ( ) { $ result = $ this -> config -> get ( 'concrete.misc.default_jpeg_image_compression' ) ; if ( $ this -> valn -> integer ( $ result , 0 , 100 ) ) { $ result = ( int ) $ result ; } else { $ result = static :: DEFAULT_JPEG_QUALITY ; } return $ result ; }
Get the default JPEG quality .
9,786
public function getDefaultPngCompressionLevel ( ) { $ result = $ this -> config -> get ( 'concrete.misc.default_png_image_compression' ) ; if ( $ this -> valn -> integer ( $ result , 0 , 9 ) ) { $ result = ( int ) $ result ; } else { $ result = static :: DEFAULT_PNG_COMPRESSIONLEVEL ; } return $ result ; }
Get the default PNG compression level .
9,787
protected function normalizeFormat ( $ format ) { $ format = strtolower ( trim ( ( string ) $ format ) ) ; if ( $ format === 'jpg' ) { $ format = static :: FORMAT_JPEG ; } return $ format ; }
Normalize a format .
9,788
public function isMediaTypeSupported ( $ mediaType , $ minWeight = null ) { $ data = $ this -> getMediaTypeData ( $ mediaType ) ; if ( $ minWeight === null ) { return $ data !== [ ] ; } $ minWeight = ( float ) $ minWeight ; foreach ( $ data as $ item ) { if ( $ item [ 'q' ] >= $ minWeight ) { return true ; } } return false ; }
Check if the client signaled that it supports a media type .
9,789
public function getMediaTypeData ( $ mediaType ) { $ map = $ this -> getRequestAcceptMap ( ) ; list ( $ type , $ subType ) = $ this -> normalizeMediaType ( $ mediaType ) ; $ result = [ ] ; foreach ( $ this -> getMediaTypeAlternatives ( $ type , $ subType ) as $ alternative ) { if ( isset ( $ map [ $ alternative ] ) ) { $ result [ $ alternative ] = $ map [ $ alternative ] ; } } return $ result ; }
Get the data associated to a media type .
9,790
public function getRequestAcceptMap ( ) { if ( $ this -> requestAcceptMap === null ) { $ requestAccept = $ this -> getRequestAccept ( ) ; $ requestAcceptMap = $ this -> parseRequestAccept ( $ requestAccept ) ; $ requestAcceptMap = $ this -> sortRequestAcceptMap ( $ requestAcceptMap ) ; $ this -> requestAcceptMap = $ requestAcceptMap ; } return $ this -> requestAcceptMap ; }
Get the data extracted from the Accept header .
9,791
protected function getRequestAccept ( ) { $ accept = $ this -> request -> headers -> get ( 'accept' ) ; if ( ! is_string ( $ accept ) ) { return '' ; } return trim ( $ accept ) ; }
Get the Accept header of the request .
9,792
public function load ( $ url , $ cache = 3600 ) { if ( $ cache !== false ) { Reader :: setCache ( new ZendCacheDriver ( 'cache/expensive' , $ cache ) ) ; } $ feed = Reader :: import ( $ url ) ; return $ feed ; }
Loads a newsfeed object .
9,793
protected static function createRedirectResponse ( $ url , $ code , $ headers ) { $ r = new RedirectResponse ( $ url , $ code , $ headers ) ; $ r -> setRequest ( Request :: getInstance ( ) ) ; return $ r ; }
Actually sends a redirect .
9,794
public static function to ( ) { $ args = func_get_args ( ) ; if ( is_object ( $ args [ 0 ] ) && $ args [ 0 ] instanceof UrlInterface ) { $ url = $ args [ 0 ] ; } else { $ url = call_user_func_array ( '\URL::to' , func_get_args ( ) ) ; } $ r = static :: createRedirectResponse ( ( string ) $ url , 302 , array ( ) ) ; return $ r ; }
Redirects to a concrete5 resource .
9,795
public static function page ( Page $ c , $ code = 302 , $ headers = array ( ) ) { if ( $ c -> getCollectionPath ( ) ) { $ url = Core :: make ( 'helper/navigation' ) -> getLinkToCollection ( $ c , true ) ; } else { $ url = \ URL :: to ( $ c ) ; } $ r = static :: createRedirectResponse ( ( string ) $ url , $ code , $ headers ) ; return $ r ; }
Redirect to a page .
9,796
public function getTotal ( ) { if ( $ this -> total == - 1 ) { $ this -> total = count ( $ this -> items ) ; } return $ this -> total ; }
Returns the total number of items found by this list .
9,797
public function getPage ( $ page = false ) { $ this -> setCurrentPage ( $ page ) ; $ offset = 0 ; if ( $ this -> currentPage > 1 ) { $ offset = min ( $ this -> itemsPerPage * ( $ this -> currentPage - 1 ) , 2147483647 ) ; } return $ this -> get ( $ this -> itemsPerPage , $ offset ) ; }
Returns an array of object by page .
9,798
public function displaySummary ( $ right_content = '' ) { if ( $ this -> getTotal ( ) < 1 ) { return false ; } $ summary = $ this -> getSummary ( ) ; if ( $ summary -> currentEnd == - 1 ) { $ html = '<div class="ccm-paging-top">' . t ( 'Viewing <b>%s</b> to <b>%s</b> (<b>%s</b> Total)' , $ summary -> currentStart , "<span id=\"pagingPageResults\">" . $ summary -> total . "</span>" , "<span id=\"pagingTotalResults\">" . $ this -> total . "</span>" ) . ( $ right_content != '' ? '<span class="ccm-paging-top-content">' . $ right_content . '</span>' : '' ) . '</div>' ; } else { $ html = '<div class="ccm-paging-top">' . t ( 'Viewing <b>%s</b> to <b>%s</b> (<b>%s</b> Total)' , $ summary -> currentStart , "<span id=\"pagingPageResults\">" . $ summary -> currentEnd . "</span>" , "<span id=\"pagingTotalResults\">" . $ this -> total . "</span>" ) . ( $ right_content != '' ? '<span class="ccm-paging-top-content">' . $ right_content . '</span>' : '' ) . '</div>' ; } echo $ html ; }
Displays summary text about a list .
9,799
public function displayPagingV2 ( $ script = false , $ return = false , $ additionalVars = array ( ) ) { $ summary = $ this -> getSummary ( ) ; $ paginator = $ this -> getPagination ( $ script , $ additionalVars ) ; if ( $ summary -> pages > 1 ) { $ html = '' ; $ html .= '<div class="ccm-search-results-pagination"><ul class="pagination">' ; $ prevClass = 'prev' ; $ nextClass = 'next' ; if ( ! $ paginator -> hasPreviousPage ( ) ) { $ prevClass = 'prev disabled' ; } if ( ! $ paginator -> hasNextPage ( ) ) { $ nextClass = 'next disabled' ; } $ html .= '<li class="' . $ prevClass . '">' . $ paginator -> getPrevious ( false , 'a' ) . '</li>' ; $ html .= $ paginator -> getPages ( 'li' ) ; $ html .= '<li class="' . $ nextClass . '">' . $ paginator -> getNext ( false , 'a' ) . '</li>' ; $ html .= '</ul></div>' ; } if ( isset ( $ html ) ) { if ( $ return ) { return $ html ; } else { echo $ html ; } } }
Gets paging that works in our new format