Skip to content

Commit

Permalink
0.10.0 breaks backwards compatibility but streamlines and improves ma…
Browse files Browse the repository at this point in the history
…ny components. See CHANGELOG.md.
  • Loading branch information
Robin de Graaf committed Apr 17, 2017
1 parent 6dc35f5 commit c196abc
Show file tree
Hide file tree
Showing 31 changed files with 588 additions and 216 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Parable PHP Framework Changelog

### 0.10.0

Note: Breaks backwards compatibility in some instances, and based on your implementation might require small tweaks or none whatsoever. By reading the following
changelog carefully it should be trivial to fix any incompatibilities.

__Changes__
- `\Parable\Auth\Authentication` has been moved to `\Parable\Framework\Authentication`, since it cannot function without packages from `Framework` and `Http`.
- `\Parable\Auth\Rights` has been moved to `\Parable\Tool\Rights`, since by itself it does not warrent an `Auth` namespace.
- `\Parable\Mail\Mailer` has also been improved:
- The main class been simplified and all template logic has been moved to `\Parable\Framework\Mail\Mailer`, since those require external logic.
- `\Parable\Framework\Mail\Mailer` now uses a `GetSet` implementation (`\Parable\Mail\TemplateVariables`) for its template variables and requires a full path for `loadTemplate` calls.
- `\Parable\Mail\Mailer` has gained `requiredHeader`, to distinguish between headers it wants to enforce itself and ones set by the dev.
- `\Parable\Mail\Mailer` has gained `getSubject()`, `getBody()`, `getHeaders()`, `getRequiredHeaders()`.
- `\Parable\Mail\Mailer` has gained `resetMailData()`, `resetRecipients()`, `resetSender()`, `reset()` (resets all but sender).
- All classes previously using `Routes` as a namespace now use `Routing` to make the namespace more consistently singular.
- `\Parable\Console` has once again gotten some love:
- `\Parable\Console\Command` namespace has been added, with 2 commands: `Help` and `Init`.
- It's now possible to add your own commands to the `parable` command, as shown in structure's `\Config\App` (`$config->get('console.commands')`).
- `\Parable\Console\App` is now always available to Commands, by setting it through `setApp()`.
- `parable.php` has been moved up one directory.
- `\Parable\Events` namespace has been changed to `\Parable\Event` for consistency.
- `\Parable\Http\Values\GetSet` has gained the following methods: `getAllAndReset()`, `getAndRemove($key)`, `reset()` and `count()`.

__Bugfixes__
- `\Parable\Framework\View` list of `@property` tags updated, since some classes were missing.

__Miscellaneous__
- Where logical and readable, double-quote {}-style concatenation added.
- Comments improved in places.

### 0.9.8

__Changes__
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"Parable\\": "src/"
}
},
"bin": ["src/parable"]
"bin": ["parable"]
}
31 changes: 31 additions & 0 deletions parable
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env php
<?php
ini_set('display_errors', '1');

/** @var \Parable\Console\App $app */
$app = require_once(__DIR__ . '/src/Framework/Bootstrap.php');

/** @var \Parable\Filesystem\Path $path */
$path = \Parable\DI\Container::get(\Parable\Filesystem\Path::class);
$path->setBasedir(BASEDIR);

$app->setName('Parable');

// Always add Help & Init
$app->addCommand(\Parable\DI\Container::get(\Parable\Console\Command\Help::class));
$app->addCommand(\Parable\DI\Container::get(\Parable\Console\Command\Init::class));

// Attempt to load commands set by the user
if (file_exists($path->getDir('app'))) {
/** @var \Parable\Framework\Config $config */
$config = \Parable\DI\Container::get(\Parable\Framework\Config::class)->load();
if ($config->get('console.commands')) {
// We don't try/catch because the dev shouldn't add non-existing classes.
foreach ($config->get('console.commands') as $commandClassName) {
$app->addCommand(\Parable\DI\Container::get($commandClassName));
}
}
}

$app->setDefaultCommand('help');
$app->run();
7 changes: 0 additions & 7 deletions src/Auth/Exception.php

This file was deleted.

