This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created AbstractRepository to force fetchAll to return a LinkedVersio…
…ns collection.
- Loading branch information
Showing
4 changed files
with
111 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <https://github.com/baleen/migrations>. | ||
*/ | ||
|
||
namespace Baleen\Migrations\Exception; | ||
|
||
/** | ||
* Class RepositoryException | ||
* @author Gabriel Somoza <gabriel@strategery.io> | ||
*/ | ||
class RepositoryException extends BaleenException | ||
{ | ||
} |
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,71 @@ | ||
<?php | ||
|
||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <https://github.com/baleen/migrations>. | ||
*/ | ||
|
||
namespace Baleen\Migrations\Repository; | ||
|
||
use Baleen\Migrations\Exception\RepositoryException; | ||
use Baleen\Migrations\Migration\Factory\FactoryInterface; | ||
use Baleen\Migrations\Version\Collection\LinkedVersions; | ||
|
||
/** | ||
* Class AbstractRepository | ||
* @author Gabriel Somoza <gabriel@strategery.io> | ||
*/ | ||
abstract class AbstractRepository implements RepositoryInterface | ||
{ | ||
|
||
/** | ||
* @var FactoryInterface | ||
*/ | ||
protected $factory; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setMigrationFactory(FactoryInterface $factory) | ||
{ | ||
$this->factory = $factory; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @return LinkedVersions | ||
* @throws RepositoryException | ||
*/ | ||
public function fetchAll() | ||
{ | ||
$result = $this->doFetchAll(); | ||
if (!is_object($result) || !$result instanceof LinkedVersions) { | ||
throw new RepositoryException( | ||
'Method AbstractRepository::doFetchAll() must return a LinkedVersions object' | ||
); | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* Must fetch all versions available to the repository, load them with their migrations, and return them as a | ||
* LinkedVersions collection. It must use a factory (default or supplied by 'setMigrationFactory()') to instantiate | ||
* each of the migrations. | ||
* | ||
* @return mixed | ||
*/ | ||
abstract protected function doFetchAll(); | ||
} |
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