public function testLoadEntity() { $this->getController(); $this->paramsPlugin->expects($this->once())->method('fromRoute')->with('entity')->will($this->returnValue('user')); $this->entityService->expects($this->once())->method('getEntity')->with('user'); $this->object->loadEntity(); }
/** * @param Params $params * @param bool $allowDraft * * @return \Jobs\Entity\Job|object * @throws \Doctrine\ODM\MongoDB\LockException */ public function get(Params $params, $allowDraft = false) { /* @var \Jobs\Repository\Job $jobRepository */ $jobRepository = $this->repositoryService->get('Jobs/Job'); $idFromRoute = $params('id', 0); $idFromQuery = $params->fromQuery('id', 0); $idFromSubForm = $params->fromPost('job', 0); $id = empty($idFromRoute) ? empty($idFromQuery) ? $idFromSubForm : $idFromQuery : $idFromRoute; if (empty($id) && $allowDraft) { $this->acl->__invoke('Jobs/Manage', 'new'); $user = $this->auth->getUser(); /** @var \Jobs\Entity\Job $job */ $job = $jobRepository->findDraft($user); if (empty($job)) { $job = $jobRepository->create(); $job->setIsDraft(true); $job->setUser($user); $this->repositoryService->store($job); } return $job; } $job = $jobRepository->find($id); if (!$job) { throw new \RuntimeException('No job found with id "' . $id . '"'); } return $job; }
public function testGetQrCodeWithParams() { $params = new Params(); $routeParams = array('extension' => 'png', 'size' => 123, 'message' => 'this is a long message', 'padding' => 10); $params->setController(new ControllerMock($routeParams)); $qrCode = new QrCode($routeParams['message']); $qrCode->setImageType($routeParams['extension']); $qrCode->setSize($routeParams['size']); $qrCode->setPadding($routeParams['padding']); $this->assertEquals($qrCode->get(), $this->qrCodeService->getQrCodeContent($params)); }
public function getLocationsByCityAction(Params $params, BaseFinder $cityFinderService, BaseFinder $regionFinderService, BaseFinder $countryFinderService) { $dataLocation = $params->fromPost(); $city = $cityFinderService->find(['RoLocations' => ['Cities' => ['Id' => $dataLocation['id']]]]); if (!$city) { $this->setError('error'); return $this->view; } $this->view->countries = $countryFinderService->findMany(['RoLocations' => ['Countries' => []]]); $this->view->regions = $regionFinderService->findMany(['RoLocations' => ['Regions' => ['countryId' => $city->getCountryId()]]]); $this->view->cities = $cityFinderService->findMany(['RoLocations' => ['Cities' => ['regionId' => $city->getRegionId()]]]); $this->view->locations = $city->extract(); return $this->view; }
/** * @param string $paramName * * @return mixed */ private function findParam($paramName) { $param = $this->params->fromRoute($paramName, null); if (!$param) { $param = $this->params->fromQuery($paramName, null); } if (!$param) { $param = $this->params->fromHeader($paramName, null); } if (!$param) { $param = $this->params->fromFiles($paramName, null); } return $param; }
/** * Returns a QrCode content to be rendered or saved * If the first argument is a Params object, all the information will be tried to be fetched for it, * ignoring any other argument * @param string|Params $messageOrParams * @param string $extension * @param int $size * @param int $padding * @return mixed */ public function getQrCodeContent($messageOrParams, $extension = null, $size = null, $padding = null) { if ($messageOrParams instanceof Params) { $extension = $messageOrParams->fromRoute('extension', $this->options->getExtension()); $size = $messageOrParams->fromRoute('size', $this->options->getSize()); $padding = $messageOrParams->fromRoute('padding', $this->options->getPadding()); $messageOrParams = $messageOrParams->fromRoute('message'); } else { $extension = isset($extension) ? $extension : $this->options->getExtension(); $size = isset($size) ? $size : $this->options->getSize(); $padding = isset($padding) ? $padding : $this->options->getPadding(); } $qrCode = new QrCode($messageOrParams); $qrCode->setImageType($extension); $qrCode->setSize($size); $qrCode->setPadding($padding); return $qrCode->get(); }
public function __invoke(ZendPaginator $paginator = null, $scrollingStyle = 'Sliding', $partial = 'partial/paginator', $params = null) { if (count($paginator) != 0) { $paginationControl = $this->getView()->plugin('paginationControl'); if ($params == null) { $params = []; } if (!isset($params['route'])) { $params['route'] = null; } if (!isset($params['params'])) { $params['params'] = []; } $params['options']['query'] = $this->params->fromQuery(); if (!isset($params['reuseMatchedParams'])) { $params['reuseMatchedParams'] = true; } return $paginationControl->__invoke($paginator, $scrollingStyle, $partial, $params); } return ''; }
/** * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator * @param \Zend\StdLib\RequestInterface $request * @param \Phpro\SmartCrud\Controller\CrudController $controller * @param \Zend\Mvc\Controller\Plugin\Params $params */ protected function mockServiceLocator($serviceLocator, $request, $controller, $params) { $prophet = new Prophet(); $app = $prophet->prophesize('\\Zend\\Mvc\\Application'); $event = $prophet->prophesize('\\Zend\\Mvc\\MvcEvent'); if ($controller) { $controller->plugin('params')->willReturn($params->getWrappedObject()); $controller = $controller->getWrappedObject(); } // mock routeMatch $routeMatch = $prophet->prophesize('Zend\\Mvc\\Router\\Http\\RouteMatch'); $routeMatch->getParam('controller')->willReturn('DummyControllerSlag'); // Mock controller manager $controllerManager = $prophet->prophesize('Zend\\Mvc\\Controller\\ControllerManager'); $controllerManager->get('DummyControllerSlag')->willReturn($controller); $serviceLocator->get('controllerLoader')->willReturn($controllerManager); // Add application data to mvc event $event->getRequest()->willReturn($request->getWrappedObject()); $event->getRouteMatch()->willReturn($routeMatch); $app->getMvcEvent()->willReturn($event); $serviceLocator->get('application')->willReturn($app); }
/** * Grabs a param from route match by default. * * @param string|null $param * @param mixed $default * @return mixed */ public function __invoke($param = null, $default = null) { $result = parent::__invoke($param, null); if ($result !== null) { return $result; } $value = $default; foreach ($this->variablesOrder as $method) { if (method_exists($this, 'from' . $method)) { $val = $this->{'from' . $method}($param); if (null !== $val) { $value = $val; break; } } } return $value; }
/** * @param $type * @param $key * @param $value */ protected function mockParam($type, $key, $value) { $this->params->expects($this->any())->method('from' . ucfirst($type))->with($key)->will($this->returnValue($value)); }
public function fromRoute($param = null, $default = null) { return $this->params->fromRoute($param, $default); }