Newscoop\Storage::isUsed PHP Method

isUsed() public method

Test is used
public isUsed ( string $key, object $searchEngine = null ) : mixed
$key string
$searchEngine object
return mixed
    public function isUsed($key, $searchEngine = null)
    {
        if (!isset($searchEngine)) {
            $searchEngine = new \FileTextSearch();
        }
        $searchEngine->setExtensions(array('tpl', 'css'));
        $searchEngine->setSearchKey($key);
        $result = $searchEngine->findReplace($this->root);
        if (is_array($result) && sizeof($result) > 0) {
            return $result[0];
        }
        if (pathinfo($key, PATHINFO_EXTENSION) == 'tpl') {
            $key = " {$key}";
        }
        $searchEngine->setSearchKey($key);
        $result = $searchEngine->findReplace($this->root);
        if (is_array($result) && sizeof($result) > 0) {
            return $result[0];
        }
        return $searchEngine->m_totalFound > 0;
    }

Usage Example

示例#1
0
 /**
  * Delete item
  *
  * @param string $key
  * @return void
  * @throws InvalidArgumentException
  */
 public function deleteItem($key)
 {
     if ($this->repository->isUsed($key) || $this->storage->isUsed($key)) {
         throw new \InvalidArgumentException(sprintf("The template object %s is in use and can not be deleted.", $key));
     }
     try {
         $this->storage->deleteItem($key);
         $this->repository->delete($key);
     } catch (\InvalidArgumentException $e) {
         throw new \InvalidArgumentException(sprintf("Can't remove non empty directory '%s'", basename($key)), $e->getCode(), $e);
     }
 }