mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-09-02 02:12:37 +02:00
Reorganization
This commit is contained in:
@@ -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)
|
||||
]);
|
||||
}
|
||||
}
|
@@ -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
18
app/config/app.php
Normal 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
5
app/config/cache.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
// ...
|
||||
];
|
44
app/controllers/DirectoryController.php
Normal file
44
app/controllers/DirectoryController.php
Normal 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
1
app/themes/default/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/node_modules/
|
@@ -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
9376
app/themes/default/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
app/themes/default/package.json
Normal file
11
app/themes/default/package.json
Normal 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"
|
||||
}
|
||||
}
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user