Skip to content

Commit

Permalink
moved oxygen/theme into this repo, fixed more phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
neon64 committed Mar 20, 2022
1 parent 6937ce5 commit 25706bc
Show file tree
Hide file tree
Showing 20 changed files with 522 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ All parts of the framework depend on the Laravel framework to varying degrees.
- [oxygen/data](https://github.com/oxygen-cms/data) - wrapper around Doctrine ORM
- [oxygen/core](https://github.com/oxygen-cms/core) - core framework, depends on *oxygen/data*
- [oxygen/crud](https://github.com/oxygen-cms/crud) - scaffolding for Create-Read-Update-Delete operations, depends on *oxygen/data* and *oxygen/core*
- [oxygen/theme](https://github.com/oxygen-cms/theme) - theming support - doesn't depend on any oxygen packages
- [oxygen/preferences](https://github.com/oxygen-cms/preferences) - dynamic preferences configuration, depends on *oxygen/core*, *oxygen/data*, *oxygen/theme*
- [oxygen/auth](https://github.com/oxygen-cms/auth) - authentication, depends on *oxygen/core*, *oxygen/data*, *oxygen/preferences*

**Basic modules** - each of these adds some optional part of the backend interface, they can be mixed and matched as you please.

- [oxygen/mod-auth](https://github.com/oxygen-cms/mod-auth) - authentication - this one is pretty necessary to be able to access the backend interface
- [oxygen/mod-import-export](https://github.com/oxygen-cms/mod-import-export) - import/export database content

Things which the CMS can store:
Expand All @@ -39,6 +37,8 @@ Things which the CMS can store:

Deprecated:

- [oxygen/theme](https://github.com/oxygen-cms/theme) - theming support - integrated into oxygen/core
- [oxygen/mod-auth](https://github.com/oxygen-cms/mod-auth) - authentication - integrated into oxygen/auth (user-interface into [oxygen-cms/ui](https://github.com/oxygen-cms/ui))
- *oxygen/mod-preferences* - preferences UI - **integrated into Vue.JS user interface**
- *oxygen/mod-dashboard* - admin dashboard - **integrated into new Vue.JS user interface**
- *oxygen/mod-security* - a basic log of all login attempts - **now integrated into the authentication module**
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"Oxygen\\Core\\Console\\ConsoleServiceProvider",
"Oxygen\\Core\\Translation\\TranslationServiceProvider",
"Oxygen\\Core\\Templating\\TemplatingServiceProvider",
"Oxygen\\Core\\Form\\FormServiceProvider"
"Oxygen\\Core\\Form\\FormServiceProvider",
"Oxygen\\Core\\Theme\\ThemeServiceProvider"
]
}
},
Expand All @@ -45,6 +46,6 @@
"phpspec/phpspec": "^6.1"
},
"scripts": {
"test": "vendor/bin/phpspec run && vendor/bin/phpstan analyze src --level 1"
"test": "vendor/bin/phpspec run && vendor/bin/phpstan analyze src --level 2"
}
}
37 changes: 37 additions & 0 deletions spec/Theme/ThemeManagerSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace spec\Oxygen\Core\Theme;

use Oxygen\Core\Theme\CurrentThemeLoader;
use Oxygen\Core\Theme\Theme;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class ThemeManagerSpec extends ObjectBehavior {

function let(\Oxygen\Core\Theme\CurrentThemeLoader $loader) {
$this->beConstructedWith($loader);
}

function it_is_initializable() {
$this->shouldHaveType('Oxygen\Core\Theme\ThemeManager');
}

function it_can_store_themes(\Oxygen\Core\Theme\Theme $theme) {
$theme->getKey()->willReturn('foo');
$this->register($theme);
$this->all()->shouldReturn(['foo' => $theme]);
}

function it_can_make_themes() {
$this->make([
'key' => 'fantasticTheme',
'name' => 'FANTASTIC Theme',
'provides' => [
'foo' => 'bar'
]
]);
$this->all()->shouldHaveCount(1);
}

}
51 changes: 51 additions & 0 deletions spec/Theme/ThemeSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace spec\Oxygen\Core\Theme;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class ThemeSpec extends ObjectBehavior {

function let() {
$this->beConstructedWith('testTheme');
}

function it_is_initializable() {
$this->shouldHaveType('Oxygen\Core\Theme\Theme');
}

function it_has_a_key() {
$this->getKey()->shouldReturn('testTheme');
}

function it_has_a_name() {
$this->setName('Test Theme');
$this->getName()->shouldReturn('Test Theme');
}

function it_can_provide_things() {
$this->getProvides()->shouldHaveCount(0);
$this->provides('foo', 'bar');
$this->getProvides()->shouldBe(['foo' => 'bar']);
}

function it_can_have_an_image() {
$this->hasImage()->shouldReturn(false);
$this->setImage('image');
$this->getImage()->shouldReturn('image');
$this->hasImage()->shouldReturn(true);
}

function it_can_be_filled_from_an_array() {
$this->fillFromArray([
'name' => 'Other Theme',
'provides' => [
'other' => 'option'
]
]);
$this->getName()->shouldReturn('Other Theme');
$this->getProvides()->shouldReturn(['other' => 'option']);
}

}
2 changes: 1 addition & 1 deletion src/Blueprint/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public function getDefaultActionFactory() {
* Gets the toolbar items for a
* particular toolbar group.
*
* @param string
* @param string $group
* @return mixed
*/
public function getToolbarOrder($group) {
Expand Down
3 changes: 2 additions & 1 deletion src/Factory/FactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ interface FactoryInterface {
* Creates a new object using the passed parameters.
*
* @param array $parameters Passed parameters
* @param string|null $controller Default controller to use
* @return mixed
*/
public function create(array $parameters);
public function create(array $parameters, string $controller = null);

}
4 changes: 2 additions & 2 deletions src/Html/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Form implements RenderableInterface {
/**
* The id of the form.
*
* @var
* @var string|null
*/
protected $id;

Expand All @@ -88,7 +88,7 @@ public function __construct(Action $action) {
/**
* Sets the arguments that will be passed to $action->getRouteParameters() later on
*
* @param $arguments
* @param array $arguments
*/
public function setRouteParameterArguments($arguments) {
$this->routeParameterArguments = $arguments;
Expand Down
2 changes: 1 addition & 1 deletion src/Html/Form/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getItems() {
/**
* Adds a custom class to the row.
*
* @param $name
* @param string $name
*/
public function addClass($name) {
$this->extraClasses[] = $name;
Expand Down
2 changes: 2 additions & 0 deletions src/Html/RenderableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Oxygen\Core\Html;

use Exception;

interface RenderableInterface {

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Html/Toolbar/Factory/ButtonToolbarItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class ButtonToolbarItemFactory implements FactoryInterface {
* Creates a new toolbar item using the passed parameters.
*
* @param array $parameters Passed parameters
* @param string|null $controller default controller to use
* @return ButtonToolbarItem
*/
public function create(array $parameters) {
public function create(array $parameters, string $controller = null) {
$toolbarItem = new ButtonToolbarItem($parameters['label'], $parameters['action']);
unset($parameters['label'], $parameters['action']);
foreach($parameters as $key => $value) {
Expand Down
3 changes: 2 additions & 1 deletion src/Html/Toolbar/Factory/FormToolbarItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class FormToolbarItemFactory implements FactoryInterface {
* Creates a new toolbar item using the passed parameters.
*
* @param array $parameters Passed parameters
* @param string|null $controller Default controller to use
* @return FormToolbarItem
*/
public function create(array $parameters) {
public function create(array $parameters, string $controller = null) {
$toolbarItem = new FormToolbarItem($parameters['action']);
unset($parameters['action']);
foreach($parameters as $key => $value) {
Expand Down
3 changes: 2 additions & 1 deletion src/Html/Toolbar/Factory/VoidButtonToolbarItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class VoidButtonToolbarItemFactory implements FactoryInterface {
* Creates a new toolbar item using the passed parameters.
*
* @param array $parameters Passed parameters
* @param string|null $controller Default controller to use
* @return VoidButtonToolbarItem
*/
public function create(array $parameters) {
public function create(array $parameters, string $controller = null) {
$toolbarItem = new VoidButtonToolbarItem($parameters['label'], $parameters['action']);
unset($parameters['label'], $parameters['action']);
foreach($parameters as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Html/Toolbar/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function setPrefix($prefix) {
/**
* Sets a shared items pool for the toolbar.
*
* @param $items
* @param array $items
* @return void
*/
public function setSharedItemsPool(&$items) {
Expand Down
1 change: 1 addition & 0 deletions src/Html/Toolbar/ToolbarItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Oxygen\Core\Html\Toolbar;

use Oxygen\Core\Html\RenderableInterface;
use Oxygen\Core\Html\RendererInterface;

interface ToolbarItem extends RenderableInterface {

Expand Down
42 changes: 42 additions & 0 deletions src/Theme/BootThemeMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Oxygen\Core\Theme;

use Closure;

class BootThemeMiddleware {

/**
* The theme manager.
*
* @var ThemeManager
*/
protected $themeManager;

/**
* Create a new filter instance.
*
* @param ThemeManager $themes
*/
public function __construct(ThemeManager $themes) {
$this->themeManager = $themes;
}

/**
* Handle an incoming request.
*
* @param mixed $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next) {
try {
$currentTheme = $this->themeManager->current();
$currentTheme->boot();
} catch(ThemeNotFoundException $e) {
// no theme to boot
}

return $next($request);
}
}
21 changes: 21 additions & 0 deletions src/Theme/CurrentThemeLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Oxygen\Core\Theme;

interface CurrentThemeLoader {

/**
* Returns the current theme.
*
* @return string
*/
public function getCurrentTheme(): string;

/**
* Changes the current theme.
*
* @param string $theme the name of the new theme
*/
public function setCurrentTheme(string $theme);

}
Loading

0 comments on commit 25706bc

Please sign in to comment.