Пример #1
0
 /**
  * onAfterRouting
  *
  * @param Event $event
  *
  * @return  void
  */
 public function onAfterRouting(Event $event)
 {
     /** @var WebApplication $app */
     $app = $event['app'];
     $package = $app->getPackage();
     // In Warder
     if ($this->warder->isEnabled()) {
         RecordResolver::addNamespace(ReflectionHelper::getNamespaceName($this->warder) . '/Admin/Record', PriorityQueue::LOW);
         DataMapperResolver::addNamespace(ReflectionHelper::getNamespaceName($this->warder) . '/Admin/DataMapper', PriorityQueue::LOW);
         FieldDefinitionResolver::addNamespace(ReflectionHelper::getNamespaceName($package) . '/Form');
     }
     // Frontend
     if ($this->warder->isFrontend()) {
         $package->getMvcResolver()->addNamespace(ReflectionHelper::getNamespaceName($this->warder), PriorityQueue::BELOW_NORMAL);
         FieldDefinitionResolver::addNamespace(ReflectionHelper::getNamespaceName($this->warder) . '\\Form');
     } elseif ($this->warder->isAdmin()) {
         $package->getMvcResolver()->addNamespace(ReflectionHelper::getNamespaceName($this->warder) . '\\Admin', PriorityQueue::BELOW_NORMAL);
         FieldDefinitionResolver::addNamespace(ReflectionHelper::getNamespaceName($this->warder) . '\\Admin\\Form');
     }
 }
 /**
  * getFieldDefinition
  *
  * @param string $definition
  * @param string $name
  *
  * @return FieldDefinitionInterface
  */
 public function getFieldDefinition($definition = null, $name = null)
 {
     if (class_exists($definition) && is_subclass_of($definition, FieldDefinitionInterface::class)) {
         return new $definition();
     }
     $name = $name ?: $this->getName();
     if (!($class = FieldDefinitionResolver::create(ucfirst($name) . '\\' . ucfirst($definition)))) {
         $class = sprintf('%s\\Form\\%s\\%sDefinition', MvcHelper::getPackageNamespace($this, 2), ucfirst($name), ucfirst($definition));
         if (!class_exists($class)) {
             return new NullFiledDefinition();
         }
     }
     return new $class();
 }