Skip to content

Commit

Permalink
modified: app/Config.php
Browse files Browse the repository at this point in the history
	modified:   app/Controller/CommentController.php
	modified:   app/Controller/DownloadController.php
	modified:   app/Controller/FileController.php
	modified:   app/Controller/SearchController.php
	modified:   app/Controller/UploadController.php
	modified:   app/Database/CommentMapper.php
	modified:   app/Database/FileMapper.php
	modified:   app/Database/SearchGateway.php
	modified:   app/Entity/File.php
	modified:   app/Exception/FileUploadException.php
	modified:   app/Helper/AuthHelper.php
	modified:   app/Helper/CommentHelper.php
	modified:   app/Helper/CookieHelper.php
	modified:   app/Helper/FileHelper.php
	modified:   app/Helper/IdHelper.php
	modified:   app/Helper/LanguageHelper.php
	modified:   app/Helper/LinkHelper.php
	modified:   app/Helper/PaginationHelper.php
	modified:   app/Helper/PathingHelper.php
	modified:   app/Helper/PreviewHelper.php
	modified:   app/Helper/SearchHelper.php
	modified:   app/Helper/Utils.php
	modified:   app/Middleware/CsrfMiddleware.php
	modified:   app/Middleware/LocaleMiddleware.php
	modified:   app/Translator.php
	modified:   app/Validation/Validation.php
	modified:   app/init.php
  • Loading branch information
foobar1643 committed Aug 30, 2016
1 parent 0ba57aa commit b4b3179
Show file tree
Hide file tree
Showing 28 changed files with 1,177 additions and 91 deletions.
34 changes: 33 additions & 1 deletion app/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,43 @@

namespace Filehosting;

/**
* Application configuration file, can use default settings, or load an .ini file.
*
* @author foobar1643 <foobar76239@gmail.com>
*/
class Config
{
/* Default settings */
/** @var int $appSizeLimit Uploaded file size limit in bytes. */
private $appSizeLimit = 10485760;
/** @var int $appEnableXsendfile An option to enable file downloads through X-Sendfile. */
private $appEnableXsendfile = 0;

/** @var string $dbHost Database IP address. */
private $dbHost = "127.0.0.1";
/** @var string $dbPort Database port. */
private $dbPort = "5432";
/** @var string $dbUsername Database user. */
private $dbUsername = "root";
/** @var string $dbPassword Database password. */
private $dbPassword = "qwerty";
/** @var string $dbName Database name. */
private $dbName = "filehosting";

/** @var string $sphinxHost Sphinx search engine IP address. */
private $sphinxHost = "127.0.0.1";
/** @var string $sphinxPort Sphinx search engine port. */
private $sphinxPort = "9306";

/**
* Loads config from a .ini file.
*
* @param string $file A file to load.
*
* @throws InvalidArgumentException if value does not exists in a config class.
*
* @return void
*/
public function loadFromFile($file)
{
$ini = parse_ini_file($file, true);
Expand All @@ -31,6 +53,16 @@ public function loadFromFile($file)
}
}

