/** * @load * @param ReflectionMethod $reflection */ protected function _createFromReflection($reflection) { $this->_name = $reflection->getName(); $this->_public = $reflection->isPublic(); foreach ($reflection->getParameters() as $paramReflection) { //Argument::create($this, $paramReflection); $this->addArgument(Argument::create($this, $paramReflection)); } }
/** * @load * @param ReflectionMethod $reflection */ private function _createFromReflection($reflection) { $this->_name = $reflection->getName(); $this->_public = $reflection->isPublic(); $this->_inherited = !($reflection->getDeclaringClass()->getName() == $this->_controller->className()); foreach ($reflection->getParameters() as $paramReflection) { //Argument::create($this, $paramReflection); $this->addArgument(Argument::create($this, $paramReflection)); } //{ Add Views if ($this->isAction()) { $viewPath = \Path::instance()->evaluate(':' . $this->controller()->project()->name() . '.apps.view.+' . $this->controller()->name() . '.-' . $this->name()); if (file_exists($viewPath)) { $this->setViewDirectoryCreated(); $dh = opendir($viewPath); $viewsFound = array(); while (false !== ($file = readdir($dh))) { if ($file != "." && $file != ".." && strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'php') { $viewFilePath = rtrim($viewPath, '/') . "/{$file}"; if ($file == 'layout.php') { $this->setHasLayout(); } else { if ($file == 'params.php') { $this->setHasParams(); } else { $viewsFound[$file] = $viewFilePath; $this->addView(ControllerView::create($this, pathinfo($file, PATHINFO_FILENAME))); } } } } closedir($dh); if (array_key_exists('view.php', $viewsFound)) { $this->setHasDefaultView(); } } } //} }
/** * Run the database seeds. * * @return void */ public function run() { Eloquent::unguard(); $algorithmsXmls = File::allFiles(public_path() . '/algorithms'); foreach ($algorithmsXmls as $algorithmsXml) { $dom = new DomDocument(); $dom->load($algorithmsXml); $root = $dom->documentElement; $modality = Modality::whereName($root->getAttribute('modality'))->first(); if (empty($modality)) { throw new Exception("Could not find modality! ({$algorithmsXml})"); } $protocolName = $root->getAttribute('protocol'); $protocol = Protocol::whereName($protocolName)->whereModalityId($modality->Id)->first(); if (empty($protocol)) { \Log::warning("Could not find protocol! ({$algorithmsXml})"); continue; } $arguments = []; $parameters = []; $description = ""; foreach ($root->childNodes as $node) { if (get_class($node) == 'DOMText') { continue; } switch ($node->nodeName) { case 'arguments': foreach ($node->childNodes as $argument) { if (get_class($argument) == 'DOMText') { continue; } $arguments[] = ['Name' => $argument->getAttribute('name')]; } break; case 'parameters': foreach ($node->childNodes as $parameter) { if (get_class($parameter) == 'DOMText') { continue; } $parameters[] = ['Name' => $parameter->getAttribute('name'), 'Type' => $parameter->getAttribute('type'), 'Value' => $parameter->hasAttribute('value') ? $parameter->getAttribute('value') : null]; } break; case 'description': $description = $node->textContent; break; default: throw new Exception("Unrecognized entry in algorithm XML - {$node->nodeName}! ({$algorithmsXml})"); } } $algorithm = new Algorithm(); $algorithm->content = $description; $resultName = $root->getAttribute('result'); $resultType = $root->getAttribute('type'); $result = Parameter::whereName($resultName)->first(); if (empty($result)) { $result = Parameter::create(['Name' => $resultName, 'Type' => $resultType]); } $algorithm->result()->associate($result); $algorithm->protocol()->associate($protocol); $algorithm->save(); foreach ($arguments as $argument) { $algorithm->arguments()->attach(Argument::create($argument)); } foreach ($parameters as $parameter) { $algorithm->attribute($parameter); } } }