* @package generis */ class MicrotimeRandUriProvider extends ConfigurableService implements UriProvider { const OPTION_PERSISTENCE = 'persistence'; const OPTION_NAMESPACE = 'namespace'; // --- ASSOCIATIONS --- // --- ATTRIBUTES --- // --- OPERATIONS --- /** * @return common_persistence_SqlPersistence */ public function getPersistence() { return $this->getServiceLocator()->get(PersistenceManager::SERVICE_ID)->getPersistenceById($this->getOption(self::OPTION_PERSISTENCE)); } /** * Generates a URI based on the value of PHP microtime() and rand(). * * @access public * @author Jerome Bogaerts, * @return string */ public function provide() { $uriExist = false; do { list($usec, $sec) = explode(" ", microtime()); $uri = $this->getOption(self::OPTION_NAMESPACE) . 'i' . (str_replace(".", "", $sec . "" . $usec)) . rand(0, 1000); $sqlResult = $this->getPersistence()->query("SELECT COUNT(subject) AS num FROM statements WHERE subject = '" . $uri . "'"); if ($row = $sqlResult->fetch()) { $uriExist = $row['num'] > 0; $sqlResult->closeCursor(); } } while ($uriExist); return (string) $uri; } }