/**
  * @Route("/entry-point/{mac}", defaults={"mac" = null})
  * @Method({"GET", "POST"})
  * @Template()
  */
 public function indexAction(Request $request, $mac)
 {
     // Attempting to do anything here as a logged in user will fail. Set the current user token to null to log user out.
     $this->get('security.token_storage')->setToken(null);
     if (!$mac) {
         if (!$request->getSession()->get('auth-data')) {
             // No MAC code, nothing in the session, so we can't help - return to front page.
             return $this->redirectToRoute('barbon_hostedapi_app_index_index');
         }
     } else {
         $cacheKey = sprintf('mac-%s', $mac);
         // If MAC isn't found in the cache, it's already been processed - redirect back to this route without the MAC, and try again.
         if (!$this->cache->contains($cacheKey)) {
             return $this->redirectToRoute('barbon_hostedapi_landlord_authentication_entrypoint_index');
         }
         // store data to session and empty the cache
         $authData = unserialize($this->cache->fetch($cacheKey));
         $request->getSession()->set('auth-data', $authData);
         $this->cache->delete($cacheKey);
     }
     // Decide which tab should start as visible, so that is a registration attempt is in progress it re-shows that tab.
     $selectedTab = $request->query->get('action') ?: 'register';
     if ($request->isMethod(Request::METHOD_POST)) {
         if ($request->request->has('direct_landlord')) {
             $selectedTab = 'register';
         }
     }
     return array('selectedTab' => $selectedTab);
 }
 /**
  * {@inheritdoc}
  */
 public function removeTags(array $tags)
 {
     foreach ($tags as $tag) {
         // doctrine does not care if the key does not exist.
         $this->cache->delete($tag);
     }
 }
