Skip to content

Commit

Permalink
:octocat: use chillerlan\Traits\{...}
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Dec 16, 2017
1 parent 7f3ef4a commit 2433b31
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 350 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"php": ">=7.0.3",
"psr/simple-cache": "^1.0",
"chillerlan/php-cache": "1.*",
"chillerlan/php-traits": "1.0.*"
"chillerlan/php-traits": "1.1.*"
},
"require-dev": {
"phpunit/phpunit": "6.4.*"
"phpunit/phpunit": "6.5.*"
},
"autoload": {
"psr-4": {
Expand Down
95 changes: 9 additions & 86 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@

namespace chillerlan\Database;

use ArrayAccess, Countable, Iterator;
use chillerlan\Database\Traits\{Enumerable, Magic};
use ArrayAccess, Countable, SeekableIterator;
use chillerlan\Traits\{
Enumerable, Magic, Interfaces\ArrayAccessTrait, SPL\SeekableIteratorTrait, SPL\CountableTrait
};

/**
* @property int $length
*
* each($func [, $fieldname)
*/
class Result implements Iterator, ArrayAccess, Countable{
use Enumerable, Magic;
class Result implements SeekableIterator, ArrayAccess, Countable{
use ArrayAccessTrait, SeekableIteratorTrait, CountableTrait, Magic, Enumerable;

/**
* @var \chillerlan\Database\ResultRow[]
Expand Down Expand Up @@ -52,11 +54,11 @@ class Result implements Iterator, ArrayAccess, Countable{
*
* @throws \chillerlan\Database\ConnectionException
*/
public function __construct($data = null, $sourceEncoding = null, $destEncoding = 'UTF-8'){
public function __construct($data = null, string $sourceEncoding = null, string $destEncoding = null){
$this->sourceEncoding = $sourceEncoding;
$this->destEncoding = $destEncoding;
$this->destEncoding = $destEncoding ?? 'UTF-8';

if(is_null($data)){
if($data === null){
$data = [];
}
else if($data instanceof \Traversable){
Expand Down Expand Up @@ -130,24 +132,6 @@ protected function magic_get_length():int{
* ArrayAccess *
***************/

/**
* @param int|string $offset
*
* @return bool
*/
public function offsetExists($offset):bool{
return isset($this->array[$offset]);
}

/**
* @param int|string $offset
*
* @return \chillerlan\Database\ResultRow|mixed|null
*/
public function offsetGet($offset){
return $this->array[$offset] ?? null;
}

/**
* @param int|string $offset
* @param array $value
Expand All @@ -165,65 +149,4 @@ public function offsetSet($offset, $value){

}

/**
* @param int|string $offset
*
* @return void
*/
public function offsetUnset($offset){
unset($this->array[$offset]);
}


/*************
* Countable *
*************/

/**
* @return int
*/
public function count():int{
return count($this->array);
}


/************
* Iterator *
************/

/**
* @return \chillerlan\Database\ResultRow|mixed
*/
public function current(){
return $this->offsetGet($this->offset);
}

/**
* @return int
*/
public function key():int{
return $this->offset;
}

/**
* @return bool
*/
public function valid():bool{
return $this->offsetExists($this->offset);
}

/**
* @return void
*/
public function next(){
$this->offset++;
}

/**
* @return void
*/
public function rewind(){
$this->offset = 0;
}

}
56 changes: 0 additions & 56 deletions src/Traits/ClassLoader.php

This file was deleted.

65 changes: 0 additions & 65 deletions src/Traits/Container.php

This file was deleted.

96 changes: 0 additions & 96 deletions src/Traits/Enumerable.php

This file was deleted.

Loading

0 comments on commit 2433b31

Please sign in to comment.