Permalink
Please sign in to comment.
Showing
with
385 additions
and 227 deletions.
- +2 −2 config/console.yml
- +15 −0 config/services.yml
- +87 −0 config/skeletons.yml
- +13 −225 console/create.php
- +203 −0 helper/packager.php
- +2 −0 language/en/common.php
- +63 −0 skeleton.php
4
config/console.yml
15
config/services.yml
| @@ -1,2 +1,17 @@ | ||
| imports: | ||
| - { resource: console.yml } | ||
| + - { resource: skeletons.yml } | ||
| + | ||
| +services: | ||
| + phpbb.skeleton.helper.packager: | ||
| + class: phpbb\skeleton\helper\packager | ||
| + arguments: | ||
| + - @user | ||
| + - @path_helper | ||
| + - @phpbb.skeleton.collection | ||
| + - %core.root_path% | ||
| + | ||
| + phpbb.skeleton.helper.validator: | ||
| + class: phpbb\skeleton\helper\validator | ||
| + arguments: | ||
| + - @user |
87
config/skeletons.yml
| @@ -0,0 +1,87 @@ | ||
| +services: | ||
| + phpbb.skeleton.collection: | ||
| + class: phpbb\di\service_collection | ||
| + arguments: | ||
| + - @service_container | ||
| + tags: | ||
| + - { name: service_collection, tag: phpbb.skeleton.ext.skeleton } | ||
| + | ||
| + phpbb.skeleton.ext.skeleton.phplistener: | ||
| + class: phpbb\skeleton\skeleton | ||
| + arguments: | ||
| + - 'phplistener' | ||
| + - true | ||
| + - [] | ||
| + - ['config/services.yml', 'event/main_listener.php'] | ||
| + tags: | ||
| + - { name: phpbb.skeleton.ext.skeleton } | ||
| + | ||
| + phpbb.skeleton.ext.skeleton.htmllistener: | ||
| + class: phpbb\skeleton\skeleton | ||
| + arguments: | ||
| + - 'htmllistener' | ||
| + - true | ||
| + - [] | ||
| + - ['styles/prosilver/template/event/overall_header_navigation_prepend.html'] | ||
| + tags: | ||
| + - { name: phpbb.skeleton.ext.skeleton } | ||
| + | ||
| + phpbb.skeleton.ext.skeleton.acp: | ||
| + class: phpbb\skeleton\skeleton | ||
| + arguments: | ||
| + - 'acp' | ||
| + - true | ||
| + - [] | ||
| + - ['acp/main_info.php', 'acp/main_module.php', 'adm/style/demo_body.html', 'language/en/info_acp_demo.php'] | ||
| + tags: | ||
| + - { name: phpbb.skeleton.ext.skeleton } | ||
| + | ||
| + phpbb.skeleton.ext.skeleton.migration: | ||
| + class: phpbb\skeleton\skeleton | ||
| + arguments: | ||
| + - 'migration' | ||
| + - true | ||
| + - [] | ||
| + - ['migrations/release_1_0_0.php', 'migrations/release_1_0_1.php'] | ||
| + tags: | ||
| + - { name: phpbb.skeleton.ext.skeleton } | ||
| + | ||
| + phpbb.skeleton.ext.skeleton.service: | ||
| + class: phpbb\skeleton\skeleton | ||
| + arguments: | ||
| + - 'service' | ||
| + - true | ||
| + - [] | ||
| + - ['service.php', 'config/services.yml', 'config/parameters.yml'] | ||
| + tags: | ||
| + - { name: phpbb.skeleton.ext.skeleton } | ||
| + | ||
| + phpbb.skeleton.ext.skeleton.controller: | ||
| + class: phpbb\skeleton\skeleton | ||
| + arguments: | ||
| + - 'controller' | ||
| + - true | ||
| + - [] | ||
| + - ['config/routing.yml', 'config/services.yml', 'event/main_listener.php', 'language/en/common.php', 'controller/main.php', 'styles/prosilver/template/demo_body.html'] | ||
| + tags: | ||
| + - { name: phpbb.skeleton.ext.skeleton } | ||
| + | ||
| + phpbb.skeleton.ext.skeleton.tests: | ||
| + class: phpbb\skeleton\skeleton | ||
| + arguments: | ||
| + - 'tests' | ||
| + - true | ||
| + - [] | ||
| + - ['tests/controller/main_test.php', 'tests/dbal/fixtures/config.xml', 'tests/dbal/simple_test.php', 'tests/functional/demo_test.php', 'tests/mock/controller_helper.php', 'tests/mock/template.php', 'tests/mock/user.php', 'phpunit.xml.dist'] | ||
| + tags: | ||
| + - { name: phpbb.skeleton.ext.skeleton } | ||
| + | ||
| + phpbb.skeleton.ext.skeleton.travis: | ||
| + class: phpbb\skeleton\skeleton | ||
| + arguments: | ||
| + - 'travis' | ||
| + - true | ||
| + - ['tests'] | ||
| + - ['travis/prepare-phpbb.sh', '.travis.yml'] | ||
| + tags: | ||
| + - { name: phpbb.skeleton.ext.skeleton } |
238
console/create.php
203
helper/packager.php
| @@ -0,0 +1,203 @@ | ||
| +<?php | ||
| +/** | ||
| + * | ||
| + * This file is part of the phpBB Forum Software package. | ||
| + * | ||
| + * @copyright (c) phpBB Limited <https://www.phpbb.com> | ||
| + * @license GNU General Public License, version 2 (GPL-2.0) | ||
| + * | ||
| + * For full copyright and license information, please see | ||
| + * the docs/CREDITS.txt file. | ||
| + * | ||
| + */ | ||
| + | ||
| +namespace phpbb\skeleton\helper; | ||
| + | ||
| +use phpbb\config\config; | ||
| +use phpbb\di\service_collection; | ||
| +use phpbb\path_helper; | ||
| +use phpbb\template\context; | ||
| +use phpbb\template\twig\twig; | ||
| +use phpbb\user; | ||
| +use Symfony\Component\Filesystem\Filesystem; | ||
| + | ||
| +class packager | ||
| +{ | ||
| + protected $data = array(); | ||
| + | ||
| + /** @var user */ | ||
| + protected $user; | ||
| + | ||
| + /** @var path_helper */ | ||
| + protected $path_helper; | ||
| + | ||
| + /** @var service_collection */ | ||
| + protected $collection; | ||
| + | ||
| + /** | ||
| + * Constructor | ||
| + * | ||
| + * @param user $user User instance (mostly for translation) | ||
| + * @param path_helper $path_helper The filesystem object | ||
| + * @param service_collection $collection | ||
| + * @param string $root_path | ||
| + */ | ||
| + public function __construct(user $user, path_helper $path_helper, service_collection $collection, $root_path) | ||
| + { | ||
| + $this->user = $user; | ||
| + $this->path_helper = $path_helper; | ||
| + $this->collection = $collection; | ||
| + $this->root_path = $root_path; | ||
| + } | ||
| + | ||
| + /** | ||
| + * @return array | ||
| + */ | ||
| + public function get_composer_dialog_values() | ||
| + { | ||
| + return array( | ||
| + 'author' => array( | ||
| + 'author_name' => null, | ||
| + 'author_email' => null, | ||
| + 'author_homepage' => null, | ||
| + 'author_role' => null, | ||
| + ), | ||
| + 'extension' => array( | ||
| + 'vendor_name' => null, | ||
| + 'extension_display_name' => null, | ||
| + 'extension_name' => null, | ||
| + 'extension_description' => null, | ||
| + 'extension_version' => '1.0.0-dev', | ||
| + 'extension_homepage' => null, | ||
| + 'extension_time' => date('Y-m-d'), | ||
| + ), | ||
| + 'requirements' => array( | ||
| + 'php_version' => '>=5.3.3', | ||
| + 'phpbb_version_min' => '>=3.1.4', | ||
| + 'phpbb_version_max' => '<3.2.0@dev', | ||
| + ) | ||
| + ); | ||
| + } | ||
| + | ||
| + /** | ||
| + * @return array | ||
| + */ | ||
| + public function get_component_dialog_values() | ||
| + { | ||
| + $components = array(); | ||
| + foreach ($this->collection as $service) | ||
| + { | ||
| + /** @var \phpbb\skeleton\skeleton $service */ | ||
| + $components[$service->get_name()] = array( | ||
| + 'default' => $service->get_default(), | ||
| + 'dependencies' => $service->get_dependencies(), | ||
| + 'files' => $service->get_files(), | ||
| + ); | ||
| + } | ||
| + | ||
| + return $components; | ||
| + } | ||
| + | ||
| + /** | ||
| + * @param array $data | ||
| + */ | ||
| + public function create_extension($data) | ||
| + { | ||
| + $ext_path = $this->root_path . 'store/tmp-ext/' . "{$data['extension']['vendor_name']}/{$data['extension']['extension_name']}/"; | ||
| + $filesystem = new Filesystem(); | ||
| + $filesystem->remove($this->root_path . 'store/tmp-ext/'); | ||
| + $filesystem->mkdir($ext_path); | ||
| + | ||
| + $template_engine = new twig($this->path_helper, new config(array( | ||
| + 'load_tplcompile' => true, | ||
| + 'tpl_allow_php' => false, | ||
| + 'assets_version' => null, | ||
| + )), $this->user, new context()); | ||
| + $template_engine->set_custom_style('skeletonextension', $this->root_path . 'ext/phpbb/skeleton/skeleton'); | ||
| + | ||
| + $template_engine->assign_vars(array( | ||
| + 'COMPONENT' => $data['components'], | ||
| + 'EXTENSION' => $data['extension'], | ||
| + 'REQUIREMENTS' => $data['requirements'], | ||
| + 'AUTHORS' => $data['authors'], | ||
| + )); | ||
| + | ||
| + $component_data = $this->get_component_dialog_values(); | ||
| + $skeleton_files = array( | ||
| + 'license.txt', | ||
| + 'README.md', | ||
| + ); | ||
| + | ||
| + foreach ($data['components'] as $component => $selected) | ||
| + { | ||
| + if ($selected && !empty($component_data[$component]['files'])) | ||
| + { | ||
| + $skeleton_files = array_merge($skeleton_files, $component_data[$component]['files']); | ||
| + } | ||
| + } | ||
| + | ||
| + foreach ($skeleton_files as $file) | ||
| + { | ||
| + $template_engine->set_filenames(array('body' => $file . '.tpl')); | ||
| + $body = $template_engine->assign_display('body'); | ||
| + if (substr($file, -5) === '.html') | ||
| + { | ||
| + $body = str_replace('<', '<', $body); | ||
| + $body = str_replace('{', '{', $body); | ||
| + } | ||
| + $filesystem->dumpFile($ext_path . $file, trim($body) . "\n"); | ||
| + } | ||
| + | ||
| + $filesystem->dumpFile($ext_path . 'composer.json', $this->get_composer_json_from_data($data)); | ||
| + } | ||
| + | ||
| + /** | ||
| + * @param array $data | ||
| + * @return string | ||
| + */ | ||
| + public function get_composer_json_from_data($data) | ||
| + { | ||
| + $composer = array( | ||
| + 'name' => "{$data['extension']['vendor_name']}/{$data['extension']['extension_name']}", | ||
| + 'type' => 'phpbb-extension', | ||
| + 'description' => "{$data['extension']['extension_description']}", | ||
| + 'homepage' => "{$data['extension']['extension_homepage']}", | ||
| + 'version' => "{$data['extension']['extension_version']}", | ||
| + 'time' => "{$data['extension']['extension_time']}", | ||
| + 'license' => 'GPL-2.0', | ||
| + 'authors' => array(), | ||
| + 'require' => array( | ||
| + 'php' => "{$data['requirements']['php_version']}", | ||
| + ), | ||
| + 'require-dev' => array( | ||
| + 'phpbb/epv' => 'dev-master', | ||
| + ), | ||
| + 'extra' => array( | ||
| + 'display-name' => "{$data['extension']['extension_display_name']}", | ||
| + 'soft-require' => array( | ||
| + 'phpbb/phpbb' => "{$data['requirements']['phpbb_version_min']},{$data['requirements']['phpbb_version_max']}", | ||
| + ), | ||
| + ), | ||
| + ); | ||
| + | ||
| + if ($data['components']['build']) | ||
| + { | ||
| + $composer['require-dev']['phing/phing'] = '2.4.*'; | ||
| + } | ||
| + | ||
| + foreach ($data['authors'] as $i => $author_data) | ||
| + { | ||
| + if ($data['authors'][$i]['author_name'] !== '') | ||
| + { | ||
| + $composer['authors'][] = array( | ||
| + 'name' => "{$data['authors'][$i]['author_name']}", | ||
| + 'email' => "{$data['authors'][$i]['author_email']}", | ||
| + 'homepage' => "{$data['authors'][$i]['author_homepage']}", | ||
| + 'role' => "{$data['authors'][$i]['author_role']}", | ||
| + ); | ||
| + } | ||
| + } | ||
| + | ||
| + return json_encode($composer, JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES); | ||
| + } | ||
| +} |
2
language/en/common.php
63
skeleton.php
| @@ -0,0 +1,63 @@ | ||
| +<?php | ||
| +/** | ||
| + * | ||
| + * This file is part of the phpBB Forum Software package. | ||
| + * | ||
| + * @copyright (c) phpBB Limited <https://www.phpbb.com> | ||
| + * @license GNU General Public License, version 2 (GPL-2.0) | ||
| + * | ||
| + * For full copyright and license information, please see | ||
| + * the docs/CREDITS.txt file. | ||
| + * | ||
| + */ | ||
| + | ||
| +namespace phpbb\skeleton; | ||
| + | ||
| +class skeleton | ||
| +{ | ||
| + /** @var string */ | ||
| + protected $name; | ||
| + | ||
| + /** @var bool */ | ||
| + protected $default; | ||
| + | ||
| + /** @var array */ | ||
| + protected $dependencies; | ||
| + | ||
| + /** @var array */ | ||
| + protected $files; | ||
| + | ||
| + /** | ||
| + * @param string $name | ||
| + * @param bool $default | ||
| + * @param array $dependencies | ||
| + * @param array $files | ||
| + */ | ||
| + public function __construct($name, $default, array $dependencies, array $files) | ||
| + { | ||
| + $this->name = $name; | ||
| + $this->default = $default; | ||
| + $this->dependencies = $dependencies; | ||
| + $this->files = $files; | ||
| + } | ||
| + | ||
| + public function get_name() | ||
| + { | ||
| + return $this->name; | ||
| + } | ||
| + | ||
| + public function get_default() | ||
| + { | ||
| + return $this->default; | ||
| + } | ||
| + | ||
| + public function get_dependencies() | ||
| + { | ||
| + return $this->dependencies; | ||
| + } | ||
| + | ||
| + public function get_files() | ||
| + { | ||
| + return $this->files; | ||
| + } | ||
| +} |
0 comments on commit
f0517b5