106 lines
1.6 KiB
PHP
106 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace CoursEndingBundle;
|
|
|
|
/**
|
|
* Class DataRestContainer
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
*/
|
|
class DataRestContainer
|
|
{
|
|
/**
|
|
* @var int
|
|
*/
|
|
protected $count;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $type;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $class;
|
|
|
|
/**
|
|
* @var mixed
|
|
*/
|
|
protected $data;
|
|
|
|
/**
|
|
* @param mixed $data
|
|
*/
|
|
public function __construct($data)
|
|
{
|
|
$this->setData($data);
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
protected function count()
|
|
{
|
|
$data = $this->getData();
|
|
|
|
if (null === $data) {
|
|
return $this->count = 0;
|
|
}
|
|
|
|
if (is_array($data)) {
|
|
return $this->count = count($data);
|
|
}
|
|
|
|
if (is_object($data)) {
|
|
if ($data instanceof \Traversable) {
|
|
return $this->count = count($data);
|
|
}
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function type()
|
|
{
|
|
$this->type = gettype($this->data);
|
|
|
|
if ($this->type === 'object') {
|
|
$this->class = get_class($this->data);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param mixed $data
|
|
* @return DataRestContainer
|
|
*/
|
|
public function setData($data)
|
|
{
|
|
$this->data = $data;
|
|
|
|
$this->count();
|
|
$this->type();
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return mixed $data
|
|
*/
|
|
public function getData()
|
|
{
|
|
return $this->data;
|
|
}
|
|
|
|
/**
|
|
* @var int
|
|
*/
|
|
public function getCount()
|
|
{
|
|
return $this->count;
|
|
}
|
|
}
|
|
|