Skip to content

Commit

Permalink
Merge pull request #42 from devvoh/develop
Browse files Browse the repository at this point in the history
Update release to Parable 1.1.0
  • Loading branch information
Robin de Graaf authored May 17, 2018
2 parents 71a84e5 + f033067 commit 795506d
Show file tree
Hide file tree
Showing 80 changed files with 1,895 additions and 535 deletions.
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
# Parable PHP Framework Changelog

### 1.1.0

__Changes__

- The `parable` command has been fixed up massively. There's now a `\Parable\Framework\ConsoleApp` class, which handles the actual logic. By using this, you can offer your own command instead of `parable`.
- `defines.php` now sets a global constant `APP_CONTEXT` to either `web` or `cli`. This can help you figure out what context you're running in.
- `defines.php` now also defines a new function: `register_parable_package()`. This can be used by external Parable Packages to register themselves with Parable at the soonest possible moment. See below for details.
- `\Parable\Console\App` now also adds the command you set through `setDefaultCommand()`. It's now also possible to `removeCommandByName()`.
- `\Parable\DI\Container` gained `getDependenciesFor()` so it's possible to get just an array of instantiated dependencies.
- `\Parable\Framework\App` gained multiple hooks: `HOOK_LOAD_CONFIG_BEFORE`/`AFTER`, `HOOK_LOAD_INITS_BEFORE`/`AFTER`, `HOOK_LOAD_LAYOUT_BEFORE`/`AFTER`.
- `\Parable\Framework\App` now supports layouts, which are loaded just before the response is sent. See the `Response` changes below for details. The config values used to load the templates are `parable.layout.header` and `parable.layout.footer`. They're expected to be `.phtml` files.
- `\Parable\Framework\Loader` has been added, containing `InitLoader` and `CommandLoader`, easing the use of either and separating that logic away nicely.
- `\Parable\Framework\Package\PackageManager` was added, allowing external packages to register themselves with Parable before Parable is actually completely set up. Packages are loaded _before_ config and anything else. They get to use the hooks mentioned above.
- `\Parable\Framework\Package\PackageInterface` is an interface used to define a Parable Package.
- `\Parable\Framework\Authentication` has gained `resetUser()` and `reset()`, which calls it and `revokeAuthentication()` both. This makes it possible to unset the user as well.
- `\Parable\Framework\Authentication` has also gained `setUserIdProperty()` and `getUserIdProperty()`, for more control over how to load users.
- `\Parable\Http\Output\OutputInterface` has gained `acceptsContent($content)`, which will return a boolean for whether it accepts a type of content or not.
- `\Parable\Http\Output\OutputInterface::prepare()` now has to return a string value. Always. Exception thrown if not. This makes Output behavior expected.D
- `\Parable\Http\Output\AbstractOutput` was added, which implements `acceptsContent()` to return default `true`.
- `\Parable\Http\Output\Html` overrides `acceptsContent()` to only accept `string` or `null` types. `Json` accepts all types.
- `\Parable\Http\Response` has gained `setHeaderContent()` and `setFooterContent`, which are pre/appended to the content when sending. This is used by `App`'s layout logic. Also there's getters for both.
- `\Parable\Http\Response` also gained `stopOutputBuffer()`, which does the same as `returnOutputBuffer()` but doesn't return anything. `stopAllOutputBuffers()` pretty much does what it says.
- `\Parable\ORM\Query`'s join methods now all accept a new optional parameter, `$tableName`. Normally, the table name is set to the table already set on the query. But now you can override it. This makes it possible to join tables with other tables, neither of which are forced to be the main table.
- `\Parable\ORM\Query` has gained `whereCondition()`, taking the standard `$key`, `$comparator` and optional `$value` (default `null`) and `$tableName`. This was added to ease adding simple wheres, without having to _always_ build a condition set.
- `\Parable\ORM\Query\ConditionSet` now accepts a 4th parameter, which is `$tableName`, in case you want to check against a different table's values.
- `\Parable\Rights\Rights` has gained `getRightsNames()`, which will return the names of all rights configured.

__Bugfixes__

