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

Remove usage of Timber\PostCollection in Repository #78

Merged
merged 2 commits into from
Jan 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
titouanmathis marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Should we keep ArrayObject as an allowed type?

The PostQuery and PostCollection classes are base on PHP's ArrayObject class. Allowing the usage of ArrayObject results could help implement PostCollection or PostQuery in child classes.

Maybe we can discuss this next monday?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, can plan a meeting on the topic !
There is no PostQuery or PostCollection logic in this class since the do_query() method is to implement.
This could lead to some implementation with direct SQL query with wpdb for example

* @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