示例#1
0
 /**
  * Collection tag with its version
  *
  * @return array
  */
 public function getCollectionTags()
 {
     try {
         $name = sfCacheTaggingToolkit::obtainCollectionName($this->getTable());
         $version = sfCacheTaggingToolkit::obtainCollectionVersion($name);
         return array($name => $version);
     } catch (sfCacheDisabledException $e) {
         $this->notifyApplicationLog($e);
     }
     return array();
 }
 /**
  * Format passed tags to the array
  *
  * @param mixed $argument   false|array|Doctrine_Collection_Cachetaggable|
  *                          Doctrine_Record|ArrayIterator|Doctrine_Table
  *                          IteratorAggregate|Iterator
  * @throws InvalidArgumentException
  * @return array
  */
 public static function formatTags($argument)
 {
     $tagsToReturn = null;
     if (false === $argument) {
         $tagsToReturn = array();
     } elseif ($argument instanceof Doctrine_Table) {
         $name = sfCacheTaggingToolkit::obtainCollectionName($argument);
         $version = sfCacheTaggingToolkit::obtainCollectionVersion($name);
         $tagsToReturn = array($name => $version);
     } elseif (is_array($argument)) {
         $tagsToReturn = $argument;
     } elseif ($argument instanceof Doctrine_Collection_Cachetaggable) {
         $tagsToReturn = $argument->getCacheTags();
     } elseif ($argument instanceof Doctrine_Record) {
         $table = $argument->getTable();
         if (!$table->hasTemplate(self::TEMPLATE_NAME)) {
             throw new InvalidArgumentException(sprintf('Object "%s" should have the "%s" template', $table->getClassnameToReturn(), self::TEMPLATE_NAME));
         }
         $tagsToReturn = $argument->getCacheTags();
     } elseif ($argument instanceof ArrayIterator || $argument instanceof ArrayObject) {
         $tagsToReturn = $argument->getArrayCopy();
     } elseif ($argument instanceof IteratorAggregate || $argument instanceof Iterator) {
         foreach ($argument as $key => $value) {
             $tagsToReturn[$key] = $value;
         }
     } else {
         throw new InvalidArgumentException(sprintf('Invalid argument\'s type "%s". ' . 'See acceptable types in the PHPDOC of "%s"', sprintf('%s%s', gettype($argument), is_object($argument) ? '(' . get_class($argument) . ')' : ''), __METHOD__));
     }
     return $tagsToReturn;
 }
示例#3
0
 /**
  * Retrieves collections tags version or initialize new version if
  * nothing was before
  *
  * @return string Version
  */
 public function obtainCollectionVersion()
 {
     try {
         $version = sfCacheTaggingToolkit::obtainCollectionVersion($this->obtainCollectionName());
         return $version;
     } catch (sfCacheDisabledException $e) {
     }
     return self::UNSAVED_RECORD_DEFAULT_VERSION;
 }