1: <?php
2: 3: 4: 5: 6:
7:
8: namespace Peg\Custom\Command\Action;
9:
10: use Peg\Custom\Settings;
11: use Peg\Custom\Application;
12: use Peg\Custom\CommandLine\Error;
13: use Peg\Custom\Utilities\FileSystem;
14:
15: 16: 17:
18: class Init extends \Peg\Custom\CommandLine\Action
19: {
20:
21: public function OnCall(\Peg\Custom\CommandLine\Command $command)
22: {
23:
24: $authors = $command->GetOption("authors")->GetValue();
25: $contributors = $command->GetOption("contributors")->GetValue();
26: $name = $command->GetOption("name")->GetValue();
27: $version = $command->GetOption("initial-version")->GetValue();
28: $force = $command->GetOption("force")->active;
29: $config_type = $command->GetOption("config-type")->GetValue();
30:
31:
32: $extension_dir = Application::GetCwd();
33:
34: if(strlen($command->value) > 0)
35: $extension_dir .= "/" . $command->value;
36:
37: if(!file_exists($extension_dir))
38: FileSystem::MakeDir($extension_dir, 0755, true);
39:
40:
41: $dir_parts = explode("/", str_replace("\\", "/", $extension_dir));
42:
43: $extension = $dir_parts[count($dir_parts) - 1];
44:
45: if(strlen($name) > 0)
46: $extension = $name;
47:
48: $files = FileSystem::GetDirContent($extension_dir);
49:
50: if(!$force)
51: {
52: if(count($files) > 0)
53: Error::Show(t("The directory you are trying to initialize is not empty."));
54: }
55:
56:
57: if($config_type == "json")
58: {
59: Settings::SetBackEnd(new \Peg\Custom\Config\JSON);
60: Settings::Load($extension_dir, "peg.json");
61: }
62: else
63: {
64: Settings::SetBackEnd(new \Peg\Custom\Config\INI);
65: Settings::Load($extension_dir, "peg.conf");
66: }
67:
68: $this->CopySkeleton($extension_dir, $extension, $version, $authors, $contributors);
69: }
70:
71: 72: 73: 74: 75: 76: 77:
78: private function CopySkeleton($directory, $extension, $version, $authors, $contributors)
79: {
80: Settings::SetExtensionName($extension);
81: Settings::SetAuthors($authors);
82: Settings::SetContributors($contributors);
83: Settings::SetVersion($version);
84:
85: FileSystem::RecursiveCopyDir(Application::GetSkeletonPath(), $directory);
86:
87:
88: $date = date("F d Y");
89:
90: ob_start();
91: include($directory . "/CHANGES");
92:
93: $changes_content = ob_get_contents();
94: ob_end_clean();
95:
96: file_put_contents($directory . "/CHANGES", $changes_content);
97:
98:
99: $developers = trim($authors . ", " . $contributors, ", ");
100:
101: ob_start();
102: include($directory . "/CREDITS");
103:
104: $credits_content = ob_get_contents();
105: ob_end_clean();
106:
107: file_put_contents($directory . "/CREDITS", $credits_content);
108: }
109:
110: }