protected function serve()
 {
     $this->options['name'] = $this->input->getArgument('name');
     $this->name['machine'] = $this->generateMachineName($this->options['name']);
     $this->name['camel'] = $this->generateCamelName($this->options['name']);
     $path['src'] = PLUGINS_DIR . 'component-generator/' . self::COMPONENT;
     $path['dest'] = PLUGINS_DIR . $this->name['machine'];
     $path['tmp'] = CACHE_DIR . 'tmp/' . self::COMPONENT;
     $replace = array('/{{ COMPONENT }}/' => lcfirst($this->name['camel']), '/{{ COMPONENT NAME }}/' => $this->options['name'], '/{{ COMPONENT CAMEL NAME }}/' => $this->name['camel'], '/{{ COMPONENT MACHINE NAME }}/' => $this->name['machine']);
     // Copy dir to cache/temp
     Folder::copy($path['src'], $path['tmp']);
     // Recursively rewrite file names and contents of all files
     $this->rewriteRecursive($path['tmp'], array_keys($replace), array_values($replace));
     // Move dir to rest
     Folder::move($path['tmp'], $path['dest']);
     // Success message
 }
示例#2
0
 /**
  * Moves or copies the page in filesystem.
  *
  * @internal
  */
 protected function doRelocation($reorder)
 {
     if (empty($this->_original)) {
         return;
     }
     // Do reordering.
     if ($reorder && $this->order() != $this->_original->order()) {
         /** @var Pages $pages */
         $pages = self::getGrav()['pages'];
         $parent = $this->parent();
         // Extract visible children from the parent page.
         $list = array();
         /** @var Page $page */
         foreach ($parent->children()->visible() as $page) {
             if ($page->order()) {
                 $list[$page->slug] = $page->path();
             }
         }
         // If page was moved, take it out of the list.
         if ($this->_action == 'move') {
             unset($list[$this->slug()]);
         }
         $list = array_values($list);
         // Then add it back to the new location (if needed).
         if ($this->order()) {
             array_splice($list, min($this->order() - 1, count($list)), 0, array($this->path()));
         }
         // Reorder all moved pages.
         foreach ($list as $order => $path) {
             if ($path == $this->path()) {
                 // Handle current page; we do want to change ordering number, but nothing else.
                 $this->order($order + 1);
             } else {
                 // Handle all the other pages.
                 $page = $pages->get($path);
                 if ($page && $page->exists() && $page->order() != $order + 1) {
                     $page = $page->move($parent);
                     $page->order($order + 1);
                     $page->save(false);
                 }
             }
         }
     }
     if ($this->_action == 'move' && $this->_original->exists()) {
         Folder::move($this->_original->path(), $this->path());
     }
     if ($this->_action == 'copy' && $this->_original->exists()) {
         Folder::copy($this->_original->path(), $this->path());
     }
     if ($this->name() != $this->_original->name()) {
         $path = $this->path();
         if (is_file($path . '/' . $this->_original->name())) {
             rename($path . '/' . $this->_original->name(), $path . '/' . $this->name());
         }
     }
     $this->_action = null;
     $this->_original = null;
 }