for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* This file is part of the Packagist Mirror.
*
* For the full license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Webs\Mirror;
use PHPSnippets\DataStructures\CircularArray;
/**
* Middleware to http operations.
* @author Webysther Nunes <[email protected]>
class Mirror
{
* @var string
protected $master;
* @var array
protected $slaves;
* @var CircularArray
protected $all;
protected $data;
* @param string $master
* @param array $slaves
public function __construct(string $master, array $slaves)
$this->master = $master;
$this->slaves = $slaves;
$this->data = [];
foreach ($slaves as $value) {
if(empty($value) || !filter_var($value, FILTER_VALIDATE_URL)){
continue;
}
$this->data[] = $value;
if (!in_array($master, $this->data)) {
$this->data[] = $master;
$this->all = CircularArray::fromArray($this->data);
* @return string
public function getMaster():string
return $this->master;
* Get all mirrors.
* @return CircularArray
public function getAll():CircularArray
return $this->all;
* Get next item.
public function getNext():string
$this->all->next();
return $this->all->current();
* @param string $value
public function remove(string $value):CircularArray
$this->data = array_values(array_diff($this->data, [$value]));
return $this->getAll();
* @return array
public function toArray():array
return $this->getAll()->toArray();