Skip to content

Commit

Permalink
chore(views): refactor views service to store absolute paths
Browse files Browse the repository at this point in the history
Refs #6844
  • Loading branch information
ewinslow committed Jun 12, 2015
1 parent 346861c commit 0a95202
Show file tree
Hide file tree
Showing 41 changed files with 1,820 additions and 1,410 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
"phpcs --standard=vendor/elgg/sniffs/elgg.xml --warning-severity=0 --ignore=*/tests/*,*/upgrades/*,*/deprecated* engine/classes engine/lib",
"composer validate"
],
"pre-commit": [
"composer lint",
"composer test"
],
"test": "phpunit",
"travis:install": [
"composer self-update",
Expand Down
5 changes: 3 additions & 2 deletions engine/classes/Elgg/Application/CacheHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function handleRequest($path) {

$this->application->bootCore();

if (!_elgg_is_view_cacheable($view)) {

if (!_elgg_services()->views->get($view)->isCacheable()) {
$this->send403();
} else {
echo $this->renderView($view, $viewtype);
Expand All @@ -85,7 +86,7 @@ public function handleRequest($path) {
$this->application->bootCore();

elgg_set_viewtype($viewtype);
if (!_elgg_is_view_cacheable($view)) {
if (!_elgg_services()->views->get($view)->isCacheable()) {
$this->send403();
}

Expand Down
4 changes: 0 additions & 4 deletions engine/classes/Elgg/Database/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,6 @@ function load() {
return false;
}

if (elgg_get_config('system_cache_loaded')) {
$start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_VIEWS;
}

if (elgg_get_config('i18n_loaded_from_cache')) {
$start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_LANGUAGES;
}
Expand Down
66 changes: 3 additions & 63 deletions engine/classes/Elgg/Debug/Inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,80 +37,20 @@ public function getPluginHooks() {
* @return string[]
*/
public function getViewtypes() {
global $CONFIG;

return array_keys($CONFIG->views->locations);
return array_keys(_elgg_services()->views->getViewtypes());
}

/**
* Get Elgg view information
*
* @param string $viewtype The Viewtype we wish to inspect
*
* @return array [view] => map of priority to ViewComponent[]
* @return array [view] => map of priority to View[]
*/
public function getViews($viewtype = 'default') {
global $CONFIG;

$overrides = null;
if ($CONFIG->system_cache_enabled) {
$data = _elgg_services()->systemCache->load('view_overrides');
if ($data) {
$overrides = unserialize($data);
}
} else {
$overrides = _elgg_services()->views->getOverriddenLocations();
}

// maps view name to array of ViewComponent[] with priority as keys
$views = array();

$location = "{$CONFIG->viewpath}{$viewtype}/";
$core_file_list = $this->recurseFileTree($location);

// setup views array before adding extensions and plugin views
foreach ($core_file_list as $path) {
$component = ViewComponent::fromPaths($path, $location);
$views[$component->view] = array(500 => $component);
}

// add plugins and handle overrides
foreach ($CONFIG->views->locations[$viewtype] as $view => $location) {
$component = new ViewComponent();
$component->view = $view;
$component->location = "{$location}{$viewtype}/";
$views[$view] = array(500 => $component);
}

// now extensions
foreach ($CONFIG->views->extensions as $view => $extensions) {
$view_list = array();
foreach ($extensions as $priority => $ext_view) {
if (isset($views[$ext_view])) {
$view_list[$priority] = $views[$ext_view][500];
}
}
if (count($view_list) > 0) {
$views[$view] = $view_list;
}
}

ksort($views);

// now overrides
foreach ($views as $view => $view_list) {
if (!empty($overrides[$viewtype][$view])) {
$overrides_list = array();
foreach ($overrides[$viewtype][$view] as $i => $location) {
$component = new ViewComponent();
$component->overridden = true;
$component->view = $view;
$component->location = "{$location}{$viewtype}/";
$overrides_list["o:$i"] = $component;
}
$views[$view] = $overrides_list + $view_list;
}
}
$views = _elgg_services()->views->getViews();

// view handlers
$handlers = _elgg_services()->hooks->getAllHandlers();
Expand Down
89 changes: 0 additions & 89 deletions engine/classes/Elgg/Debug/Inspector/ViewComponent.php

This file was deleted.

26 changes: 23 additions & 3 deletions engine/classes/Elgg/Di/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @property-read \Elgg\Database\Datalist $datalist
* @property-read \Elgg\Database $db
* @property-read \Elgg\DeprecationService $deprecation
* @property-read \Elgg\Filesystem\Directory $elggRootDir
* @property-read \Elgg\EntityPreloader $entityPreloader
* @property-read \Elgg\Database\EntityTable $entityTable
* @property-read \Elgg\EventsService $events
Expand Down Expand Up @@ -56,13 +57,15 @@
* @property-read \Elgg\SystemMessagesService $systemMessages
* @property-read \Elgg\I18n\Translator $translator
* @property-read \Elgg\Database\UsersTable $usersTable
* @property-read \Elgg\ViewsService $views
* @property-read \Elgg\Views\PathRegistry $viewPaths
* @property-read \Elgg\Views\ViewRegistry $views
* @property-read \Elgg\Views\ViewtypeRegistry $viewtypes
* @property-read \Elgg\WidgetsService $widgets
*
* @package Elgg.Core
* @access private
*/
class ServiceProvider extends \Elgg\Di\DiContainer {
class ServiceProvider extends DiContainer {

/**
* Constructor
Expand Down Expand Up @@ -134,6 +137,10 @@ public function __construct(\Elgg\Config $config) {
$this->setFactory('deprecation', function(ServiceProvider $c) {
return new \Elgg\DeprecationService($c->session, $c->logger);
});

$this->setFactory('elggRootDir', function(ServiceProvider $c) {
return \Elgg\Filesystem\GaufretteDirectory::createLocal(realpath(__DIR__ . '/../../../..'));
});

$this->setClassName('entityPreloader', \Elgg\EntityPreloader::class);

Expand Down Expand Up @@ -257,8 +264,21 @@ public function __construct(\Elgg\Config $config) {

$this->setClassName('usersTable', \Elgg\Database\UsersTable::class);

$this->setFactory('viewPaths', function(ServiceProvider $c) {
return new \Elgg\Views\DirectoryPathRegistry($c->elggRootDir->chroot('views'), $c->viewtypes);
});

$this->setFactory('views', function(ServiceProvider $c) {
return new \Elgg\ViewsService($c->hooks, $c->logger);
global $CONFIG;

return new \Elgg\Views\ViewRegistry(
$CONFIG, $c->events, $c->hooks, $c->logger, $c->viewtypes, $c->viewPaths);
});

$this->setFactory('viewtypes', function(ServiceProvider $c) {
global $CONFIG;

return new \Elgg\Views\ViewtypeRegistry($CONFIG, $c->input);
});

$this->setClassName('widgets', \Elgg\WidgetsService::class);
Expand Down
27 changes: 27 additions & 0 deletions engine/classes/Elgg/Filesystem/Directory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Elgg\Filesystem;

use Elgg\Structs\Collection;

/**
* A simple directory abstraction.
*
Expand Down Expand Up @@ -48,6 +50,15 @@ public function getFile($path);
*/
public function getFiles($path = '');

/**
* Get the absolute path to the given directory-relative path.
*
* @param string $path A file/directory path within this directory.
*
* @return string
*/
public function getFullPath($path = '');

/**
* Do a PHP include of the file and return the result.
*
Expand All @@ -59,6 +70,15 @@ public function getFiles($path = '');
*/
public function includeFile($path);

/**
* Whether this directory has an existing subdirectory at the given path.
*
* @param string $path The relative path within this directory
*
* @return boolean
*/
public function isDirectory($path);

/**
* Whether this directory has an existing file at the given location.
*
Expand All @@ -77,4 +97,11 @@ public function isFile($path);
* @return void
*/
public function putContents($path, $content);

/**
* Returns the full path of this directory
*
* @return string
*/
public function __toString();
}
Loading

0 comments on commit 0a95202

Please sign in to comment.