-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed
FlexObject::triggerEvent()
does not emit events [#2816]
- Loading branch information
Showing
37 changed files
with
797 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
system/src/Grav/Common/Flex/Traits/FlexCollectionTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @package Grav\Common\Flex | ||
* | ||
* @copyright Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved. | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Common\Flex\Traits; | ||
|
||
use RocketTheme\Toolbox\Event\Event; | ||
|
||
/** | ||
* Trait FlexCollectionTrait | ||
* @package Grav\Common\Flex\Traits | ||
*/ | ||
trait FlexCollectionTrait | ||
{ | ||
use FlexCommonTrait; | ||
|
||
/** | ||
* @param string $name | ||
* @param object|null $event | ||
* @return $this | ||
*/ | ||
public function triggerEvent(string $name, $event = null) | ||
{ | ||
if (null === $event) { | ||
$event = new Event(['collection' => $this]); | ||
} | ||
if (strpos($name, 'onFlexCollection') !== 0 && strpos($name, 'on') === 0) { | ||
$name = 'onFlexCollection' . substr($name, 2); | ||
} | ||
|
||
$container = $this->getContainer(); | ||
$container->fireEvent($name, $event); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @package Grav\Common\Flex | ||
* | ||
* @copyright Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved. | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Common\Flex\Traits; | ||
|
||
use Grav\Common\Debugger; | ||
use Grav\Common\Grav; | ||
use Grav\Common\Twig\Twig; | ||
use Twig\Error\LoaderError; | ||
use Twig\Error\SyntaxError; | ||
use Twig\Template; | ||
use Twig\TemplateWrapper; | ||
|
||
/** | ||
* Trait FlexCommonTrait | ||
* @package Grav\Common\Flex\Traits | ||
*/ | ||
trait FlexCommonTrait | ||
{ | ||
/** | ||
* @param string $layout | ||
* @return Template|TemplateWrapper | ||
* @throws LoaderError | ||
* @throws SyntaxError | ||
*/ | ||
protected function getTemplate($layout) | ||
{ | ||
$container = $this->getContainer(); | ||
|
||
/** @var Twig $twig */ | ||
$twig = $container['twig']; | ||
|
||
try { | ||
return $twig->twig()->resolveTemplate($this->getTemplatePaths($layout)); | ||
} catch (LoaderError $e) { | ||
/** @var Debugger $debugger */ | ||
$debugger = Grav::instance()['debugger']; | ||
$debugger->addException($e); | ||
|
||
return $twig->twig()->resolveTemplate(['flex/404.html.twig']); | ||
} | ||
} | ||
|
||
abstract protected function getTemplatePaths(string $layout): array; | ||
abstract protected function getContainer(): Grav; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @package Grav\Common\Flex | ||
* | ||
* @copyright Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved. | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Common\Flex\Traits; | ||
|
||
use Grav\Common\Grav; | ||
use Grav\Common\User\Interfaces\UserInterface; | ||
use Grav\Framework\Flex\Flex; | ||
|
||
/** | ||
* Implements Grav specific logic | ||
*/ | ||
trait FlexGravTrait | ||
{ | ||
/** | ||
* @return Grav | ||
*/ | ||
protected function getContainer(): Grav | ||
{ | ||
return Grav::instance(); | ||
} | ||
|
||
/** | ||
* @return Flex | ||
*/ | ||
protected function getFlexContainer(): Flex | ||
{ | ||
$container = $this->getContainer(); | ||
|
||
/** @var Flex $flex */ | ||
$flex = $container['flex']; | ||
|
||
return $flex; | ||
} | ||
|
||
/** | ||
* @return UserInterface|null | ||
*/ | ||
protected function getActiveUser(): ?UserInterface | ||
{ | ||
$container = $this->getContainer(); | ||
|
||
/** @var UserInterface|null $user */ | ||
$user = $container['user'] ?? null; | ||
|
||
return $user; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
protected function isAdminSite(): bool | ||
{ | ||
$container = $this->getContainer(); | ||
|
||
return isset($container['admin']); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getAuthorizeScope(): string | ||
{ | ||
return $this->isAdminSite() ? 'admin' : 'site'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @package Grav\Common\Flex | ||
* | ||
* @copyright Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved. | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Common\Flex\Traits; | ||
|
||
/** | ||
* Trait FlexIndexTrait | ||
* @package Grav\Common\Flex\Traits | ||
*/ | ||
trait FlexIndexTrait | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @package Grav\Common\Flex | ||
* | ||
* @copyright Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved. | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Common\Flex\Traits; | ||
|
||
use RocketTheme\Toolbox\Event\Event; | ||
|
||
/** | ||
* Trait FlexObjectTrait | ||
* @package Grav\Common\Flex\Traits | ||
*/ | ||
trait FlexObjectTrait | ||
{ | ||
use FlexCommonTrait; | ||
|
||
/** | ||
* @param string $name | ||
* @param object|null $event | ||
* @return $this | ||
*/ | ||
public function triggerEvent(string $name, $event = null) | ||
{ | ||
if (null === $event) { | ||
$event = new Event(['object' => $this]); | ||
} | ||
if (strpos($name, 'onFlexObject') !== 0 && strpos($name, 'on') === 0) { | ||
$name = 'onFlexObject' . substr($name, 2); | ||
} | ||
|
||
$container = $this->getContainer(); | ||
$container->fireEvent($name, $event); | ||
|
||
return $this; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
system/src/Grav/Common/Flex/Types/Generic/GenericCollection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @package Grav\Common\Flex | ||
* | ||
* @copyright Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved. | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Common\Flex\Types\Generic; | ||
|
||
use Grav\Common\Flex\Traits\FlexCollectionTrait; | ||
use Grav\Common\Flex\Traits\FlexGravTrait; | ||
use Grav\Framework\Flex\FlexCollection; | ||
|
||
/** | ||
* Class GenericCollection | ||
* @package Grav\Common\Flex\Generic | ||
*/ | ||
class GenericCollection extends FlexCollection | ||
{ | ||
use FlexGravTrait; | ||
use FlexCollectionTrait; | ||
} |
26 changes: 26 additions & 0 deletions
26
system/src/Grav/Common/Flex/Types/Generic/GenericIndex.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @package Grav\Common\Flex | ||
* | ||
* @copyright Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved. | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Common\Flex\Types\Generic; | ||
|
||
use Grav\Common\Flex\Traits\FlexGravTrait; | ||
use Grav\Common\Flex\Traits\FlexIndexTrait; | ||
use Grav\Framework\Flex\FlexIndex; | ||
|
||
/** | ||
* Class GenericIndex | ||
* @package Grav\Common\Flex\Generic | ||
*/ | ||
class GenericIndex extends FlexIndex | ||
{ | ||
use FlexGravTrait; | ||
use FlexIndexTrait; | ||
} |
26 changes: 26 additions & 0 deletions
26
system/src/Grav/Common/Flex/Types/Generic/GenericObject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @package Grav\Common\Flex | ||
* | ||
* @copyright Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved. | ||
* @license MIT License; see LICENSE file for details. | ||
*/ | ||
|
||
namespace Grav\Common\Flex\Types\Generic; | ||
|
||
use Grav\Common\Flex\Traits\FlexGravTrait; | ||
use Grav\Common\Flex\Traits\FlexObjectTrait; | ||
use Grav\Framework\Flex\FlexObject; | ||
|
||
/** | ||
* Class GenericObject | ||
* @package Grav\Common\Flex\Generic | ||
*/ | ||
class GenericObject extends FlexObject | ||
{ | ||
use FlexGravTrait; | ||
use FlexObjectTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.