FOSElasticaBundle/Provider/AbstractProvider.php

57 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace FOS\ElasticaBundle\Provider;
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
2014-02-19 12:58:02 +01:00
/**
* AbstractProvider
*/
abstract class AbstractProvider implements ProviderInterface
{
2014-02-19 12:58:02 +01:00
/**
* @var ObjectPersisterInterface
*/
protected $objectPersister;
2014-02-19 12:58:02 +01:00
/**
* @var string
*/
protected $objectClass;
/**
* @var array
*/
protected $options;
/**
* Constructor.
*
* @param ObjectPersisterInterface $objectPersister
* @param string $objectClass
* @param array $options
*/
public function __construct(ObjectPersisterInterface $objectPersister, $objectClass, array $options = array())
{
$this->objectPersister = $objectPersister;
$this->objectClass = $objectClass;
$this->options = array_merge(array(
'batch_size' => 100,
), $options);
}
/**
* Get string with RAM usage information (current and peak)
*
* @return string
*/
2014-02-19 09:31:22 +01:00
protected function getMemoryUsage()
{
2014-02-19 12:58:02 +01:00
$memory = round(memory_get_usage() / (1024 * 1024)); // to get usage in Mo
$memoryMax = round(memory_get_peak_usage() / (1024 * 1024)); // to get max usage in Mo
2014-02-19 09:31:22 +01:00
2014-02-19 12:58:02 +01:00
return sprintf('(RAM : current=%uMo peak=%uMo)', $memory, $memoryMax);
}
}