Example #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle(\Pingpong\Modules\Repository $modules)
 {
     $baseUrl = str_replace(public_path(), '', $modules->getAssetsPath());
     $config = ['baseUrl' => rtrim($baseUrl, '/') . '/', 'shim' => [], 'paths' => [], 'urlArgs' => time()];
     $dir = public_path('backend');
     if (!is_dir($dir)) {
         mkdir($dir);
     }
     /* @var Module $module */
     foreach ($modules->enabled() as $module) {
         $path = $module->getExtraPath('Config/backend.php');
         if (file_exists($path)) {
             $value = (require $path);
             if (is_array($value) && array_key_exists('requirejs', $value) && is_array($value['requirejs'])) {
                 foreach ($value['requirejs'] as $m => $c) {
                     if (is_string($c)) {
                         $config['paths'][$m] = $module->getLowerName() . '/' . ltrim($c, '/');
                     } elseif (is_array($c)) {
                         if (array_key_exists('path', $c)) {
                             $config['paths'][$m] = $module->getLowerName() . '/' . ltrim($c['path'], '/');
                         }
                         if (array_key_exists('deps', $c)) {
                             $config['shim'][$m] = ['deps' => (array) $c['deps']];
                         }
                     }
                 }
             }
         }
     }
     $config = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
     file_put_contents(public_path('backend/config.js'), "require.config({$config});");
 }
Example #2
0
 /**
  * Retrieve layout file from all module but just in current theme
  *
  * @return mixed
  */
 public function scanLayout()
 {
     $key = $this->getKey(['scan', 'all-layout', 'in', 'all-modules', 'but', 'only', 'in', 'current-theme']);
     if (is_null($this->getData($key))) {
         $pathModules = $this->module->getPath();
         $moduleDirectories = scandir($pathModules);
         foreach ($moduleDirectories as $moduleDir) {
             if (!in_array($moduleDir, [".", ".."])) {
                 /*Layouts path  của module hiện tại*/
                 $currentFolderLayoutsPathInModule = $pathModules . '/' . $moduleDir . '/themes/' . $this->izTheme->getCurrentThemeName() . '/layouts';
                 /*Check layouts path file exist*/
                 if (!file_exists($currentFolderLayoutsPathInModule)) {
                     continue;
                 }
                 $layoutFiles = scandir($currentFolderLayoutsPathInModule);
                 foreach ($layoutFiles as $layoutFile) {
                     if (!in_array($layoutFile, [".", ".."])) {
                         if (pathinfo($layoutFile, PATHINFO_EXTENSION) !== 'php') {
                             continue;
                         }
                         $layoutFileNameWithoutExt = preg_replace('/(\\.blade\\.php)$/', '', $layoutFile);
                         $this->_layouts[] = $layoutFileNameWithoutExt;
                     }
                 }
             }
         }
         $this->setData($key, $this->_layouts);
     }
     return $this->getData($key);
 }
Example #3
0
 /**
  * Run the migration from the specified module.
  *
  * @param string $name
  *
  * @return mixed
  */
 protected function migrate($name)
 {
     $module = $this->module->findOrFail($name);
     $this->call('migrate', ['--path' => $this->getPath($module), '--database' => $this->option('database'), '--pretend' => $this->option('pretend'), '--force' => $this->option('force')]);
     if ($this->option('seed')) {
         $this->call('module:seed', ['module' => $name]);
     }
 }
Example #4
0
 /**
  * Boot widgets for all enabled modules
  * @param Repository $modules
  */
 private function bootWidgets(Repository $modules)
 {
     foreach ($modules->enabled() as $module) {
         if (!$module->widgets) {
             continue;
         }
         foreach ($module->widgets as $widgetClass) {
             app($widgetClass)->boot();
         }
     }
 }
Example #5
0
 /**
  * Retrieve all file xml in all theme but just in current theme
  * FIXME: Need cache here
  *
  * @return mixed
  */
 protected function scanThemeXml()
 {
     /*FIXME: need cache xml*/
     $key = $this->getKey(['retrieve', 'all-xml', 'in', 'all-modules', 'only', 'current-theme']);
     if (is_null($this->getData($key))) {
         $pathModules = $this->module->getPath();
         $moduleDirectories = scandir($pathModules);
         foreach ($moduleDirectories as $moduleDir) {
             if (!in_array($moduleDir, [".", ".."])) {
                 /*Xml path  của module hiện tại*/
                 $currentFolderXmlPathInModule = $pathModules . '/' . $moduleDir . '/themes/' . $this->getCurrentTheme() . '/xml';
                 /*Check xml path file exist*/
                 if (!file_exists($currentFolderXmlPathInModule)) {
                     continue;
                 }
                 $xmlFiles = scandir($currentFolderXmlPathInModule);
                 foreach ($xmlFiles as $xmlFile) {
                     if (!in_array($xmlFile, [".", ".."])) {
                         if (pathinfo($xmlFile, PATHINFO_EXTENSION) !== 'xml') {
                             continue;
                         }
                         $currentXMLDir = $currentFolderXmlPathInModule . '/' . $xmlFile;
                         $xml = simplexml_load_file($currentXMLDir);
                         $xmlFile = preg_replace('/\\.[^.\\s]{3,4}$/', '', $xmlFile);
                         // May have many xml for this path in themes each modules
                         if (!isset($this->xmlThemeData[$xmlFile])) {
                             $this->xmlThemeData[$xmlFile] = [];
                         }
                         foreach ($xml as $node => $scope) {
                             switch ($node) {
                                 case 'bower_components':
                                     $this->convertXmlScopeBowerComponent($scope, $xmlFile);
                                     break;
                                 case 'custom_assets':
                                     $this->convertXmlScopeCustomAssets($scope, $xmlFile);
                                     break;
                                 case 'view_data':
                                     $this->convertXmlScopeViewData($scope, $xmlFile);
                                     break;
                                 case 'app_dependencies':
                                     $this->convertXmlScopeAppDependency($scope, $xmlFile);
                                     break;
                             }
                         }
                     }
                 }
             }
         }
         $this->setData($key, $this->xmlThemeData);
     }
     return $this->getData($key);
 }
