Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions sources/lib/Request/ParamConverter/EntityParamConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class EntityParamConverter implements ParamConverterInterface
{
Expand Down Expand Up @@ -47,6 +48,16 @@ public function apply(Request $request, ParamConverter $configuration)
}
}

if (null === $entity && false === $options["optional"]) {
throw new NotFoundHttpException(
sprintf(
'%s object not found by the %s.',
$options['model'],
$this->getClassName($this)
)
);
}

$request->attributes->set($name, $entity);

return true;
Expand Down Expand Up @@ -83,4 +94,11 @@ private function getPk(Model $model, Request $request)
}
return $values;
}

private function getClassName(ParamConverterInterface $configuration)
{
$r = new \ReflectionClass($configuration);

return $r->getName();
}
}