2 changes: 2 additions & 0 deletions src/Console/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public function run()
throw new \Parable\Console\Exception('No valid command found.');
}

$command->setApp($this);

$this->parameter->setOptions($command->getOptions());
$this->parameter->checkOptions();

Expand Down
14 changes: 14 additions & 0 deletions src/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ class Command
/** @var array */
protected $options = [];

/** @var \Parable\Console\App */
protected $app;

/**
* @param \Parable\Console\App $app
*
* @return $this
*/
public function setApp(\Parable\Console\App $app)
{
$this->app = $app;
return $this;
}

/**
* @param string $name
*
Expand Down
47 changes: 47 additions & 0 deletions src/Console/Command/Help.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Parable\Console\Command;

class Help extends \Parable\Console\Command
{
/** @var string */
protected $name = 'help';

/** @var string */
protected $description = 'Shows all commands available.';

/**
* @param \Parable\Console\Output $output
* @param \Parable\Console\Input $input
* @param \Parable\Console\Parameter $parameter
*
* @return $this
*/
public function run(
\Parable\Console\Output $output,
\Parable\Console\Input $input,
\Parable\Console\Parameter $parameter
) {
$output->writeln("<yellow>{$this->app->getName()} help</yellow>");
$output->writeln('--------------------------------------------------');
$output->writeln('Available commands:');
$output->newline();

$longestName = 0;
foreach ($this->app->getCommands() as $command) {
$strlen = strlen($command->getName());
if ($strlen > $longestName) {
$longestName = $strlen;
}
}

foreach ($this->app->getCommands() as $command) {
$name = $command->getName();
$output->write(str_pad(" <green>{$name}</green>", $longestName + 22, ' ', STR_PAD_RIGHT));
$output->write("{$command->getDescription()}");
$output->newline();
}
$output->newline();
return $this;
}
}
142 changes: 142 additions & 0 deletions src/Console/Command/Init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

namespace Parable\Console\Command;

class Init extends \Parable\Console\Command
{
/** @var string */
protected $name = 'init';

/** @var string */
protected $description = 'This command initializes a parable structure.';

/** @var \Parable\Filesystem\Path */
protected $path;

public function __construct(
\Parable\Filesystem\Path $path
) {
$this->path = $path;
}

/**
* @param \Parable\Console\Output $output
* @param \Parable\Console\Input $input
* @param \Parable\Console\Parameter $parameter
*
* @return $this
*/
public function run(
\Parable\Console\Output $output,
\Parable\Console\Input $input,
\Parable\Console\Parameter $parameter
) {
$output->writeln([
"Parable initialization script",
"-----------------------------------",
"This script will initialize Parable's structure.",
"",
"<red>WARNING</red>",
"This will overwrite existing files without notice!",
"",
]);

for (;;) {
$output->write("Do you want to continue? [y/N] ");
if ($input->getYesNo(false)) {
break;
} else {
$output->writeln(["", "<red>You chose not to continue.</red>", ""]);
return $this;
}
}

/** @var \Parable\Filesystem\Path $path */
$output->newline();
$output->write('Creating folder structure: ');

$dirs = [
'app',
'app/Command',
'app/Config',
'app/Controller',
'app/Init',
'app/Model',
'app/Routing',
'app/View',
'app/View/Home',
'public',
];

foreach ($dirs as $dir) {
if (!file_exists($this->path->getDir($dir))) {
mkdir($this->path->getDir($dir));
}
$output->write('.');
}

$output->writeln(" <green>OK</green>");

$output->write('Copying files: ');
copy(
$this->path->getDir('vendor/devvoh/parable/structure/.htaccess'),
$this->path->getDir('.htaccess')
);
$output->write('.');
copy(
$this->path->getDir('vendor/devvoh/parable/structure/public/.htaccess'),
$this->path->getDir('public/.htaccess')
);
$output->write('.');
copy(
$this->path->getDir('vendor/devvoh/parable/structure/public/index.php'),
$this->path->getDir('public/index.php')
);
$output->write('.');
copy(
$this->path->getDir('vendor/devvoh/parable/structure/app/Command/HelloWorld.php'),
$this->path->getDir('app/Command/HelloWorld.php')
);
$output->write('.');
copy(
$this->path->getDir('vendor/devvoh/parable/structure/app/Config/App.php'),
$this->path->getDir('app/Config/App.php')
);
$output->write('.');
copy(
$this->path->getDir('vendor/devvoh/parable/structure/app/Controller/Home.php'),
$this->path->getDir('app/Controller/Home.php')
);
$output->write('.');
copy(
$this->path->getDir('vendor/devvoh/parable/structure/app/Init/Example.php'),
$this->path->getDir('app/Init/Example.php')
);
$output->write('.');
copy(
$this->path->getDir('vendor/devvoh/parable/structure/app/Model/User.php'),
$this->path->getDir('app/Model/User.php')
);
$output->write('.');
copy(
$this->path->getDir('vendor/devvoh/parable/structure/app/Routing/App.php'),
$this->path->getDir('app/Routing/App.php')
);
$output->write('.');
copy(
$this->path->getDir('vendor/devvoh/parable/structure/app/View/Home/index.phtml'),
$this->path->getDir('app/View/Home/index.phtml')
);
$output->write('.');
copy(
$this->path->getDir('vendor/devvoh/parable/structure/app/View/Home/test.phtml'),
$this->path->getDir('app/View/Home/test.phtml')
);
$output->write('.');

$output->writeln(" <green>OK</green>");

$output->writeln(["", "<green>Completed!</green>", ""]);
return $this;
}
}
8 changes: 4 additions & 4 deletions src/DI/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public static function get($className, $parentClassName = '')
&& isset(self::$relations[$parentClassName])
&& isset(self::$relations[$parentClassName][$className])
) {
$message = 'Cyclical dependency found: ' . $className . ' depends on ' . $parentClassName;
$message .= ' but is itself a dependency of ' . $parentClassName . '.';
$message = "Cyclical dependency found: {$className} depends on {$parentClassName}";
$message .= " but is itself a dependency of {$parentClassName}.";
throw new \Parable\DI\Exception($message);
}

