コード例 #1
0
ファイル: CategoryController.php プロジェクト: kazak/forum
 /**
  * Retrieves category with id $id or throws an exception if it doesn't exist.
  *
  * @param int $id A Category identifier
  *
  * @return CategoryInterface
  *
  * @throws NotFoundHttpException
  */
 protected function getCategory($id)
 {
     $category = $this->categoryManager->find($id);
     if (null === $category) {
         throw new NotFoundHttpException(sprintf('Category (%d) not found', $id));
     }
     return $category;
 }
コード例 #2
0
 /**
  * @param CategoryInterface|int  $id
  * @param CategoryInterface|null $default
  *
  * @return CategoryInterface
  */
 protected final function getCategory($id, CategoryInterface $default = null)
 {
     if ($id instanceof CategoryInterface) {
         return $id;
     }
     if (is_numeric($id)) {
         return $this->categoryManager->find($id);
     }
     return $default;
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function getNewInstance()
 {
     $media = parent::getNewInstance();
     if ($this->hasRequest()) {
         if ($this->getRequest()->isMethod('POST')) {
             $media->setProviderName($this->getRequest()->get(sprintf('%s[providerName]', $this->getUniqid()), null, true));
         } else {
             $media->setProviderName($this->getRequest()->get('provider'));
         }
         $media->setContext($context = $this->getRequest()->get('context'));
         if ($categoryId = $this->getPersistentParameter('category')) {
             $category = $this->categoryManager->find($categoryId);
             if ($category && $category->getContext()->getId() == $context) {
                 $media->setCategory($category);
             }
         }
     }
     return $media;
 }