Esempio n. 3
0
 /**
  * Get metadata for a certain class - loads once and caches
  * @param  string                $className
  * @throws \Drest\DrestException
  * @return ClassMetaData         $metaData
  */
 public function getMetadataForClass($className)
 {
     if (isset($this->loadedMetadata[$className])) {
         return $this->loadedMetadata[$className];
     }
     // check the cache
     if ($this->cache !== null) {
         $classMetadata = $this->cache->fetch($this->cache_prefix . $className);
         if ($classMetadata instanceof ClassMetaData) {
             if ($classMetadata->expired()) {
                 $this->cache->delete($this->cache_prefix . $className);
             } else {
                 $this->loadedMetadata[$className] = $classMetadata;
                 return $classMetadata;
             }
         }
     }
     $classMetadata = $this->driver->loadMetadataForClass($className);
     if ($classMetadata !== null) {
         $this->loadedMetadata[$className] = $classMetadata;
         if ($this->cache !== null) {
             $this->cache->save($this->cache_prefix . $className, $classMetadata);
         }
         return $classMetadata;
     }
     if (is_null($this->loadedMetadata[$className])) {
         throw DrestException::unableToLoadMetaDataFromDriver();
     }
     return $this->loadedMetadata[$className];
 }
 public function removeObject($object)
 {
     $class = $this->getClassMetadata();
     $identifier = $this->getObjectIdentifier($object);
     $identifier = $identifier[$class->identifier[0]];
     $this->cache->delete($identifier);
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function deleteItem($key)
 {
     if (!is_string($key)) {
         throw new InvalidArgumentException('Passed key is invalid');
     }
     return $this->cache->delete($key);
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function stop($token)
 {
     if (!$this->exists($token)) {
         return;
     }
     $this->dataCache->delete($token);
 }
 /**
  * {@inheritDoc}
  */
 protected function internalRemoveItem(&$normalizedKey)
 {
     $key = $this->getOptions()->getNamespace() . $normalizedKey;
     if (!$this->cache->contains($key)) {
         return false;
     }
     return $this->cache->delete($key);
 }
 /**
  * @param PersistConfigEvent $event
  */
 public function persistConfig(PersistConfigEvent $event)
 {
     $event->getConfigManager()->calculateConfigChangeSet($event->getConfig());
     $change = $event->getConfigManager()->getConfigChangeSet($event->getConfig());
     if ($event->getConfig()->getId()->getScope() == 'email' && isset($change['available_in_template'])) {
         $this->cache->delete($this->cacheKey);
     }
 }
 /**
  * Set the state.
  *
  * @param bool        $ok
  * @param string|null $name
  */
 public function ok($ok, $name = null)
 {
     $ok = (bool) $ok;
     $key = $this->getCacheKey($name);
     if ($ok === true) {
         $this->cache->delete($key);
     } else {
         $this->cache->save($key, 1, $this->ttl);
     }
 }
Esempio n. 10
0
 /**
  * @param PersistConfigEvent $event
  */
 public function persistConfig(PersistConfigEvent $event)
 {
     $config = $event->getConfig();
     if ($config->getId()->getScope() !== 'email') {
         return;
     }
     $change = $event->getConfigManager()->getConfigChangeSet($config);
     if (isset($change['available_in_template'])) {
         $this->cache->delete($this->cacheKey);
     }
 }
Esempio n. 11
0
 /**
  * @param PreFlushConfigEvent $event
  */
 public function preFlush(PreFlushConfigEvent $event)
 {
     $config = $event->getConfig('email');
     if (null === $config || $event->isEntityConfig()) {
         return;
     }
     $changeSet = $event->getConfigManager()->getConfigChangeSet($config);
     if (isset($changeSet['available_in_template'])) {
         $this->cache->delete($this->cacheKey);
     }
 }
 public function reset($class = null)
 {
     if ($class === null) {
         if ($this->cacheProvider instanceof \Doctrine\Common\Cache\FlushableCache) {
             $this->cacheProvider->flushAll();
         }
         return parent::reset($class);
     }
     $id = $class . '#info';
     $this->cacheProvider->delete($id);
     return parent::reset($class);
 }
Esempio n. 13
0
 /** @inheritdoc */
 public function invalidate($restaurantId)
 {
     if ($this->cache->contains($restaurantId)) {
         $cached = $this->cache->fetch($restaurantId)['cached']->getTimestamp();
         $now = (new \DateTime())->getTimestamp();
         if ($now - $cached < 60) {
             throw new EnhanceYourCalmException();
         }
         $this->cache->delete($restaurantId);
         return true;
     }
     return false;
 }
Esempio n. 14
0
 protected function removePathAndFilter($path, $filter)
 {
     $indexKey = $this->generateIndexKey($this->generateCacheKey($path, $filter));
     if (!$this->cache->contains($indexKey)) {
         return;
     }
     $index = $this->cache->fetch($indexKey);
     if (null === $path) {
         foreach ($index as $eachCacheKey) {
             $this->cache->delete($eachCacheKey);
         }
         $index = array();
     } else {
         $cacheKey = $this->generateCacheKey($path, $filter);
         if (false !== ($indexIndex = array_search($cacheKey, $index))) {
             unset($index[$indexIndex]);
             $this->cache->delete($cacheKey);
         }
     }
     if (empty($index)) {
         $this->cache->delete($indexKey);
     } else {
         $this->cache->save($indexKey, $index);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function removeRolePermission(Role $role, Permission $permission)
 {
     $this->driver->removeRolePermission($role, $permission);
     // Invalidate cache
     $cacheId = sprintf('roles/%s', $role->getRoleName());
     $this->cache->delete($cacheId);
 }
 /**
  * Delete the cache keys
  *
  * @param Cache $cache
  * @param array $keys
  */
 protected function clearCache(Cache $cache, $keys)
 {
     $keys = array_unique($keys);
     foreach ($keys as $key) {
         $cache->delete($key);
     }
 }
Esempio n. 17
0
 /**
  * {@inheritdoc}
  */
 public function deleteItem($key, array $tags = array())
 {
     if (!is_string($key)) {
         throw new InvalidArgumentException('Passed key is invalid');
     }
     $taggedKey = $this->generateCacheKey($key, $tags);
     return $this->cache->delete($taggedKey);
 }
 /**
  * {@inheritDoc}
  */
 public function deleteDir($dirname)
 {
     $success = $this->adapter->deleteDir($dirname);
     if ($success) {
         $this->cache->delete($this->getCacheKey($dirname));
     }
     return $success;
 }
Esempio n. 19
0
 /**
  * Resets the cache
  */
 public function reset()
 {
     for ($i = $this->getStart(), $end = $this->getEnd(); $i < $end; $i++) {
         $this->cache->delete($i);
     }
     $this->cache->save('start', 0);
     $this->cache->save('end', 0);
 }
Esempio n. 20
0
 /**
  * @param object $object
  *
  * @return bool
  */
 public function remove($object)
 {
     $className = get_class($object);
     $this->cache->setNamespace($className);
     $tags = $object->getTags();
     $id = $this->getRepository($className)->getId($tags);
     return $this->cache->delete($id);
 }
Esempio n. 21
0
 /**
  * {@inheritdoc}
  */
 public function delete($userId, $contentUuid, $webspaceKey, $locale)
 {
     $id = $this->getId($userId, $contentUuid, $locale);
     $classId = $this->getId($userId, $contentUuid, $locale, 'class');
     $this->dataCache->delete($id);
     $this->dataCache->delete($classId);
     $this->changesCache->delete($id);
 }
Esempio n. 22
0
 /**
  * Clear a cache entry
  *
  * @param string $name Entry name
  */
 private function clearCacheEntry($name)
 {
     if ($this->cache === null) {
         return;
     }
     $cacheKey = self::CACHE_PREFIX . $name;
     $this->cache->delete($cacheKey);
 }
Esempio n. 23
0
 public function fetch(RequestInterface $request)
 {
     $key = $this->getCacheKey($request);
     $entries = $this->cache->fetch($key);
     if (!$entries) {
         return null;
     }
     $match = $matchIndex = null;
     $headers = $this->persistHeaders($request);
     $entries = unserialize($entries);
     foreach ($entries as $index => $entry) {
         $vary = isset($entry[1]['vary']) ? $entry[1]['vary'] : '';
         if ($this->requestsMatch($vary, $headers, $entry[0])) {
             $match = $entry;
             $matchIndex = $index;
             break;
         }
     }
     if (!$match) {
         return null;
     }
     // Ensure that the response is not expired
     $response = null;
     if ($match[4] < time()) {
         $response = -1;
     } else {
         $response = new Response($match[2], $match[1]);
         if ($match[3]) {
             if ($body = $this->cache->fetch($match[3])) {
                 $response->setBody(Stream\Utils::create($body));
             } else {
                 // The response is not valid because the body was somehow
                 // deleted
                 $response = -1;
             }
         }
     }
     if ($response === -1) {
         // Remove the entry from the metadata and update the cache
         unset($entries[$matchIndex]);
         if ($entries) {
             $this->cache->save($key, serialize($entries));
         } else {
             $this->cache->delete($key);
         }
         return null;
     }
     return $response;
 }
 /**
  * @param string $class
  *
  * @return object
  */
 private function recompile($class)
 {
     $this->cache->delete($this->cacheKey);
     $diCompiler = $this->injector ? $this : call_user_func_array([$this, 'createInstance'], self::$args);
     /** @var $diCompiler DiCompiler */
     $mappedClass = array_keys($this->classMap);
     $mappedClass[] = $class;
     foreach ($mappedClass as $newClass) {
         $diCompiler->compile($newClass);
     }
     // log dependency container
     // error_log($this->logger);
     $instance = $this->getInstanceSafe($diCompiler, $class);
     return $instance;
 }
Esempio n. 25
0
 /**
  * @param $id
  * @param $refreshToken
  * @return array|void
  */
 public function refreshAccess($id, $refreshToken, $force = false)
 {
     $fromcache = true;
     if ($force) {
         $this->cache->delete($id . '_token');
     }
     if (!($jsontoken = $this->cache->fetch($id . '_token'))) {
         try {
             $this->googleclient->refreshToken($refreshToken);
             $verify_token = $this->googleclient->verifyIdToken();
             if ($verify_token->getUserId() != $id) {
                 return;
             }
             $jsontoken = $this->googleclient->getAccessToken();
         } catch (\Exception $e) {
             $this->lastexception = $e;
             $this->cache->delete($id . '_token');
             return;
         }
         $fromcache = false;
         $fulltoken = json_decode($jsontoken, true);
         if (!$this->cache->save($id . '_token', $jsontoken, $fulltoken["expires_in"] - 60)) {
             return;
         }
     }
     try {
         $this->googleclient->setAccessToken($jsontoken);
         $fulltoken = json_decode($jsontoken, true);
         $fulltoken["refresh_token"] = $refreshToken;
         $this->setAdwordsOAuth2Validate($fulltoken);
         $service = new \Google_Service_Oauth2($this->googleclient);
         $tokeninfo = $service->tokeninfo(array("access_token" => $fulltoken["access_token"]));
     } catch (\Exception $e) {
         $this->lastexception = $e;
         $this->cache->delete($id . '_token');
         return;
     }
     return array("accessType" => $tokeninfo->accessType, "audience" => $tokeninfo->audience, "email" => $tokeninfo->email, "expiresIn" => $tokeninfo->expiresIn, "issuedTo" => $tokeninfo->issuedTo, "scope" => $tokeninfo->scope, "userId" => $tokeninfo->userId, "verifiedEmail" => $tokeninfo->verifiedEmail, "fromcache" => $fromcache, "force" => $force);
 }
Esempio n. 26
0
 /**
  * Removes the collaborator with the given userId from the entity with the given identifier.
  *
  * @param string $type The type of the entity
  * @param mixed $id The id of the entity
  * @param string $connectionId The id of the connection of the user
  */
 private function removeCollaboration($type, $id, $connectionId)
 {
     $identifier = $this->getUniqueCollaborationKey($type, $id);
     $entityCollaborations = $this->collaborationsEntityCache->fetch($identifier) ?: [];
     if (array_key_exists($connectionId, $entityCollaborations)) {
         unset($entityCollaborations[$connectionId]);
     }
     if (empty($entityCollaborations)) {
         $this->collaborationsEntityCache->delete($identifier);
     } else {
         $this->collaborationsEntityCache->save($identifier, $entityCollaborations);
     }
     $connectionCollaborations = $this->collaborationsConnectionCache->fetch($connectionId) ?: [];
     if (array_key_exists($identifier, $connectionCollaborations)) {
         unset($connectionCollaborations[$identifier]);
     }
     if (empty($connectionCollaborations)) {
         $this->collaborationsConnectionCache->delete($connectionId);
     } else {
         $this->collaborationsConnectionCache->save($connectionId, $connectionCollaborations);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function remove($targetPath, $filter)
 {
     $removed = $this->resolver->remove($targetPath, $filter);
     // If the resolver did not remove the content, we can leave the cache.
     if ($removed) {
         $reverseKey = $this->generateCacheKey('reverse', $targetPath, $filter);
         if ($this->cache->contains($reverseKey)) {
             $path = $this->cache->fetch($reverseKey);
             // The indexKey is not utilizing the method so the value is not important.
             $indexKey = $this->generateIndexKey($this->generateCacheKey(null, $path, $filter));
             // Retrieve the index and remove the content from the cache.
             $index = $this->cache->fetch($indexKey);
             foreach ($index as $eachCacheKey) {
                 $this->cache->delete($eachCacheKey);
             }
             // Remove the auxiliary keys.
             $this->cache->delete($indexKey);
             $this->cache->delete($reverseKey);
         }
     }
     return $removed;
 }
Esempio n. 28
0
 /**
  * @param $method
  * @param $resource
  * @param array $request
  * @param array $headers
  * @param int $returnType
  * @return array|mixed|string|resource
  */
 protected function performRequest($method, $resource, array $request, array $headers, $returnType = HttpAdapter::RETURN_TYPE_JSON)
 {
     if ($this->cache->contains($this->options['cache_key'])) {
         $accessToken = $this->cache->fetch($this->options['cache_key']);
     } else {
         $accessToken = $this->authorize();
         $this->cache->save($this->options['cache_key'], $accessToken);
     }
     try {
         $request['access_token'] = $accessToken;
         return $this->http->{$method}($resource, $request, $headers, $returnType);
     } catch (UnauthorizedException $e) {
         if (!$this->cache->delete($this->options['cache_key'])) {
             throw new CacheException('Could not delete the key in the cache. Do you have permission?');
         }
         if ($e instanceof TokenExpiredException || $e instanceof TokenInvalidException) {
             if ($this->options['token_refresh']) {
                 return $this->{$method}($resource, $request, $headers, $returnType);
             }
         }
         throw $e;
     }
 }
Esempio n. 29
0
 /**
  * @param string $txid
  * @param int $vout
  */
 public function remove($txid, $vout)
 {
     $this->cache->delete($this->getInternalIndex($txid, $vout));
 }
 public function delete($storageName, $key)
 {
     $key = $this->flattenKey($storageName, $key);
     $this->cache->delete($key);
 }