/** * Return the specified or default (key = "") message resources for the * current module. * * @param \Symfony\Component\HttpFoundation\Request $request The actionKernel request we are * processing * @param string $key The key specified in the <message-resources> element * for the requested bundle * @return \Phruts\Util\MessageResources * module ($request = null). */ protected function getResources(Request $request, $key = '') { if ($key == '') { return $request->attributes->get(\Phruts\Util\Globals::MESSAGES_KEY); } else { // Identify the current module $app = $this->actionKernel->getApplication(); $moduleConfig = \Phruts\Util\RequestUtils::getModuleConfig($request, $app); // Return the requested message resources instance return $app[$key . $moduleConfig->getPrefix()]; } }
/** * @param Request $request * @param $key * @return \Phruts\ */ public function getDataSource(Request $request, $key) { // Identify the current module $moduleConfig = \Phruts\Util\RequestUtils::getModuleConfig($request, $this->getApplication()); // Return the requested data source instance $keyPrefixed = $key . $moduleConfig->getPrefix(); $dataSource = $request->attributes->get($keyPrefixed); if (empty($dataSource)) { if (!array_key_exists($keyPrefixed, $this->dataSourceFactories)) { return null; } /** @var \Phruts\Util\DataSourceFactory $dsFactory */ $dsFactory = $this->dataSourceFactories[$keyPrefixed]; try { $dataSource = $dsFactory->createDataSource(); } catch (\Exception $e) { throw $e; } $request->attributes->set($keyPrefixed, $dataSource); } return $dataSource; }