コード例 #1
0
ファイル: ConfigCommand.php プロジェクト: afflicto/webdev
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $wd = Webdev::getInstance();
     $key = $input->getArgument('key');
     $value = $input->getArgument('value');
     if ($value !== null) {
         $wd->config->set($key, $value);
         $wd->save();
         $output->writeln('updated ' . $key . ' to ' . $value);
     } else {
         if ($wd->config->has($key)) {
             $value = $wd->config->get($key);
             if (is_array($value)) {
                 $value = var_export($value, true);
             }
             $output->writeln($key . ' => ' . $value);
         } else {
             $output->writeln('Unknown key.');
         }
     }
 }
コード例 #2
0
ファイル: CreateCommand.php プロジェクト: afflicto/webdev
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $wd = Webdev::getInstance();
     $config = $wd->config;
     # input
     $name = $input->getArgument('name');
     $web_provider = $input->getArgument('web server provider');
     $database_provider = $input->getArgument('database provider');
     $database_name = $input->getArgument('database name');
     if ($database_name == null) {
         $database_name = $name;
     }
     $project = ['name' => $name, 'documents' => null, 'web' => [], 'database' => [], 'hosts' => []];
     $output->writeln('Generating project "' . $name . '"...');
     if ($config->get('documents.enabled')) {
         $project['documents'] = $wd->createDocumentsDirectory($name);
     }
     if ($config->get('web.enabled') && $web_provider !== 'none') {
         $project['web'] = $wd->createWebDirectory($name, $web_provider);
         # is it a wamp web server?
         if ($config->get('web.default') == 'wamp') {
             # is virtualhosts managed?
             if ($config->get('web.providers.wamp.virtualhosts.enabled')) {
                 $file = $config->get('web.providers.wamp.virtualhosts.file');
                 $output->writeln('Generating wamp virtualhost directive in "' . $file . '"...');
                 $choice = $this->choice("<question>Should wamp serve the web root of your project, or a sub-directory like '/public'?.</question>\n", ['It should serve the project web root (' . $project['web']['root'] . ').', 'A sub-directory of my choosing.']);
                 if ($choice == 'A sub-directory of my choosing.') {
                     $vhost_dir = $this->ask("Tell me the name of the sub-directory (default is 'public')\n-> ", 'public');
                 } else {
                     $vhost_dir = '';
                 }
                 $vhost_dir = rtrim($project['web']['root'] . '/' . $vhost_dir, '/');
                 $project['web']['virtualhost'] = $wd->createVirtualhostDirective($file, $name, $vhost_dir);
             }
         }
         # 'git init'?
         if ($config->get('git')) {
             if ($this->ask("Run 'git init' in '" . $project['web']['root'] . "'? (y/n)\n-> ", 'no')) {
                 $output->writeln('Ok.');
                 $cwd = getcwd();
                 # go run git init
                 chdir($project['web']['root']);
                 shell_exec('git init');
                 chdir($cwd);
                 $output->writeln('Git initialized!');
             }
         }
     }
     # create datbase
     if ($config->get('database.enabled') && $database_provider !== 'none') {
         $project['database'] = $wd->createDatabase($database_name, $database_provider);
     }
     # add hosts
     if ($config->get('hosts.enabled')) {
         if ($this->confirm('Add hosts file?')) {
             $project['hosts'] = $wd->addHostsFile($name);
         }
     }
     # add the project
     $config->set('projects.' . $name, $project);
     # save config
     $wd->save();
     # done
     $output->writeln("Done! Generated Project:");
     $output->writeln($name . ' => ' . var_export($project, true));
 }
