private function validateModelType($model, $viewName = null) { $viewFile = DirectoryBuilder::getViewPath($this->getControllerName(), $this->getActionName(), $this->getAreaName(), $viewName); $viewContent = file_get_contents($viewFile); $typeRegex = '/@var\\s*.*\\s+(' . FrameworkConfig::VENDOR_NAMESPACE . '\\.*?)\\s+\\s*.*/'; preg_match($typeRegex, $viewContent, $matches); if (!isset($matches[1])) { throw new \Exception('Invalid model type provided'); } $typeGiven = get_class($model); $typeExpected = $matches[1]; if ($typeGiven != $typeExpected) { throw new \Exception('Invalid type supplied'); } return $viewFile; }