Elgg  Version master
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Elgg\ViewsService Class Reference

Views service. More...

Public Member Functions

 __construct (protected EventsService $events, protected HttpRequest $request, protected Config $config, protected SystemCache $server_cache)
 Constructor. More...
 
 setViewtype (string $viewtype= '')
 Set the viewtype. More...
 
 getViewtype ()
 Get the viewtype. More...
 
 isValidViewtype (string $viewtype)
 Checks if $viewtype is a string suitable for use as a viewtype name. More...
 
 autoregisterViews (string $view_base, string $folder, string $viewtype)
 Auto-registers views from a location. More...
 
 findViewFile (string $view, string $viewtype)
 Find the view file. More...
 
 registerViewtypeFallback (string $viewtype)
 Register a viewtype to fall back to a default view if a view isn't found for that viewtype. More...
 
 doesViewtypeFallback (string $viewtype)
 Checks if a viewtype falls back to default. More...
 
 renderDeprecatedView (string $view, array $vars, string $suggestion, string $version)
 Display a view with a deprecation notice. More...
 
 getViewList (string $view)
 Get the views, including extensions, used to render a view. More...
 
 renderView (string $view, array $vars=[], string $viewtype= '', bool $issue_missing_notice=null, array $extensions_tree=[])
 Renders a view. More...
 
 viewExists (string $view, string $viewtype= '', bool $recurse=true)
 Returns whether the specified view exists. More...
 
 extendView (string $view, string $view_extension, int $priority=501)
 Extends a view with another view. More...
 
 unextendView (string $view, string $view_extension)
 Unextends a view. More...
 
 registerViewsFromPath (string $path)
 Register all views in a given path. More...
 
 mergeViewsSpec (array $spec)
 Merge a specification of absolute view paths. More...
 
 listViews (string $viewtype= 'default')
 List all views in a viewtype. More...
 
 getInspectorData ()
 Get inspector data. More...
 
 configureFromCache ()
 Configure locations from the cache. More...
 
 cacheConfiguration ()
 Cache the configuration. More...
 
 isViewLocationsLoadedFromCache ()
 Checks if view_locations have been loaded from cache. More...
 
 getESModules ()
 Returns an array of names of ES modules detected based on view location. More...
 

Public Attributes

const VIEW_HOOK = 'view'
 
const VIEW_VARS_HOOK = 'view_vars'
 
const OUTPUT_KEY = '__view_output'
 
const BASE_VIEW_PRIORITY = 500
 

Protected Member Functions

 resolveViewtype ()
 Resolve the initial viewtype. More...
 
 fileExists (string $path)
 Wrapper for file_exists() that caches false results (the stat cache only caches true results). More...
 
 renderViewFile (string $view, array $vars, string $viewtype, bool $issue_missing_notice)
 Includes view PHP or static file. More...
 
 setViewLocation (string $view, string $viewtype, string $path)
 Update the location of a view file. More...
 

Protected Attributes

array $file_exists_cache = []
 
array $locations = []
 
array $overrides = []
 
array $extensions = []
 
array $fallbacks = []
 
string $viewtype
 
bool $locations_loaded_from_cache = false
 

Detailed Description

Views service.

Definition at line 16 of file ViewsService.php.

Constructor & Destructor Documentation

Elgg\ViewsService::__construct ( protected EventsService  $events,
protected HttpRequest  $request,
protected Config  $config,
protected SystemCache  $server_cache 
)

Constructor.

Parameters
EventsService$eventsEvents service
\Elgg\Http\Request$requestHttp Request
\Elgg\Config$configElgg configuration
\Elgg\Cache\SystemCache$server_cacheServer cache

Definition at line 69 of file ViewsService.php.

Member Function Documentation

Elgg\ViewsService::autoregisterViews ( string  $view_base,
string  $folder,
string  $viewtype 
)

Auto-registers views from a location.