コード例 #3
0
ファイル: AddCommand.php プロジェクト: afflicto/webdev
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $wd = Webdev::getInstance();
     $config = $wd->config;
     $project = ['name' => null, 'documents' => null, 'web' => null, 'database' => null, 'hosts' => []];
     # web
     if ($config->get('web.enabled')) {
         $name = $this->ask("What's the name of the project's web root directory? This will be the project name as well.\n-> ");
         $project['name'] = $name;
         # do we have multiple web providers?
         if (count($config->get('web.providers')) > 1) {
             # get all webRoots
             $places = [];
             foreach ($config->get('web.providers') as $name => $provider) {
                 $places[$name] = $provider['web_root'];
             }
             $web = $this->choice("Where's the project located?", $places);
             $project['web'] = ['root' => $web . '/' . $name];
         } else {
             $defaultProvider = $config->get('web.default');
             $web = $config->get('web.providers.' . $defaultProvider . '.web_root') . '/' . $name;
             $output->writeln("Assumed location is '{$web}'.");
             $project['web'] = ['root' => $web, 'provider' => $defaultProvider];
         }
         # virtualhosts?
         if ($project['web']['provider'] == 'wamp' && $config->get('web.providers.wamp.virtualhosts.enabled') && $this->confirm("Create virtualhost directive?")) {
             $choice = $this->choice("<question>Should wamp serve the web root of your project, or a sub-directory like '/public'?.</question>\n", ['It should serve the project web root (' . $project['web']['root'] . ').', 'A sub-directory of my choosing.']);
             if ($choice == 'A sub-directory of my choosing.') {
                 $vhost_dir = $this->ask("Tell me the name of the sub-directory (default is 'public')\n-> ", 'public');
             } else {
                 $vhost_dir = '';
             }
             $vhost_dir = rtrim($project['web']['root'] . '/' . $vhost_dir, '/');
             $project['web']['virtualhost'] = $wd->createVirtualhostDirective($config->get('web.providers.wamp.virtualhosts.file'), $project['name'], $vhost_dir);
         }
     } else {
         $project['name'] = $this->ask("What's the name of the project at least?\n-> ");
     }
     # hosts file
     if ($config->get('hosts.enabled') && $this->confirm('Update hosts file?')) {
         $project['hosts'] = $wd->addHostsFile($project['name']);
     }
     # database
     if ($config->get('database.enabled') && $this->confirm("Does this project use a database?")) {
         # determine database provider
         $database_provider = null;
         if (count($config->get('database.providers')) > 1) {
             $providers = array_keys($config->get('database.providers'));
             $database_provider = $this->choice("Choose a provider", $providers, $config->get('database.default'));
         } else {
             $database_provider = $config->get('database.default');
         }
         # get database name, or create one.
         if ($this->confirm("Does the database exist?")) {
             $dbName = $this->ask("What's the name of the database?\n-> ", $project['name']);
             $project['database'] = ['provider' => $database_provider, 'name' => $dbName];
         } else {
             if ($this->confirm("Shall I create one named '" . $project['name'] . "'?\n->")) {
                 $project['database'] = $wd->createDatabase($project['name'], $database_provider);
             } else {
                 $output->writeln('Ok.');
             }
         }
     }
     $config->set('projects.' . $project['name'], $project);
     # save
     $wd->save();
 }
コード例 #4
0
ファイル: InitCommand.php プロジェクト: afflicto/webdev
 protected function execute(InputInterface $in, OutputInterface $out)
 {
     $this->in = $in;
     $this->out = $out;
     $this->wd = Webdev::getInstance();
     $this->config = $this->wd->config;
     # I'm lazy.
     $config = $this->config;
     # reset config
     $config->set($this->wd->defaultConfiguration);
     //web servers
     if ($this->ask("First off. Would you like to add a web server? (y/n)\n-> ", 'n') == 'y') {
         $this->addWebServer();
         if (count($config->get('web.providers')) > 1) {
             $providers = array_keys($config->get('web.providers'));
             $default_provider = $this->choice("You have added more than one web server. Which one should be the default for new projects?", $providers);
             $config->set('web.default', $default_provider);
             $out->writeln('Ok!');
         }
     } else {
         $out->writeln('No web server then.');
     }
     //documents
     if ($this->ask("Do you also tend to create a separate folder somewhere else for things like documents, graphics and other resources? (y/n)\n-> ", 'n') == 'y') {
         $config->set('documents.enabled', true);
         $documents_root = $this->ask("Where do you store them?\n-> ");
         $documents_root = rtrim(str_replace('\\', '/', $documents_root), '/');
         $config->set('documents.root', $documents_root);
     }
     //hosts file
     if ($this->ask("Shall I manage the 'hosts' file on your system? For mapping 'newproject.dev' to 127.0.0.1 etc. (y/n)\n-> ", 'n') == 'y') {
         $config->set('hosts.enabled', true);
         if ($this->wd->getOS() == Webdev::OS_WINDOWS) {
             $hosts_file = 'C:/Windows/System32/drivers/etc/hosts';
         } else {
             $hosts_file = '/etc/hosts';
         }
         if ($this->ask("Is '" . $hosts_file . "' your hosts file? (y/n)\n-> ", 'no') !== 'y') {
             $hosts_file = $this->ask("Ok. Where is it?\n-> ");
         }
         $hosts_file = rtrim(str_replace('\\', '/', $hosts_file), '/');
         $config->set('hosts.file', $hosts_file);
     }
     //database
     if ($this->ask("Shall I help you setup databases for your projects too? (y/n)\n-> ", 'no') == 'y') {
         $out->writeln("Ok...");
         $this->config->set('database.enabled', true);
         $this->addDatabaseProvider();
         if (count($config->get('database.providers')) > 1) {
             $providers = array_keys($config->get('database.providers'));
             $default_provider = $this->choice("You have added more than one database server. Which one should be the default for new projects?", $providers);
             $config->set('database.default', $default_provider);
             $out->writeln('Ok!');
         }
     }
     if ($this->ask("Do you use git? I can 'git init' automatically, or ask each time, whenever you create a new project. (y/n)\n-> ", 'no')) {
         $this->config->set('git', true);
     }
     $out->writeln("<info>All set! To get started, run 'webdev list' to get a list of available commands. Perhaps try 'webdev create' to create a new project?\n");
     $this->wd->save();
 }