Skip to content

Commit

Permalink
Move SessionMessage to Framework, clean up index.php/parable
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin de Graaf committed Jan 7, 2018
1 parent 5372a5b commit d873dd4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ __Changes__

__Backwards-incompatible Changes__
- `Bootstrap.php` has been removed. `\Parable\Framework\App` handles its own setup now. This makes it easier to implement App without much hassle.
- `SessionMessage` has been moved from the `GetSet` component into `Framework`, as it isn't a `GetSet` instance itself but merely uses the `Session` instance.
- `\Parable\Console` no longer accepts options in the format `--option value`, but only in the following: `--option=value`. This is because if you had an option which didn't require a value, and was followed by an argument, the argument would be seen as the option's value instead.
- `\Parable\Console\App::setDefaultCommand()` now takes a command instance rather than the name, as the name would suggest. To set the default command by name, use `setDefaultCommandByName()` instead.
- `\Parable\Console\App::setOnlyUseDefaultCommand()` was added, and the boolean paramater was removed from the `setDefaultCommand/ByName()` function calls. Checked by calling `shouldOnlyUseDefaultCommand()`.
Expand All @@ -74,6 +75,7 @@ __Bugfixes__
- `\Parable\Console\Output` had a bug where moving the cursors would mess with the functionality of `clearLine()`. Line length is no longer kept track of, but whether or not the line is clearable is a boolean value. Moving the cursor up/down or placing it disables line clearing, writing anything enables it again. When you clear the line, the line gets cleared using the terminal width.
- `\Parable\Console\Parameter` had a bug where providing an argument after an option with an `=` sign in it (so `script.php command option=value arg`) would see the argument as the option value and overwrite the actual value. Fixed by @dmvdbrugge in PR #31. Thanks!
- `\Parable\Console\Parameter` had a bug, where false-equivalent values passed to an option would be seen as the option being provided without a value, making the returned value `true`. Fixed by @dmvdbrugge in PR #37. Thanks!
- `\Parable\Http\Response` had a bug in `appendContent()` and `prependResponse()` where when working with arrays, empty values ended up as an empty array key, messing with json output.
- `\Parable\Filesystem\Path::getDir()` had a bug where if the filename you were trying to get a proper base-dirred path for already existed in the directory the code was run from, it would think it didn't need to and return just the provided path again.
- `\Parable\Framework\Config` had a bug where a class was referenced that doesn't exist until you've run `parable init-structure`. This has been replaced with a string value instead. Found by @dmvdbrugge. Thanks!
- `\Parable\Routing\Router` now sanitizes the Url before trying to match it, stripping html and special characters.
Expand Down
7 changes: 2 additions & 5 deletions parable
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
// We're going to want to display all errors.
ini_set('display_errors', '1');

// Require defines.php so we've got DS and BASEDIR
require_once __DIR__ . DIRECTORY_SEPARATOR . "src" . DIRECTORY_SEPARATOR . "defines.php";

// Require the autoloader
require_once realpath(BASEDIR . DS . "vendor" . DS . "autoload.php");
// Require the Composer autoloader
require_once realpath(__DIR__ . "/../../autoload.php");

/** @var \Parable\Console\App $app */
$app = \Parable\DI\Container::create(\Parable\Console\App::class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Parable\GetSet;
namespace Parable\Framework;

class SessionMessage
{
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @property \Parable\Framework\Authentication $authentication
* @property \Parable\Framework\Config $config
* @property \Parable\Framework\Dispatcher $dispatcher
* @property \Parable\Framework\SessionMessage $sessionMessage
* @property \Parable\Framework\Toolkit $toolkit
* @property \Parable\Framework\View $view
* @property \Parable\Framework\Mail\Mailer $mailer
Expand All @@ -27,7 +28,6 @@
* @property \Parable\GetSet\Post $post
* @property \Parable\GetSet\Server $server
* @property \Parable\GetSet\Session $session
* @property \Parable\GetSet\SessionMessage $sessionMessage
* @property \Parable\Log\Logger $logger
* @property \Parable\ORM\Query $query
* @property \Parable\ORM\Database $database
Expand Down
20 changes: 12 additions & 8 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,12 @@ public function getContent()
*/
public function prependContent($content)
{
if (is_array($this->content)) {
array_unshift($this->content, $content);
} else {
$this->content = $content . $this->content;
if (!empty($content)) {
if (is_array($this->content)) {
array_unshift($this->content, $content);
} else {
$this->content = $content . $this->content;
}
}
return $this;
}
Expand All @@ -245,10 +247,12 @@ public function prependContent($content)
*/
public function appendContent($content)
{
if (is_array($this->content)) {
$this->content[] = $content;
} else {
$this->content .= $content;
if (!empty($content)) {
if (is_array($this->content)) {
$this->content[] = $content;
} else {
$this->content .= $content;
}
}
return $this;
}
Expand Down
7 changes: 3 additions & 4 deletions structure/public/index.php_struct
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
$bs = DIRECTORY_SEPARATOR;
$autoloaderPath = realpath(__DIR__ . $bs . ".." . $bs . "vendor" . $bs . "autoload.php");
$autoloaderPath = realpath(__DIR__ . "/../vendor/autoload2.php");

if (!file_exists($autoloaderPath)) {
die("<b>ERROR</b>: You need to run <pre style='display:inline-block;background:#e6e6e6;padding:2px 5px'>composer install</pre> before Parable will work.");
if ($autoloaderPath) {
die("<b>ERROR</b>: You need to run <code>composer install</code> before Parable will work.");

This comment has been minimized.

Copy link
@FaaPz

FaaPz Jan 7, 2018

Yay for <code> 🎉

}

require_once $autoloaderPath;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Parable\Tests\Components\GetSet;
namespace Parable\Tests\Components\Framework;

class SessionMessageTest extends \Parable\Tests\Base
{
/** @var \Parable\GetSet\SessionMessage */
/** @var \Parable\Framework\SessionMessage */
protected $sessionMessage;

protected function setUp()
Expand All @@ -13,15 +13,15 @@ protected function setUp()

$session = new \Parable\GetSet\Session();
$session->set(
\Parable\GetSet\SessionMessage::SESSION_KEY,
\Parable\Framework\SessionMessage::SESSION_KEY,
[
'notice' => [
'This is message 1.',
'This is message 2.'
],
]
);
$this->sessionMessage = new \Parable\GetSet\SessionMessage($session);
$this->sessionMessage = new \Parable\Framework\SessionMessage($session);
}

public function testGet()
Expand Down

0 comments on commit d873dd4

Please sign in to comment.