- `\Parable\Console\Output` has had its tags fixed up. It's now possible to combine fore- and background colors, as was always intended. Some small typo fixes in the tag names, but they're easy to fix.
- `\Parable\Framework\App` has lost some classes from its constructor. They're now loaded on an as-needed basis. So if you don't need the session, it won't be loaded, for example.
- `\Parable\Framework\App` now loads the database immediately after loading the Config, instead of much later.
- `\Parable\Framework\Dispatcher` didn't check route return values and blindly attempted to string-concatenate them. With the help of the `Output` changes, it now checks what kind of data it is and handles it accordingly.
- `\Parable\GetSet\Base` now throws an exception when `getAll()` is called for a global resource type, but the resource doesn't exist. Example case: attempting to use session data before the session is started.
- `\Parable\Http\Response` now checks whether it's possible to append output buffers to content, and uses `acceptsContent` to make sure only valid content is set using the available output method.
- `\Parable\ORM\Model` now returns all fields when `exportToArray()` is called and no `$model->exportable` values are actually available. Remember, Parable's not here to hold your hand. You're responsible for only exporting the right data!

__Parable Packages Information__

Parable Packages are rather simple. Say you want to build something that relies on and extends Parable. If so, just create a class that implements `PackageInterface`, implement the methods defined there, and in your composer.json, make sure that under `autoload`/`files` it loads a php file (_after_ `defines.php` itself is loaded) that calls `register_parable_package()` (as defined in Parable's own `defines.php`) and passes the name of your package file.

Parable will attempt to load the commands and inits defined in your parable package file, and they'll be available from the start of the application's runtime. The commands _will_ be available from the default `parable` command as well.

More details will be added to the documentation once released.

### 1.0.0

Considering the 0.11.x branch as Release Candidate 1 and the 0.12.x branch as RC2, it's time to ship final Parable. This release brings a major clean-up, documentation, and some useful additions.

If you're new to Parable, welcome! None of this is relevant for you :)

__Changes__

- All method doc blocks now have explanatory text, even if it's superfluous, for documentation purposes.
- `\Parable\Console\App` now supports adding multiple commands in one go, using `addCommands([...])`.
- `\Parable\Console\Command\Help` now can generate a string for the usage of a command. Try it yourself: `vendor/bin/parable help init-structure`. Usage is also added to any exception caught by `\Parable\Console\App`'s exception handler.
Expand Down Expand Up @@ -58,6 +104,7 @@ __Changes__
- It's now possible to set a new config value - `parable.database.soft-quotes` - to either `true` (default) or `false`. If `true`, Parable will fake quotes for values if there's no database instance available. If set to `false`, it'll refuse to quote instead.

__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.
Expand All @@ -81,6 +128,7 @@ __Backwards-incompatible Changes__
- Two config keys were renamed: `parable.session.autoEnable` has become `parable.session.auto-enable` and `parable.app.homeDir` has become `parable.app.homedir`. The option for `init-structure` has also become `--homedir`.

__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!
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ coverage: dependencies
rm -rf ./coverage
vendor/bin/phpunit --coverage-html ./coverage tests

tests-clean:
vendor/bin/phpunit --verbose tests

coverage-clean:
rm -rf ./coverage
vendor/bin/phpunit --coverage-html ./coverage tests

server:
@echo Running on http://127.0.0.1:5678
php -t ../../.. -S 127.0.0.1:5678 php-server.php
46 changes: 3 additions & 43 deletions parable
Original file line number Diff line number Diff line change
@@ -1,47 +1,7 @@
#!/usr/bin/env php
<?php
// We're going to want to display all errors.
ini_set('display_errors', '1');

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

/** @var \Parable\Console\App $app */
$app = \Parable\DI\Container::create(\Parable\Console\App::class);

// Add the default location to the autoloader and register it
$autoloader = \Parable\DI\Container::create(\Parable\Framework\Autoloader::class);
$autoloader->addLocation(BASEDIR . DS . 'app');
$autoloader->register();

// Set the basedir on the path
$path = \Parable\DI\Container::create(\Parable\Filesystem\Path::class);
$path->setBaseDir(BASEDIR);

$app->setName("Parable " . \Parable\Framework\App::PARABLE_VERSION);

$helpCommand = \Parable\DI\Container::get(\Parable\Console\Command\Help::class);
$initStructureCommand = \Parable\DI\Container::get(\Parable\Framework\Command\InitStructure::class);

// Always add Help & Init
$app->addCommands([
$helpCommand,
$initStructureCommand,
]);

// 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);
$config->load();

if ($config->get('parable.commands')) {
// We don't try/catch because the dev shouldn't add non-existing classes.
foreach ($config->get('parable.commands') as $commandClassName) {
$app->addCommand(\Parable\DI\Container::get($commandClassName));
}
}
}

