/** * @return ModelAndView **/ public function run(Prototyped $subject, Form $form, HttpRequest $request) { if ($object = $form->getValue('id')) { FormUtils::object2form($object, $form); } return ModelAndView::create(); }
/** * @return ModelAndView **/ public function run(Prototyped $subject, Form $form, HttpRequest $request) { if (!$form->getErrors()) { ClassUtils::copyProperties($form->getValue('id'), $subject); FormUtils::form2object($form, $subject, false); return parent::run($subject, $form, $request); } return new ModelAndView(); }
/** * @return ModelAndView **/ public function run(Prototyped $subject, Form $form, HttpRequest $request) { $form->markGood('id'); if (!$form->getErrors()) { FormUtils::form2object($form, $subject); return parent::run($subject, $form, $request); } return new ModelAndView(); }
/** * @return MetaConfiguration **/ public function checkIntegrity() { $out = $this->getOutput()->newLine()->infoLine('Checking sanity of generated files: ')->newLine(); $out->info("\t"); $formErrors = []; foreach ($this->classes as $name => $class) { if (!($class->getPattern() instanceof SpookedClassPattern || $class->getPattern() instanceof SpookedEnumerationPattern || $class->getPattern() instanceof SpookedEnumPattern || $class->getPattern() instanceof SpookedRegistryPattern || $class->getPattern() instanceof InternalClassPattern) && class_exists(MetaClassNameBuilder::getClassOfMetaClass($class, true))) { $out->info($name, true); $className = MetaClassNameBuilder::getClassOfMetaClass($class); $info = new \ReflectionClass($className); $this->checkClassSanity($class, $info); if ($info->implementsInterface(Prototyped::class)) { $this->checkClassSanity($class, new \ReflectionClass($class->getProtoClass())); } if ($info->implementsInterface(DAOConnected::class)) { $this->checkClassSanity($class, new \ReflectionClass($class->getDaoClass())); } foreach ($class->getInterfaces() as $interface) { Assert::isTrue($info->implementsInterface($interface), 'class ' . $class->getName() . ' expected to implement interface ' . $interface); } // special handling for Enumeration instances if ($class->getPattern() instanceof EnumerationClassPattern || $class->getPattern() instanceof EnumClassPattern || $class->getPattern() instanceof RegistryClassPattern) { $object = new $className(call_user_func([$className, 'getAnyId'])); Assert::isTrue(unserialize(serialize($object)) == $object); $out->info(', '); if ($this->checkEnumerationRefIntegrity) { if ($object instanceof Enumeration || $object instanceof Enum || $object instanceof Registry) { $this->checkEnumerationReferentialIntegrity($object, $class->getTableName()); } } continue; } if ($class->getPattern() instanceof AbstractClassPattern) { $out->info(', '); continue; } /** @var Prototyped $object */ $object = new $className(); $proto = $object->proto(); $form = $proto->makeForm(); foreach ($class->getProperties() as $name => $property) { Assert::isTrue($property->toLightProperty($class) == $proto->getPropertyByName($name), 'defined property does not match autogenerated one - ' . $class->getName() . '::' . $property->getName()); } if (!$object instanceof DAOConnected) { $out->info(', '); continue; } $dao = $object->dao(); Assert::isEqual($dao->getIdName(), $class->getIdentifier()->getColumnName(), 'identifier name mismatch in ' . $class->getName() . ' class'); try { DBPool::getByDao($dao); } catch (MissingElementException $e) { // skipping $out->info(', '); continue; } $query = Criteria::create($dao)->setLimit(1)->add(Expression::notNull($class->getIdentifier()->getName()))->addOrder($class->getIdentifier()->getName())->toSelectQuery(); $out->warning(' (' . $query->getFieldsCount() . '/' . $query->getTablesCount() . '/'); $clone = clone $object; if (serialize($clone) == serialize($object)) { $out->info('C', true); } else { $out->error('C', true); } $out->warning('/'); try { $object = $dao->getByQuery($query); $form = $object->proto()->makeForm(); FormUtils::object2form($object, $form); if ($errors = $form->getErrors()) { $formErrors[$class->getName()] = $errors; $out->error('F', true); } else { $out->info('F', true); } } catch (ObjectNotFoundException $e) { $out->warning('F'); } $out->warning('/'); if (Criteria::create($dao)->setFetchStrategy(FetchStrategy::cascade())->toSelectQuery() == $dao->makeSelectHead()) { $out->info('H', true); } else { $out->error('H', true); } $out->warning('/'); // cloning once again $clone = clone $object; FormUtils::object2form($object, $form); FormUtils::form2object($form, $object); if ($object != $clone) { $out->error('T', true); } else { $out->info('T', true); } $out->warning(')')->info(', '); } } $out->infoLine('done.'); if ($formErrors) { $out->newLine()->errorLine('Errors found:')->newLine(); foreach ($formErrors as $class => $errors) { $out->errorLine("\t" . $class . ':', true); foreach ($errors as $name => $error) { $out->errorLine("\t\t" . $name . ' - ' . ($error == Form::WRONG ? ' wrong' : ' missing')); } $out->newLine(); } } return $this; }
protected function addObject(HttpRequest $request, Form $form, Identifiable $object) { FormUtils::form2object($form, $object); return $object->dao()->add($object); }