cs Iterator & Mediator

This commit is contained in:
Dominik Liebler
2013-09-12 11:20:27 +02:00
parent 032cc57cf6
commit 1c9a83bea1
2 changed files with 34 additions and 19 deletions

View File

@@ -22,9 +22,9 @@ namespace DesignPatterns;
class File class File
{ {
/** /**
* @var Rowset * @var RowSet
*/ */
protected $rowset; protected $rowSet;
/** /**
* @var string * @var string
@@ -36,26 +36,35 @@ class File
*/ */
public function __construct($pathName) public function __construct($pathName)
{ {
$this->rowset = new Rowset($this); $this->rowSet = new Rowset($this);
} }
public function process() public function process()
{ {
// this is the place to show how using an iterator, with foreach // this is the place to show how using an iterator, with foreach
// See the CardGame.php file // See the CardGame.php file
$this->rowset->process(); $this->rowSet->process();
} }
} }
class Rowset implements \Iterator class Rowset implements \Iterator
{ {
protected $_currentRow; /**
* @var
*/
protected $currentRow;
protected $_file; /**
* @var string
*/
protected $file;
/**
* @param string $file
*/
public function __construct($file) public function __construct($file)
{ {
$this->_file = $file; $this->file = $file;
} }
/** /**
@@ -81,28 +90,28 @@ class Rowset implements \Iterator
public function rewind() public function rewind()
{ {
// seek to first line from $this->_file // seek to first line from $this->file
} }
public function next() public function next()
{ {
// read the next line from $this->_file // read the next line from $this->file
if (!$eof) { if (!$eof) {
$data = ''; // get the line $data = ''; // get the line
$this->_currentRow = new Row($data); $this->currentRow = new Row($data);
} else { } else {
$this->_currentRow = null; $this->currentRow = null;
} }
} }
public function current() public function current()
{ {
return $this->_currentRow; return $this->currentRow;
} }
public function valid() public function valid()
{ {
return null !== $this->_currentRow; return null !== $this->currentRow;
} }
public function key() public function key()

View File

@@ -1,9 +1,5 @@
<?php <?php
/*
* DesignPatternPHP
*/
namespace DesignPatterns\Mediator; namespace DesignPatterns\Mediator;
/** /**
@@ -12,10 +8,20 @@ namespace DesignPatterns\Mediator;
*/ */
interface MediatorInterface interface MediatorInterface
{ {
/**
* sends the response
*
* @param string $content
*/
function sendResponse($content); function sendResponse($content);
/**
* makes a request
*/
function makeRequest(); function makeRequest();
/**
* queries the DB
*/
function queryDb(); function queryDb();
} }