-
-
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.
Added
Grav\Common\Media
interfaces and trait; use those in Page
a…
…nd `Media` classes Added `Grav\Common\Page` interface to allow custom page types in the future
- Loading branch information
Showing
9 changed files
with
147 additions
and
26 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
9 changes: 9 additions & 0 deletions
9
system/src/Grav/Common/Media/Interfaces/MediaCollectionInterface.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,9 @@ | ||
<?php | ||
namespace Grav\Common\Media\Interfaces; | ||
|
||
/** | ||
* Class implements media collection interface. | ||
*/ | ||
interface MediaCollectionInterface | ||
{ | ||
} |
22 changes: 22 additions & 0 deletions
22
system/src/Grav/Common/Media/Interfaces/MediaInterface.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,22 @@ | ||
<?php | ||
namespace Grav\Common\Media\Interfaces; | ||
|
||
/** | ||
* Class implements media interface. | ||
*/ | ||
interface MediaInterface | ||
{ | ||
/** | ||
* Gets the associated media collection. | ||
* | ||
* @return MediaCollectionInterface Collection of associated media. | ||
*/ | ||
public function getMedia(); | ||
|
||
/** | ||
* Get filesystem path to the associated media. | ||
* | ||
* @return string|null Media path or null if the object doesn't have media folder. | ||
*/ | ||
public function getMediaFolder(); | ||
} |
9 changes: 9 additions & 0 deletions
9
system/src/Grav/Common/Media/Interfaces/MediaObjectInterface.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,9 @@ | ||
<?php | ||
namespace Grav\Common\Media\Interfaces; | ||
|
||
/** | ||
* Class implements media object interface. | ||
*/ | ||
interface MediaObjectInterface | ||
{ | ||
} |
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,60 @@ | ||
<?php | ||
namespace Grav\Common\Media\Traits; | ||
|
||
use Grav\Common\Cache; | ||
use Grav\Common\Grav; | ||
use Grav\Common\Media\Interfaces\MediaCollectionInterface; | ||
use Grav\Common\Page\Media; | ||
|
||
trait MediaTrait | ||
{ | ||
protected $media; | ||
|
||
/** | ||
* Get filesystem path to the associated media. | ||
* | ||
* @return string|null | ||
*/ | ||
abstract public function getMediaFolder(); | ||
|
||
/** | ||
* Gets the associated media collection. | ||
* | ||
* @return MediaCollectionInterface Representation of associated media. | ||
*/ | ||
public function getMedia() | ||
{ | ||
/** @var Cache $cache */ | ||
$cache = Grav::instance()['cache']; | ||
|
||
if ($this->media === null) { | ||
// Use cached media if possible. | ||
$cacheKey = md5('media' . $this->getCacheKey()); | ||
if (!$media = $cache->fetch($cacheKey)) { | ||
$media = new Media($this->getMediaFolder()); | ||
$cache->save($cacheKey, $media); | ||
} | ||
$this->media = $media; | ||
} | ||
|
||
return $this->media; | ||
} | ||
|
||
/** | ||
* Sets the associated media collection. | ||
* | ||
* @param MediaCollectionInterface $media Representation of associated media. | ||
* @return $this | ||
*/ | ||
protected function setMedia(MediaCollectionInterface $media) | ||
{ | ||
$this->media = $media; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
abstract protected function getCacheKey(); | ||
} |
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,9 @@ | ||
<?php | ||
namespace Grav\Common\Page\Interfaces; | ||
|
||
/** | ||
* Class implements page interface. | ||
*/ | ||
interface PageInterface | ||
{ | ||
} |
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