-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added SEQUENCE support to calendar events, refactored calendar to all…
…ow batch production of events during stream export
- Loading branch information
Showing
7 changed files
with
278 additions
and
32 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace Jsvrcek\ICS\Utility; | ||
|
||
class Provider implements \Iterator | ||
{ | ||
/** | ||
* | ||
* @var \Closure | ||
*/ | ||
private $provider; | ||
|
||
/** | ||
* | ||
* @var array | ||
*/ | ||
public $data = array(); | ||
|
||
/** | ||
* | ||
* @var array | ||
*/ | ||
public $manuallyAddedData = array(); | ||
|
||
/** | ||
* | ||
* @var integer | ||
*/ | ||
private $key; | ||
|
||
/** | ||
* @param \Closure $provider An optional closure for adding items in batches during iteration. The closure will be | ||
* called each time the end of the internal data array is reached during iteration, and the current data | ||
* array key value will be passed as an argument. The closure should return an array containing the next | ||
* batch of items. | ||
*/ | ||
public function __construct(\Closure $provider = null) | ||
{ | ||
$this->provider = $provider; | ||
} | ||
|
||
/** | ||
* for manually adding items, rather than using a provider closure to add items in batches during iteration | ||
* Cannot be used in conjunction with a provider closure! | ||
* | ||
* @param mixed $item | ||
*/ | ||
public function add($item) | ||
{ | ||
$this->manuallyAddedData[] = $item; | ||
} | ||
|
||
/* (non-PHPdoc) | ||
* @see Iterator::current() | ||
*/ | ||
public function current() | ||
{ | ||
return current($this->data); | ||
} | ||
|
||
/* (non-PHPdoc) | ||
* @see Iterator::key() | ||
*/ | ||
public function key() | ||
{ | ||
return $this->key; | ||
} | ||
|
||
/* (non-PHPdoc) | ||
* @see Iterator::next() | ||
*/ | ||
public function next() | ||
{ | ||
array_shift($this->data); | ||
$this->key++; | ||
} | ||
|
||
/* (non-PHPdoc) | ||
* @see Iterator::rewind() | ||
*/ | ||
public function rewind() | ||
{ | ||
$this->data = array(); | ||
$this->key = 0; | ||
} | ||
|
||
/** | ||
* get next batch from provider if data array is at the end | ||
* | ||
* (non-PHPdoc) | ||
* @see Iterator::valid() | ||
*/ | ||
public function valid() | ||
{ | ||
if (count($this->data) < 1) | ||
{ | ||
if ($this->provider instanceof \Closure) | ||
{ | ||
$this->data = $this->provider->__invoke($this->key); | ||
} | ||
else | ||
{ | ||
$this->data = $this->manuallyAddedData; | ||
$this->manuallyAddedData = array(); | ||
} | ||
} | ||
|
||
return count($this->data) > 0; | ||
} | ||
} |
Oops, something went wrong.