$app->setDefaultCommand($helpCommand);
$app->run();
$consoleApp = \Parable\DI\Container::get(\Parable\Framework\ConsoleApp::class);
$consoleApp->setErrorReportingEnabled(true);
$consoleApp->run();
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/</directory>
<exclude>
<file>./src/Framework/Bootstrap.php</file>
<file>./src/defines.php</file>
<file>./src/Console/Input.php</file>
<file>./src/GetSet/Session.php</file>
<file>./src/Framework/Command/InitStructure.php</file>
Expand Down
39 changes: 35 additions & 4 deletions src/Console/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public function __construct(

set_exception_handler(function ($e) {
// @codeCoverageIgnoreStart

/** @var \Exception $e */
$this->output->writeErrorBlock($e->getMessage());

if ($this->activeCommand) {
$this->output->writeln("<yellow>Usage</yellow>: " . $this->activeCommand->getUsage());
$this->output->writeln('<yellow>Usage</yellow>: ' . $this->activeCommand->getUsage());
}
// @codeCoverageIgnoreEnd
});
Expand Down Expand Up @@ -109,19 +111,21 @@ public function addCommands(array $commands)
*/
public function setDefaultCommandByName($commandName)
{
$this->defaultCommand = $commandName;
$this->defaultCommand = $commandName;
return $this;
}

/**
* Set the default command to use if no command is given.
* Set the default command to use if no command is given. Also
* adds the command.
*
* @param \Parable\Console\Command $command
*
* @return $this
*/
public function setDefaultCommand(\Parable\Console\Command $command)
{
$this->addCommand($command);
$this->setDefaultCommandByName($command->getName());
return $this;
}
Expand Down Expand Up @@ -149,6 +153,18 @@ public function shouldOnlyUseDefaultCommand()
return $this->onlyUseDefaultCommand;
}

/**
* Returns whether the $commandName is registered.
*
* @param string $commandName
*
* @return bool
*/
public function hasCommand($commandName)
{
return isset($this->commands[$commandName]);
}

/**
* Return the command by name if it's set on the application.
*
Expand All @@ -158,7 +174,7 @@ public function shouldOnlyUseDefaultCommand()
*/
public function getCommand($commandName)
{
if (isset($this->commands[$commandName])) {
if ($this->hasCommand($commandName)) {
return $this->commands[$commandName];
}
return null;
Expand All @@ -174,6 +190,21 @@ public function getCommands()
return $this->commands;
}

/**
* Remove a command by name.
*
* @param string $commandName
*
* @return $this
*/
public function removeCommandByName($commandName)
{
if ($this->hasCommand($commandName)) {
unset($this->commands[$commandName]);
}
return $this;
}

/**
* Run the application.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function getUsage()
if ($argument->isRequired()) {
$string[] = $argument->getName();
} else {
$string[] = "[" . $argument->getName() . "]";
$string[] = "[{$argument->getName()}]";
}
}

Expand All @@ -209,7 +209,7 @@ public function getUsage()
$string[] = "[--{$optionString}]";
}

return implode(" ", $string);
return implode(' ', $string);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Console/Command/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Help extends \Parable\Console\Command

public function __construct()
{
$this->addArgument("command_name");
$this->addArgument('command_name');
}

/**
Expand All @@ -27,9 +27,9 @@ public function run()
$this->output->newline();
}

$commandName = $this->parameter->getArgument("command_name");
$commandName = $this->parameter->getArgument('command_name');
if ($commandName) {
$this->showCommandHelp($this->parameter->getArgument("command_name"));
$this->showCommandHelp($this->parameter->getArgument('command_name'));
} else {
$this->showGeneralHelp();
}
Expand Down
7 changes: 3 additions & 4 deletions src/Console/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public function disableShowInput()
* Request input from the user, while hiding the actual input. Use this to request passwords, for example.
*
* @return string
*
* @throws \Parable\Console\Exception
*/
public function getHidden()
Expand Down Expand Up @@ -165,14 +164,14 @@ public function getYesNo($default = true)
$value = strtolower($this->get());

// Y/N values are ALWAYS directly returned as true/false
if ($value == 'y') {
if ($value === 'y') {
return true;
} elseif ($value == 'n') {
} elseif ($value === 'n') {
return false;
}

// If no value, we return the default value
if ($value == '') {
if (empty($value)) {
return (bool)$default;
}

Expand Down
Loading

0 comments on commit 795506d

Please sign in to comment.