First commit

This commit is contained in:
Chris Kankiewicz
2019-10-24 16:03:34 -07:00
commit 4e3267c6b6
17 changed files with 4368 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerAdmin Chris@ChrisKankiewicz.com
LogLevel debug
ErrorLog /dev/stderr
CustomLog /dev/stderr combined
</VirtualHost>

View File

@@ -0,0 +1,9 @@
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerAdmin Chris@ChrisKankiewicz.com
LogLevel warn
ErrorLog /dev/stderr
CustomLog /dev/stderr combined
</VirtualHost>

View File

@@ -0,0 +1,4 @@
[PHP]
error_reporting = E_ALL
log_errors = On
memory_limit = -1

View File

@@ -0,0 +1,18 @@
[PHP]
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
log_errors = On
memory_limit = -1
[opcache]
opcache.enable = 1
opcache.fast_shutdown = 1
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 10000
opcache.memory_consumption = 128
opcache.optimization_level = 0xffffffff
opcache.validate_timestamps = 0
[xdebug]
xdebug.profiler_enable = 0
xdebug.remote_autostart = 0
xdebug.remote_enable = 0

24
.editorconfig Normal file
View File

@@ -0,0 +1,24 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.json]
indent_style = space
indent_size = 4
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2
indent_style = space
[Makefile]
indent_size = 4
indent_style = tab

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.php_cs.cache
.phpunit.result.cache
/vendor/

12
.htaccess Normal file
View File

@@ -0,0 +1,12 @@
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

32
.php_cs.dist Normal file
View File

@@ -0,0 +1,32 @@
<?php
$finder = PhpCsFixer\Finder::create()->in([
__DIR__ . DIRECTORY_SEPARATOR . 'app',
__DIR__ . DIRECTORY_SEPARATOR . 'tests'
]);
return PhpCsFixer\Config::create()->setRules([
'@PSR1' => true,
'@PSR2' => true,
'@Symfony' => true,
'array_indentation' => true,
'array_syntax' => [
'syntax' => 'short'
],
'concat_space' => [
'spacing' => 'one'
],
'linebreak_after_opening_tag' => true,
'new_with_braces' => false,
'no_multiline_whitespace_before_semicolons' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'not_operator_with_successor_space' => true,
'phpdoc_to_comment' => false,
'phpdoc_no_empty_return' => false,
'phpdoc_order' => true,
'semicolon_after_instruction' => true,
'single_trait_insert_per_statement' => false,
'trailing_comma_in_multiline_array' => false,
'yoda_style' => null
])->setFinder($finder);

33
Dockerfile Normal file
View File

@@ -0,0 +1,33 @@
# Install PHP dependencies
FROM composer:1.9 AS php-dependencies
COPY . /app
RUN composer install --working-dir /app --ignore-platform-reqs \
--no-cache --no-dev --no-interaction
# Install and compile JavaScript assets
# FROM node:12.10 AS js-dependencies
# ARG FONT_AWESOME_TOKEN
# COPY --from=php-dependencies /app /app
# RUN npm config set "@fortawesome:registry" https://npm.fontawesome.com/
# RUN npm config set "//npm.fontawesome.com/:_authToken" ${FONT_AWESOME_TOKEN}
# RUN cd /app && npm install && npm run production
# Build application image
FROM php:7.3-apache as application
LABEL maintainer="Chris Kankiewicz <ckankiewicz@freedomdebtrelief.com>"
COPY --from=php-dependencies /app /var/www/html
RUN a2enmod rewrite
# Build (local) development image
FROM application as development
COPY ./.docker/php/config/php.dev.ini /usr/local/etc/php/php.ini
COPY ./.docker/apache2/config/000-default.dev.conf /etc/apache2/sites-available/000-default.conf
RUN pecl install xdebug && docker-php-ext-enable xdebug
# Build production image
FROM application as production
COPY ./.docker/php/config/php.prd.ini /usr/local/etc/php/php.ini
COPY ./.docker/apache2/config/000-default.prd.conf /etc/apache2/sites-available/000-default.conf
RUN docker-php-ext-install opcache

2
Makefile Normal file
View File

@@ -0,0 +1,2 @@
clear-cache:
@rm cache/* -rfv

View File

@@ -0,0 +1,19 @@
<?php
namespace PHLAK\DirectoryLister\Controllers;
use PHLAK\DirectoryLister\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)
]);
}
}

25
app/DirectoryLister.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
namespace PHLAK\DirectoryLister;
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;
}
}

34
composer.json Normal file
View File

@@ -0,0 +1,34 @@
{
"name": "phlak/directory-lister",
"description": "PHP directory lister",
"type": "project",
"license": "MIT",
"authors": [
{
"name": "Chris Kankiewicz",
"email": "Chris@ChrisKankiewicz.com"
}
],
"require": {
"php": ">=7.1",
"php-di/php-di": "^6.0",
"php-di/slim-bridge": "^3.0",
"slim/psr7": "^0.6.0",
"slim/slim": "^4.3",
"slim/twig-view": "3.0.0-beta"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.3",
"phpunit/phpunit": "^7.0 || ^8.0",
"psy/psysh": "^0.9.9"
},
"autoload": {
"psr-4": {
"PHLAK\\DirectoryLister\\": "app/"
}
},
"config": {
"sort-packages": true,
"optimize-autoloader": true
}
}

4102
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

20
docker-compose.yaml Normal file
View File

@@ -0,0 +1,20 @@
version: '3.4'
services:
app:
container_name: directory-lister-app
build:
context: .
target: development
environment:
VIRTUAL_HOST: directorylister.local
volumes:
- ./:/var/www/html
# - ./.docker/php/config/php.dev.ini:/usr/local/etc/php/php.ini
# - ./.docker/apache2/config/000-default.dev.conf:/etc/apache2/sites-available/000-default.conf
restart: unless-stopped
networks:
default:
external:
name: development

19
index.php Normal file
View File

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

View File

@@ -0,0 +1,3 @@
{% for file in files %}
&bull; {{ file.fileName }}<br>
{% endfor %}