/**
* Returns a value form a config.
*
* @param string $section Config section.
* @param string $key Config value key.
*
* @throws InvalidArgumentException if value can't be found.
*
* @return string
*/
public function getValue($section, $key)
{
if(isset($this->{$section . ucfirst($key)})) {
Expand Down
44 changes: 39 additions & 5 deletions app/Controller/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,48 @@

namespace Filehosting\Controller;

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use \Filehosting\Entity\Comment;
use \Filehosting\Helper\CommentHelper;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Filehosting\Entity\Comment;
use Filehosting\Helper\CommentHelper;

/**
* Callable, provides a way to add comments to the database.
*
* @author foobar1643 <foobar76239@gmail.com>
*/
class CommentController
{
/** @var Filehosting\Validation\Validation $validator Validation object instance. */
private $validator;
/** @var \Slim\Container $container DI container. */
private $container;
/** @var CommentHelper $commentHelper CommentHelper instance. */
private $commentHelper;

/**
* Constructor.
*
* @todo Remove unused container class field.
*
* @param \Slim\Container $c DI container.
*/
public function __construct(\Slim\Container $c)
{
$this->container = $c;
$this->validator = $c->get('Validation');
$this->commentHelper = $c->get('CommentHelper');
}

/**
* A method that allows to use this class as a callable.
*
* @param Request $request Slim Framework request instance.
* @param Response $response Slim Framework response instance.
* @param array $args Array with additional arguments.
*
* @return array
*/
public function __invoke(Request $request, Response $response, $args)
{
$getVars = $request->getQueryParams();
Expand All @@ -32,7 +56,17 @@ public function __invoke(Request $request, Response $response, $args)
return ["errors" => $errors, "comment" => $comment];
}

public function parsePostRequest($postVars, $fileId)
/**
* Parses POST request and returns a Comment entity.
*
* @todo Make this method private.
*
* @param array $postVars Array with variables from POST request.
* @param int $fileId ID of the file in the database.
*
* @return Comment
*/
public function parsePostRequest(array $postVars, $fileId)
{
$comment = new Comment();
$dateTime = new \DateTime("now");
Expand Down
46 changes: 39 additions & 7 deletions app/Controller/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,52 @@

namespace Filehosting\Controller;

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use \Slim\Http\Stream as Stream;
use \Filehosting\Entity\File;
use \Filehosting\Helper\FileHelper;
use \Filehosting\Exception\FileNotFoundException;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Slim\Http\Stream as Stream;
use Filehosting\Entity\File;
use Filehosting\Helper\FileHelper;
use Filehosting\Exception\FileNotFoundException;

/**
* Callable, provides a way to download files.
*
* @author foobar1643 <foobar76239@gmail.com>
*/
class DownloadController
{
private $container;
/** @var FileMapper $fileMapper FileHelper instance. */
private $fileMapper;
/** @var PathingHelper $pathingHelper PathingHelper instance. */
private $pathingHelper;
/** @var FileHelper $fileHelper FileHelper instance. */
private $fileHelper;

/**
* Constructor.
*
* @param \Slim\Container $c DI container.
*/
public function __construct(\Slim\Container $c)
{
$this->fileMapper = $c->get('FileMapper');
$this->pathingHelper = $c->get('PathingHelper');
$this->fileHelper = $c->get('FileHelper');
}

/**
* A method that allows to use this class as a callable.
*
* @todo Refactor this code.
*
* @param Request $request Slim Framework request instance.
* @param Response $response Slim Framework response instance.
* @param array $args Array with additional arguments.
*
* @throws NotFoundException if file not found.
*
* @return Response
*/
public function __invoke(Request $request, Response $response, $args)
{
$params = $request->getQueryParams();
Expand All @@ -47,6 +72,13 @@ public function __invoke(Request $request, Response $response, $args)
}
}

/**
* Returns a Response object with headers for file download.
*
* @param Response $response Slim Framework response instance.
*
* @return Response
*/
private function getDownloadHeaders(Response $response)
{
return $response->withHeader('Content-Description', "File Transfer")
Expand Down
55 changes: 48 additions & 7 deletions app/Controller/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,42 @@

namespace Filehosting\Controller;

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use \Filehosting\Entity\File;
use \Filehosting\Helper\LanguageHelper;
use \Filehosting\Helper\CookieHelper;
use \Filehosting\Helper\AuthHelper;
use \Filehosting\Translator;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Filehosting\Entity\File;
use Filehosting\Helper\LanguageHelper;
use Filehosting\Helper\CookieHelper;
use Filehosting\Helper\AuthHelper;
use Filehosting\Translator;

/**
* Callable, provides a way to download files.
*
* @todo Refactor this code.
* @todo Relocate comments selection to CommentController
*
* @author foobar1643 <foobar76239@gmail.com>
*/
class FileController
{
/** @var \Slim\Container $container DI container. */
private $container;
/** @var mixed $view View instance. */
private $view;
/** @var FileHelper $fileHelper FileHelper instance. */
private $fileHelper;
/** @var FileMapper $fileMapper FileMapper instance. */
private $fileMapper;
/** @var IdHelper $idHelper IdHelper instance. */
private $idHelper;
/** @var CommentHelper $commentHelper CommentHelper instance. */
private $commentHelper;

/**
* Constructor.
*
* @param \Slim\Container $c DI container.
*/
public function __construct(\Slim\Container $c)
{
$this->container = $c;
Expand All @@ -29,6 +48,19 @@ public function __construct(\Slim\Container $c)
$this->idHelper = $c->get('IdHelper');
}

/**
* A method that allows to use this class as a callable.
*
* @todo Refactor this code.
*
* @param Request $request Slim Framework request instance.
* @param Response $response Slim Framework response instance.
* @param array $args Array with additional arguments.
*
* @throws NotFoundException if file not found.
*
* @return Response
*/
public function __invoke(Request $request, Response $response, $args)
{
$cookieHelper = new CookieHelper($request, $response);
Expand Down Expand Up @@ -61,6 +93,15 @@ public function __invoke(Request $request, Response $response, $args)
'csrf_token' => $cookieHelper->getRequestCookie('csrf_token')]);
}

/**
* Provides a way to delete files from the database.
*
* @param Request $request Slim Framework request instance.
* @param Response $response Slim Framework response instance.
* @param array $args Array with additional arguments.
*
* @return Response
*/
public function deleteFile(Request $request, Response $response, $args)
{
$authHelper = new AuthHelper(new CookieHelper($request, $response));
Expand Down
34 changes: 30 additions & 4 deletions app/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,50 @@

namespace Filehosting\Controller;

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use \Filehosting\Helper\PaginationHelper;
use \Filehosting\Helper\LanguageHelper;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Filehosting\Helper\PaginationHelper;
use Filehosting\Helper\LanguageHelper;

/**
* Callable, provides a way to search through files.
*
* @todo Refactor this code.
*
* @author foobar1643 <foobar76239@gmail.com>
*/
class SearchController
{
/** @var int RESULTS_PER_PAGE Number of elements to show per page. */
const RESULTS_PER_PAGE = 15;

/** @var mixed $view View object. */
private $view;
/** @var SearchHelper $searchHelper SearchHelper instance. */
private $searchHelper;

/**
* Constructor.
*
* @param \Slim\Container $c DI container.
*/
public function __construct(\Slim\Container $c)
{
$this->view = $c->get('view');
$this->searchHelper = $c->get('SearchHelper');
}

/**
* A method that allows to use this class as a callable.
*
* @todo Refactor this code.
*
* @param Request $request Slim Framework request instance.
* @param Response $response Slim Framework response instance.
* @param array $args Array with additional arguments.
*
* @return Response
*/
public function __invoke(Request $request, Response $response, $args)
{
$params = $request->getQueryParams();
Expand Down
Loading

0 comments on commit b4b3179

Please sign in to comment.