Reorganization

This commit is contained in:
Chris Kankiewicz
2019-10-30 21:41:40 -07:00
parent 97eb476448
commit b99365a4e9
10 changed files with 9457 additions and 49 deletions

View File

@@ -1,19 +0,0 @@
<?php
namespace App\Controllers;
use App\DirectoryLister;
use Slim\Psr7\Request;
use Slim\Psr7\Response;
use Slim\Views\Twig;
class DirectoryController
{
public function __invoke(Request $request, Response $response, Twig $view, string $path = '.')
{
return $view->render($response, 'index.twig', [
// TODO: Sort the file listing
'files' => new DirectoryLister($path)
]);
}
}

View File

@@ -1,25 +0,0 @@
<?php
namespace App;
use DirectoryIterator;
use FilterIterator;
class DirectoryLister extends FilterIterator
{
public function __construct(string $path)
{
parent::__construct(
new DirectoryIterator($path)
);
}
public function accept()
{
if ($this->getInnerIterator()->current()->isDot()) {
return false;
}
return true;
}
}

18
app/config/app.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
return [
'list_folders_first' => true,
'list_sort_order' => 'natcasesort',
'theme' => 'default',
'date_format' => 'Y-m-d H:i:s',
'hidden_files' => [
'some.file', // Files
'some_dir', // Directories
'**/.ht*', // Globs
'/^.ht*$/', // Regular expressions
],
];

5
app/config/cache.php Normal file
View File

@@ -0,0 +1,5 @@
<?php
return [
// ...
];

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Controllers;
use Slim\Psr7\Request;
use Slim\Psr7\Response;
use Slim\Views\Twig;
use Symfony\Component\Finder\Finder;
class DirectoryController
{
/** @var Twig Twig templating component */
protected $view;
/**
* Create a new DirectoryController object.
*
* @param \Slim\Views\Twig $view
*/
public function __construct(Twig $view)
{
$this->view = $view;
}
/**
* Invoke the DirectoryController.
*
* @param \Slim\Psr7\Request $request
* @param \Slim\Psr7\Response $response
* @param string $path
*
* @return \Slim\Psr7\Response
*/
public function __invoke(Request $request, Response $response, string $path = '.')
{
$files = new Finder();
$files->in($path)->depth(0)->followLinks();
$files->sortByName($useNatrualSort = true)->sortByType();
return $this->view->render($response, 'index.twig', [
'files' => $files
]);
}
}

1
app/themes/default/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/node_modules/

View File

@@ -2,15 +2,13 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="favicon.png">
<link rel="stylesheet" href="styles.css">
<title>Directory Lister</title>
<ul>
{% for file in files %}
<li>
{{ file.fileName }}
{{ file.getBasename }}
</li>
{% endfor %}
</ul>

9376
app/themes/default/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
{
"author": "Chris Kankiewicz",
"license": "MIT",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"laravel-mix": "^5.0.0",
"tailwindcss": "^1.1.3"
}
}

View File

@@ -9,11 +9,10 @@ use Slim\Views\TwigMiddleware;
require __DIR__ . '/vendor/autoload.php';
$container = new Container();
$container->set(Twig::class, new Twig('themes/default', ['cache' => 'cache']));
$container->set(Twig::class, new Twig('app/themes/default', ['cache' => 'app/cache']));
$app = Bridge::create($container);
$app->add(TwigMiddleware::createFromContainer($app, Twig::class));
$app->get('/[{path:.*}]', Controllers\DirectoryController::class);
$app->run();