files = $files; } public function handle() { $name = trim($this->input->getArgument('name')); $group = trim($this->input->getOption('group')); $path = trim($this->input->getOption('path')); if (empty($path)) { $path = $this->resolveSettingsPath(); } $this->ensureSettingClassDoesntAlreadyExist($name, $path); $this->files->ensureDirectoryExists($path); $this->files->put( $this->getPath($name, $path), $this->getContent($name, $group, $path) ); } protected function getStub(): string { return <<getNamespace($path), $name, $group], $this->getStub() ); } protected function ensureSettingClassDoesntAlreadyExist($name, $path): void { if ($this->files->exists($this->getPath($name, $path))) { throw new InvalidArgumentException(sprintf('%s already exists!', $name)); } } protected function resolveSettingsPath(): string { return config('settings.setting_class_path', app_path('Settings')); } protected function getPath($name, $path): string { return $path . '/' . $name . '.php'; } protected function getNamespace($path): string { $path = preg_replace( [ '/^(' . preg_quote(base_path(), '/') . ')/', '/\//', ], [ '', '\\', ], $path ); $namespace = implode('\\', array_map(fn ($directory) => ucfirst($directory), explode('\\', $path))); // Remove leading backslash if present if (substr($namespace, 0, 1) === '\\') { $namespace = substr($namespace, 1); } return $namespace; } }