Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge branch 'feature/repository-update' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
perruche committed Jan 19, 2022
2 parents 819fe50 + 0abde0d commit 5b3bb09
Showing 1 changed file with 8 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
<?php
/**
* Parent repository class. Provides a very basic, fluent interface for interacting
* with PostCollection/PostQuery classes.
* Parent repository class. Provides a very basic, fluent interface to interact
* with query
*
* @package Studiometa
*/

namespace Studiometa\Repositories;

use Timber\PostCollection;

/** Class */
abstract class Repository {
/**
* List of posts.
*
* @var array|PostCollection
* @var array
*/
private $result_set = array();

/**
* Returns a list or collection of posts.
* Returns an array of posts.
*
* @return array|PostCollection
* @return array
*/
public function get() {
return $this->result_set;
Expand All @@ -39,28 +37,6 @@ public function first() {
return isset( $local_array[0] ) ? $local_array[0] : null;
}

/**
* Returns a slice of the collection starting at the given index.
* Similar to Laravel's slice().
*
* @param int $start Start index.
*
* @return array
*/
public function slice( $start ) {
$local_array = $this->get();

if ( count( $local_array ) < 1 ) {
return array();
}

if ( is_object( $local_array ) && $local_array instanceof PostCollection ) {
$local_array = $local_array->getArrayCopy();
}

return array_slice( $local_array, (int) $start );
}

/**
* Runs a query.
*
Expand Down Expand Up @@ -97,6 +73,8 @@ protected function query( array $params ) {
*
* @param array $params Query params.
* @return mixed
*
* @example ./app/Repositories/PostRepository.php How to implement do_query().
*/
abstract protected function do_query( $params );

Expand All @@ -113,7 +91,7 @@ protected function reset() {
/**
* Returns current result set
*
* @param array|PostCollection $result_set Result set.
* @param array $result_set Result set.
*
* @return Repository
*/
Expand Down

0 comments on commit 5b3bb09

Please sign in to comment.