Example #6
0
 /**
  * Run the migration from the specified module.
  *
  * @param string $name
  *
  * @return mixed
  */
 protected function migrate($name)
 {
     $module = $this->module->findOrFail($name);
     $migrator = new Migrator($module);
     $migrated = $migrator->migrate();
     if (count($migrated)) {
         foreach ($migrated as $migration) {
             $this->line("Migrated: <info>{$migration}</info>");
         }
         return;
     }
     $this->comment('Nothing to migrate.');
     if ($this->option('seed')) {
         $this->call('module:seed', ['module' => $name]);
     }
 }
Example #7
0
 /**
  * Get all assets from all modules
  *
  * @return array
  * @throws \Exception
  */
 public function getAssets()
 {
     if (!isset($isSupport)) {
         throw new \Exception('Please get From Theme');
     }
     if (is_null($this->assets)) {
         $this->assets = [];
         foreach ($this->module->getByStatus(1) as $module) {
             /** @var \Pingpong\Modules\Module $module */
             if ($asset = $this->getAssetsByModuleName($module->getName())) {
                 $this->assets = array_merge($this->assets, $asset);
             }
         }
     }
     return $this->assets;
 }
Example #8
0
 /**
  * Get destination path.
  *
  * @return string
  */
 public function getDestinationPath()
 {
     if ($this->path) {
         return $this->path;
     }
     return $this->repository->getModulePath($this->getModuleName());
 }
Example #9
0
 /**
  * Get all assets in each theme in each module
  *
  * @return array
  * @throws \Exception
  */
 public function getAssetsTree()
 {
     if (is_null($this->assets)) {
         $this->assets = [];
         $pathModules = $this->module->getPath();
         $moduleDirs = scandir($pathModules);
         foreach ($moduleDirs as $moduleDir) {
             if (!in_array($moduleDir, [".", ".."])) {
                 /*Path Config/Vendor của module hiện tại*/
                 $currentModuleThemePaths = $pathModules . '/' . $moduleDir . '/themes';
                 /*Kiểm tra xem module hiện tại có thư mục themes không*/
                 if (!file_exists($currentModuleThemePaths)) {
                     continue;
                 }
                 $themePath = scandir($currentModuleThemePaths);
                 foreach ($themePath as $themDir) {
                     if (!in_array($themDir, [".", ".."])) {
                         $currentThemeDir = $currentModuleThemePaths . '/' . $themDir . '/config.php';
                         // Check file config.php existed
                         if (!file_exists($currentThemeDir)) {
                             continue;
                         }
                         $themeConfig = (include $currentThemeDir);
                         if (isset($themeConfig['assets'])) {
                             $assetWithThemeName = [];
                             foreach ($themeConfig['assets'] as $k => $asset) {
                                 $asset['theme_name'] = $themDir;
                                 $assetWithThemeName[$k] = $asset;
                             }
                             $this->assets = array_merge($this->assets, $assetWithThemeName);
                         }
                     }
                 }
             }
         }
     }
     return $this->assets;
 }
 public function testInstallAndUpdateModule()
 {
     $this->repository->install('pingpongcms/core');
 }
Example #11
0
 /**
  * Set stub path.
  *
  * @param string $stubPath
  * @return $this 
  * @static 
  */
 public static function setStubPath($stubPath)
 {
     return \Pingpong\Modules\Repository::setStubPath($stubPath);
 }
Example #12
0
 public function destroy($name)
 {
     $module = $this->modules->findOrFail($name);
     $module->delete();
     return redirect()->back();
 }
Example #13
0
 /**
  * Display a list of all modules
  * @return View
  */
 public function index()
 {
     $modules = $this->modules->all();
     return view('workshop::admin.modules.index', compact('modules'));
 }
Example #14
0
 /**
  * Get laravel filesystem instance.
  *
  * @return \Illuminate\Filesystem\Filesystem
  */
 public function getFilesystem()
 {
     return $this->repository->getFiles();
 }