Expand All @@ -55,9 +55,9 @@ public static function get($className, $parentClassName = '')
public static function create($className, $parentClassName = '')
{
if (!class_exists($className)) {
$message = 'Could not create instance of "' . $className . '"';
$message = "Could not create instance of '{$className}'";
if ($parentClassName) {
$message .= ', required by "' . $parentClassName . '"';
$message .= ", required by '{$parentClassName}'";
}
throw new \Parable\DI\Exception($message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Events/Dock.php → src/Event/Dock.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Parable\Events;
namespace Parable\Event;

class Dock
{
Expand Down
2 changes: 1 addition & 1 deletion src/Events/Hook.php → src/Event/Hook.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Parable\Events;
namespace Parable\Event;

class Hook
{
Expand Down
8 changes: 4 additions & 4 deletions src/Framework/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class App
/** @var \Parable\Framework\Dispatcher */
protected $dispatcher;

/** @var \Parable\Events\Hook */
/** @var \Parable\Event\Hook */
protected $hook;

/** @var \Parable\Routing\Router */
Expand All @@ -35,13 +35,13 @@ class App
protected $database;

/** @var string */
protected $version = '0.9.9';
protected $version = '0.10.0';

public function __construct(
\Parable\Filesystem\Path $path,
\Parable\Framework\Config $config,
\Parable\Framework\Dispatcher $dispatcher,
\Parable\Events\Hook $hook,
\Parable\Event\Hook $hook,
\Parable\Routing\Router $router,
\Parable\Http\Request $request,
\Parable\Http\Response $response,
Expand Down Expand Up @@ -128,7 +128,7 @@ public function run()
*/
protected function loadRoutes()
{
foreach (\Parable\DI\Container::get(\Routes\App::class)->get() as $name => $route) {
foreach (\Parable\DI\Container::get(\Routing\App::class)->get() as $name => $route) {
$this->router->addRoute($name, $route);
}
return $this;
Expand Down
Loading

0 comments on commit c196abc

Please sign in to comment.