Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 22 additions & 55 deletions docs/getting_started/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ Require it with an explicit version constraint allowing its desired stability.

## Initial Setup

There are a few setup items to do before you can start using Shield in
your project.

### Command Setup

1. Run the following command. This command handles steps 1-5 of *Manual Setup* and runs the migrations.
1. Run the following command. This command handles steps 1-6 of *Manual Setup*.

```console
php spark shield:setup
Expand All @@ -67,36 +70,8 @@ Require it with an explicit version constraint allowing its desired stability.
If you want to customize table names, you must change the table names before running database migrations.
See [Customizing Table Names](../customization/table_names.md).

2. Configure **app/Config/Email.php** to allow Shield to send emails with the [Email Class](https://codeigniter.com/user_guide/libraries/email.html).

```php
<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Email extends BaseConfig
{
/**
* @var string
*/
public $fromEmail = '[email protected]';

/**
* @var string
*/
public $fromName = 'your name';

// ...
}
```

### Manual Setup

There are a few setup items to do before you can start using Shield in
your project.

1. Copy the **Auth.php**, **AuthGroups.php**, and **AuthToken.php** from **vendor/codeigniter4/shield/src/Config/** into your project's config folder and update the namespace to `Config`. You will also need to have these classes extend the original classes. See the example below. These files contain all the settings, group, and permission information for your application and will need to be modified to meet the needs of your site.

```php
Expand Down Expand Up @@ -138,7 +113,24 @@ your project.

4. **Security Setup** Set `Config\Security::$csrfProtection` to `'session'` for security reasons, if you use Session Authenticator.

5. **Migration** Run the migrations.
5. Configure **app/Config/Email.php** to allow Shield to send emails with the [Email Class](https://codeigniter.com/user_guide/libraries/email.html).

```php
<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Email extends BaseConfig
{
public string $fromEmail = '[email protected]';
public string $fromName = 'your name';
// ...
}
```

6. **Migration** Run the migrations.

!!! note

Expand All @@ -155,28 +147,3 @@ your project.

1. Remove sample migration files in **tests/_support/Database/Migrations/**
2. Or install `sqlite3` php extension

6. Configure **app/Config/Email.php** to allow Shield to send emails.

```php
<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Email extends BaseConfig
{
/**
* @var string
*/
public $fromEmail = '[email protected]';

/**
* @var string
*/
public $fromName = 'your name';

// ...
}
```
6 changes: 6 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
Expand Down Expand Up @@ -109,6 +110,11 @@
__DIR__ . '/tests/Commands/UserModelGeneratorTest.php',
__DIR__ . '/tests/Controllers/LoginTest.php',
],

RecastingRemovalRector::class => [
// To check old Email Config file
__DIR__ . '/src/Commands/Setup.php',
],
]);

// auto import fully qualified class names
Expand Down
89 changes: 89 additions & 0 deletions src/Commands/BaseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

declare(strict_types=1);

namespace CodeIgniter\Shield\Commands;

use CodeIgniter\CLI\BaseCommand as FrameworkBaseCommand;
use CodeIgniter\CLI\Commands;
use CodeIgniter\Shield\Commands\Utils\InputOutput;
use Psr\Log\LoggerInterface;

abstract class BaseCommand extends FrameworkBaseCommand
{
protected static ?InputOutput $io = null;

/**
* The group the command is lumped under
* when listing commands.
*
* @var string
*/
protected $group = 'Shield';

public function __construct(LoggerInterface $logger, Commands $commands)
{
parent::__construct($logger, $commands);

$this->ensureInputOutput();
}

/**
* Asks the user for input.
*
* @param string $field Output "field" question
* @param array|string $options String to a default value, array to a list of options (the first option will be the default value)
* @param array|string $validation Validation rules
*
* @return string The user input
*/
protected function prompt(string $field, $options = null, $validation = null): string
{
return self::$io->prompt($field, $options, $validation);
}

/**
* Outputs a string to the cli on its own line.
*/
protected function write(
string $text = '',
?string $foreground = null,
?string $background = null
): void {
self::$io->write($text, $foreground, $background);
}

/**
* Outputs an error to the CLI using STDERR instead of STDOUT
*/
protected function error(
string $text,
string $foreground = 'light_red',
?string $background = null
): void {
self::$io->error($text, $foreground, $background);
}

protected function ensureInputOutput(): void
{
if (self::$io === null) {
self::$io = new InputOutput();
}
}

/**
* @internal Testing purpose only
*/
public static function setInputOutput(InputOutput $io): void
{
self::$io = $io;
}

/**
* @internal Testing purpose only
*/
public static function resetInputOutput(): void
{
self::$io = null;
}
}
Loading