firefly-iii/app/Support/ChartProperties.php

77 lines
2.0 KiB
PHP
Raw Normal View History

2015-06-01 11:41:18 -05:00
<?php
namespace FireflyIII\Support;
use Auth;
2015-06-01 11:41:18 -05:00
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection;
use Preferences;
2015-06-01 11:41:18 -05:00
/**
* Class ChartProperties
*
* @package FireflyIII\Support
*/
class ChartProperties
{
/** @var Collection */
protected $properties;
/**
*
*/
public function __construct()
{
$this->properties = new Collection;
$this->addProperty(Auth::user()->id);
$this->addProperty(Preferences::lastActivity());
2015-06-01 11:41:18 -05:00
}
/**
* @param $property
*/
public function addProperty($property)
{
$this->properties->push($property);
}
/**
* @return string
*/
public function md5()
{
$string = '';
//Log::debug('--- building string ---');
2015-06-01 11:41:18 -05:00
foreach ($this->properties as $property) {
if ($property instanceof Collection || $property instanceof EloquentCollection) {
$string .= print_r($property->toArray(), true);
// Log::debug('added collection (size=' . $property->count() . ')');
2015-06-01 11:41:18 -05:00
continue;
}
if ($property instanceof Carbon) {
$string .= $property->toRfc3339String();
// Log::debug('Added time: ' . $property->toRfc3339String());
2015-06-01 11:41:18 -05:00
continue;
}
if (is_object($property)) {
$string .= $property->__toString();
// Log::debug('Added object of class ' . get_class($property));
2015-06-01 11:41:18 -05:00
}
if (is_array($property)) {
$string .= print_r($property, true);
// Log::debug('Added array (size=' . count($property) . ')');
2015-06-01 11:41:18 -05:00
}
$string .= (string)$property;
// Log::debug('Added cast to string: ' . $property);
2015-06-01 11:41:18 -05:00
}
// Log::debug('--- done building string ---');
2015-06-01 11:41:18 -05:00
return md5($string);
}
}