Пример #1
0
 public function generate($ns, $name)
 {
     $app = kernel()->app($ns) ?: kernel()->bundle($ns, true);
     if (!$app) {
         throw new Exception("{$ns} application or plugin not found.");
     }
     $emailClassName = $name . 'Email';
     $handle = Inflector::getInstance()->underscore($name);
     $dir = $app->locate();
     $className = $ns . '\\Email\\' . $emailClassName;
     $classDir = $dir . DIRECTORY_SEPARATOR . 'Email';
     $classFile = $classDir . DIRECTORY_SEPARATOR . $emailClassName . '.php';
     if (!file_exists($classDir)) {
         mkdir($classDir, 0755, true);
     }
     if (file_exists($classFile)) {
         $this->logger->info("Found existing {$classFile}, skip");
     } else {
         $this->render('Email.php.twig', $classFile, array('namespace' => $ns, 'emailClassName' => $emailClassName, 'emailHandle' => $handle));
     }
     foreach (kernel()->locale->available() as $locale => $name) {
         $templateFile = $app->getTemplateDir() . DIRECTORY_SEPARATOR . 'email' . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $handle . '.html';
         if (file_exists($templateFile)) {
             $this->logger->info("Found existing {$templateFile}, skip");
             continue;
         }
         $this->render('EmailTemplate.html.twig', $templateFile, array('namespace' => $ns, 'emailClassName' => $emailClassName, 'emailHandle' => $handle));
     }
     /*
      */
 }
Пример #2
0
 public function generate($ns, $crudId)
 {
     $bundle = kernel()->app($ns) ?: kernel()->bundle($ns, true);
     if (!$bundle) {
         throw new Exception("{$ns} application or plugin not found.");
     }
     $crudId = Inflector::getInstance()->underscore($crudId);
     $templateDir = $bundle->getTemplateDir() . DIRECTORY_SEPARATOR . $crudId;
     $this->copyDir('template', $templateDir);
 }
Пример #3
0
 public function generate($ns, $modelName, $crudId = null)
 {
     $bundle = kernel()->app($ns) ?: kernel()->bundle($ns, true);
     if (!$bundle) {
         throw new Exception("{$ns} application or bundle not found.");
     }
     if (!$crudId) {
         $crudId = Inflector::getInstance()->underscore($modelName);
     }
     $bundleName = $bundle->getNamespace();
     $modelClass = $bundleName . '\\Model\\' . $modelName;
     $handlerClass = $modelName . 'CRUDHandler';
     $classFile = $bundle->locate() . DIRECTORY_SEPARATOR . $handlerClass . '.php';
     $this->render('CRUDHandler.php.twig', $classFile, array('handlerClass' => $handlerClass, 'bundleName' => $bundleName, 'modelClass' => $modelClass, 'crudId' => $crudId));
 }
Пример #4
0
 /**
  * init() method will be called when the route is matched.
  */
 public function init()
 {
     $this->vars['CRUD']['Object'] = $this;
     $this->kernel = kernel();
     // Dynamic initialization
     if (!$this->modelName) {
         $modelRefl = new ReflectionClass($this->modelClass);
         $this->modelName = $modelRefl->getShortName();
     }
     if (!$this->crudId) {
         $this->crudId = \Phifty\Inflector::getInstance()->underscore($this->modelName);
     }
     if (!$this->templateId) {
         $this->templateId = $this->crudId;
     }
     // Derive options from request
     if ($request = $this->getRequest()) {
         if ($useFormControls = $request->param('_form_controls')) {
             $this->actionViewOptions['submit_btn'] = true;
             $this->actionViewOptions['_form_controls'] = true;
         }
     }
     $this->reflect = new ReflectionClass($this);
     $this->namespace = $ns = $this->reflect->getNamespaceName();
     // XXX: currently we use FooBundle\FooBundle as the main bundle class.
     $bundleClass = "{$ns}\\{$ns}";
     if (class_exists($bundleClass)) {
         $this->bundle = $this->vars['Bundle'] = $bundleClass::getInstance($this->kernel);
     } else {
         $bundleClass = "{$ns}\\Application";
         $this->bundle = $this->vars['Bundle'] = $bundleClass::getInstance($this->kernel);
     }
     $this->vars['Handler'] = $this;
     $this->vars['Controller'] = $this;
     // anyway, we have the model classname, and the namespace,
     // we should be able to registerRecordAction automatically, so we don't have to write the code.
     if ($this->registerRecordAction) {
         $self = $this;
         $this->kernel->event->register('phifty.before_action', function () use($self) {
             $self->kernel->action->registerAction('RecordActionTemplate', array('namespace' => $self->namespace, 'model' => $self->modelName, 'types' => (array) $self->registerRecordAction));
         });
     }
     $this->initPermissions();
     /*
      * TODO:  Move this to before render CRUD page, keep init method simple
     
     if ( $this->isI18NEnabled() ) {
         $this->primaryFields[] = 'lang';
     }
     */
     $this->initNavBar();
 }