for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the puli/repository package.
*
* (c) Bernhard Schussek <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Puli\Repository\ChangeStream;
use Puli\Repository\Api\Resource\PuliResource;
use Puli\Repository\Api\ResourceRepository;
/**
* Stream to track repositories changes and fetch previous versions of resources.
* @since 1.0
* @author Titouan Galopin <[email protected]>
class ChangeStream
{
* @var array
private $stack = array();
* Store a version of a resource in the ChangeStream to retrieve it if needed.
* @param string $path
* @param PuliResource $resource
public function log($path, PuliResource $resource)
if (!array_key_exists($path, $this->stack)) {
$this->stack[$path] = array();
}
$this->stack[$path][] = serialize($resource);
* Create a stack of resources for the given path.
* @param ResourceRepository $repository
* @return ResourceStack
public function buildResourceStack(ResourceRepository $repository, $path)
$stack = array();
if (isset($this->stack[$path]) && is_array($this->stack[$path])) {
foreach ($this->stack[$path] as $data) {
$resource = unserialize($data);
$resource->attachTo($repository, $path);
$stack[] = $resource;
return new ResourceStack($stack);