Parameters
string$view_baseOptional The base of the view name without the view type.
string$folderRequired The folder to begin looking in
string$viewtypeThe type of view we're looking at (default, rss, etc)
Returns
bool returns false if folder can't be read

Definition at line 162 of file ViewsService.php.

Elgg\ViewsService::cacheConfiguration ( )

Cache the configuration.

Returns
void

Definition at line 660 of file ViewsService.php.

Elgg\ViewsService::configureFromCache ( )

Configure locations from the cache.

Returns
void

Definition at line 641 of file ViewsService.php.

Elgg\ViewsService::doesViewtypeFallback ( string  $viewtype)

Checks if a viewtype falls back to default.

Parameters
string$viewtypeViewtype
Returns
bool

Definition at line 247 of file ViewsService.php.

Elgg\ViewsService::extendView ( string  $view,
string  $view_extension,
int  $priority = 501 
)

Extends a view with another view.

Parameters
string$viewThe view to extend.
string$view_extensionThis view is added to $view
int$priorityThe priority, from 0 to 1000, to add at (lowest numbers displayed first)
Returns
void
See also
elgg_extend_view()

Definition at line 480 of file ViewsService.php.

Elgg\ViewsService::fileExists ( string  $path)
protected

Wrapper for file_exists() that caches false results (the stat cache only caches true results).

This saves us from many unneeded file stat calls when a common view uses a fallback.

Parameters
string$pathPath to the file
Returns
bool

Definition at line 378 of file ViewsService.php.

Elgg\ViewsService::findViewFile ( string  $view,
string  $viewtype 
)

Find the view file.

Parameters
string$viewView name
string$viewtypeViewtype
Returns
string Empty string if not found

Definition at line 213 of file ViewsService.php.

Elgg\ViewsService::getESModules ( )

Returns an array of names of ES modules detected based on view location.

Returns
array

Definition at line 696 of file ViewsService.php.

Elgg\ViewsService::getInspectorData ( )

Get inspector data.

Returns
array

Definition at line 618 of file ViewsService.php.

Elgg\ViewsService::getViewList ( string  $view)

Get the views, including extensions, used to render a view.

Keys returned are view priorities. View existence is not checked.

Parameters
string$viewView name
Returns
string[]

Definition at line 281 of file ViewsService.php.

Elgg\ViewsService::getViewtype ( )

Get the viewtype.

Returns
string

Definition at line 105 of file ViewsService.php.

Elgg\ViewsService::isValidViewtype ( string  $viewtype)

Checks if $viewtype is a string suitable for use as a viewtype name.

Parameters
string$viewtypePotential viewtype name. Alphanumeric chars plus _ allowed.
Returns
bool

Definition at line 141 of file ViewsService.php.

Elgg\ViewsService::isViewLocationsLoadedFromCache ( )

Checks if view_locations have been loaded from cache.

This can be used to determine if there is a need to (re)load view locations

Returns
bool

Definition at line 687 of file ViewsService.php.

Elgg\ViewsService::listViews ( string  $viewtype = 'default')

List all views in a viewtype.

Parameters
string$viewtypeViewtype
Returns
string[]

Definition at line 605 of file ViewsService.php.

Elgg\ViewsService::mergeViewsSpec ( array  $spec)

Merge a specification of absolute view paths.

Parameters
array$specSpecification viewtype => [ view_name => path or array of paths ]
Returns
void

Definition at line 574 of file ViewsService.php.

Elgg\ViewsService::registerViewsFromPath ( string  $path)

Register all views in a given path.

Parameters
string$pathBase path to scan for views
Returns
bool

Definition at line 534 of file ViewsService.php.

Elgg\ViewsService::registerViewtypeFallback ( string  $viewtype)

Register a viewtype to fall back to a default view if a view isn't found for that viewtype.

Parameters
string$viewtypeThe viewtype to register
Returns
void
See also
elgg_register_viewtype_fallback()

Definition at line 236 of file ViewsService.php.

Elgg\ViewsService::renderDeprecatedView ( string  $view,
array  $vars,
string  $suggestion,
string  $version 
)

