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 Jan 26, 2015
1 parent bdf2638 commit b53939e
Show file tree
Hide file tree
Showing 21 changed files with 1,249 additions and 876 deletions.
7 changes: 4 additions & 3 deletions engine/classes/Elgg/Di/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
* @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\Registry $views
* @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 @@ -240,7 +240,8 @@ public function __construct(\Elgg\AutoloadManager $autoload_manager) {
$this->setClassName('usersTable', '\Elgg\Database\UsersTable');

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

$this->setClassName('widgets', '\Elgg\WidgetsService');
Expand Down
53 changes: 44 additions & 9 deletions engine/classes/Elgg/Filesystem/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ public function getExtension() {
}

/**
* @return string The file's basename.
* @return string The part of the file after the directory, except the suffix.
*/
public function getBasename() {
return pathinfo($this->path, PATHINFO_BASENAME);
public function getBasename($suffix = '') {
return basename($this->path, $suffix);
}

/**
* @return string The directory path without the final file name.
*/
public function getDirname() {
return pathinfo($this->path, PATHINFO_DIRNAME);
}

/**
Expand All @@ -60,18 +67,46 @@ public function getContents() {
}

/**
* Do a PHP include of the file and return the result.
* Set the content of this file, overwriting old content if necessary.
*
* TODO: This may only work for local filesystem?
* @return File
*/
public function putContents($content) {
$this->filesystem->put($this->path, $content);

return $this;
}

/**
* True if the file begins with a dot or is in a directory that begins with a dot.
*
* @return mixed
* @return bool
*/
public function includeFile() {
return $this->filesystem->includeFile($this->path);
public function isPrivate() {
return strpos($this->getPath(), "/.") !== false ||
strpos($this->getPath(), ".") === 0;
}

/**
* Get the path relative to the current filesystem.
*
* @return string
*/
public function getPath() {
return $this->path;
}

/**
* Get the entire path including that of the containing filesystem.
*
* @return string
*/
public function getFullPath() {
return $this->filesystem->getFullPath($this->path);
}

/** @inheritDoc */
public function __toString() {
return $this->path;
return $this->getFullPath();
}
}
35 changes: 16 additions & 19 deletions engine/classes/Elgg/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function isFile($path) {
*
* @return boolean
*/
private function isDirectory($path) {
public function isDirectory($path) {
$adapter = $this->gaufrette->getAdapter();
return $adapter->isDirectory($this->getGaufrettePath($path));
}
Expand Down Expand Up @@ -107,11 +107,13 @@ public function getFileContents($path) {
*/
public function getFiles($path = '') {
$keys = $this->gaufrette->listKeys($this->getGaufrettePath($path));
$chroot = $this->chroot;

$filesystem = $this;
return array_map(function($path) use ($filesystem) {
return new File($filesystem, $path);
$paths = array_map(function($file_path) use ($chroot) {
return substr($file_path, strlen($chroot));
}, $keys['keys']);

return array_map(array($this, 'getFile'), $paths);
}

/**
Expand All @@ -122,7 +124,10 @@ public function getFiles($path = '') {
* @return string
*/
private function getGaufrettePath($path) {
return $this->normalize("$this->chroot/$path");
$chroot = $this->normalize($this->chroot);
$path = $this->normalize($path);

return $this->normalize("$chroot/$path");
}

/**
Expand All @@ -132,24 +137,11 @@ private function getGaufrettePath($path) {
*
* @return string
*/
private function getFullPath($path = '') {
public function getFullPath($path = '') {
$gaufrettePath = $this->normalize($this->getGaufrettePath($path));
return "$this->localPath/$gaufrettePath";
}


/**
* Do a PHP include of the file and return the result.
* This only really works with local filesystems amirite?
*
* @param string $path Filesystem-relative path for the file to include.
*
* @return mixed
*/
public function includeFile($path) {
return include $this->getFullPath($path);
}

/**
* Whether there is a file or directory at the given path.
*
Expand Down Expand Up @@ -196,6 +188,11 @@ private function normalize($path) {
return trim($path, "/");
}

/** @inheritDoc */
public function __toString() {
return $this->getFullPath();
}

/**
* Shorthand for generating a new local filesystem.
*
Expand Down
Loading

0 comments on commit b53939e

Please sign in to comment.