Display a view with a deprecation notice.

No missing view NOTICE is logged

Parameters
string$viewThe name and location of the view to use
array$varsVariables to pass to the view
string$suggestionSuggestion with the deprecation message
string$versionHuman-readable release version: 1.7, 1.8, ...
Returns
string The parsed view
See also
elgg_view()

Definition at line 263 of file ViewsService.php.

Elgg\ViewsService::renderView ( string  $view,
array  $vars = [],
string  $viewtype = '',
bool  $issue_missing_notice = null,
array  $extensions_tree = [] 
)

Renders a view.

Parameters
string$viewName of the view
array$varsVariables to pass to the view
string$viewtypeViewtype to use
bool$issue_missing_noticeShould a missing notice be issued
array$extensions_treeArray of views that are before the current view in the extension path
Returns
string
See also
elgg_view()

Definition at line 298 of file ViewsService.php.

Elgg\ViewsService::renderViewFile ( string  $view,
array  $vars,
string  $viewtype,
bool  $issue_missing_notice 
)
protected

Includes view PHP or static file.

Parameters
string$viewThe view name
array$varsVariables passed to view
string$viewtypeThe viewtype
bool$issue_missing_noticeLog a notice if the view is missing
Returns
string|false output generated by view file inclusion or false

Definition at line 396 of file ViewsService.php.

Elgg\ViewsService::resolveViewtype ( )
protected

Resolve the initial viewtype.

Returns
string

Definition at line 118 of file ViewsService.php.

Elgg\ViewsService::setViewLocation ( string  $view,
string  $viewtype,
string  $path 
)
protected

Update the location of a view file.

Parameters
string$viewView name
string$viewtypeViewtype
string$pathFile path
Returns
void

Definition at line 725 of file ViewsService.php.

Elgg\ViewsService::setViewtype ( string  $viewtype = '')

Set the viewtype.

Parameters
string$viewtypeViewtype
Returns
bool

Definition at line 84 of file ViewsService.php.

Elgg\ViewsService::unextendView ( string  $view,
string  $view_extension 
)

Unextends a view.

Parameters
string$viewThe view that was extended.
string$view_extensionThis view that was added to $view
Returns
bool
See also
elgg_unextend_view()

Definition at line 509 of file ViewsService.php.

Elgg\ViewsService::viewExists ( string  $view,
string  $viewtype = '',
bool  $recurse = true 
)

Returns whether the specified view exists.

Parameters
string$viewThe view name
string$viewtypeIf set, forces the viewtype
bool$recurseIf false, do not check extensions
Returns
bool
See also
elgg_view_exists()

Definition at line 434 of file ViewsService.php.

Member Data Documentation

array Elgg\ViewsService::$extensions = []
protected

Definition at line 50 of file ViewsService.php.

array Elgg\ViewsService::$fallbacks = []
protected

Definition at line 55 of file ViewsService.php.

array Elgg\ViewsService::$file_exists_cache = []
protected

Definition at line 29 of file ViewsService.php.

array Elgg\ViewsService::$locations = []
protected

Definition at line 36 of file ViewsService.php.

bool Elgg\ViewsService::$locations_loaded_from_cache = false
protected

Definition at line 59 of file ViewsService.php.

array Elgg\ViewsService::$overrides = []
protected

Definition at line 43 of file ViewsService.php.

string Elgg\ViewsService::$viewtype
protected

Definition at line 57 of file ViewsService.php.

const Elgg\ViewsService::BASE_VIEW_PRIORITY = 500

Definition at line 23 of file ViewsService.php.

const Elgg\ViewsService::OUTPUT_KEY = '__view_output'

Definition at line 22 of file ViewsService.php.

const Elgg\ViewsService::VIEW_HOOK = 'view'

Definition at line 20 of file ViewsService.php.

const Elgg\ViewsService::VIEW_VARS_HOOK = 'view_vars'

Definition at line 21 of file ViewsService.php.


The documentation for this class was generated from the following file: