Skip to content

Commit

Permalink
Merge pull request #364 from alleyinteractive/custom-namespace
Browse files Browse the repository at this point in the history
Ensure the configuration is ready before Environment
  • Loading branch information
srtfisher authored Feb 14, 2023
2 parents e567650 + 288c295 commit d3646bb
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 20 deletions.
9 changes: 7 additions & 2 deletions src/mantle/application/class-application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Mantle\Support\Environment;
use Mantle\Support\Service_Provider;
use Mantle\View\View_Service_Provider;
use RuntimeException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

Expand Down Expand Up @@ -591,10 +592,14 @@ public function is_environment( ...$environments ): bool {
*
* @return string
*
* @throws RuntimeException Thrown on error determining namespace.
* @throws RuntimeException If the config is not set yet.
*/
public function get_namespace(): string {
return Environment::get( 'APP_NAMESPACE', 'App' );
if ( ! isset( $this['config'] ) ) {
throw new RuntimeException( 'Configurations not set yet.' );
}

return (string) $this['config']->get( 'app.namespace', 'App' );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package {{ namespace }}
*/

namespace App\Blocks;
namespace {{ namespace }}\Blocks;

use Mantle\Blocks\Block;
use Mantle\Contracts\Block as Block_Contract;
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/framework/console/generators/stubs/command.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package {{ namespace }}
*/

namespace App\Console;
namespace {{ namespace }}\Console;

use Mantle\Console\Command;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package {{ namespace }}
*/

namespace App\Http\Controller;
namespace {{ namespace }}\Http\Controller;

use Mantle\Http\Controller;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// phpcs:disable Squiz.Commenting.FunctionComment.MissingParamComment

namespace App\Factory;
namespace {{ namespace }}\Factory;

use Faker\Generator as Faker;
use Mantle\Support\Str;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// phpcs:disable Squiz.Commenting.FunctionComment.MissingParamComment

namespace App\Factory;
namespace {{ namespace }}\Factory;

use Faker\Generator as Faker;
use Mantle\Support\Str;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package {{ namespace }}
*/

namespace App\Console\Generators;
namespace {{ namespace }}\Console\Generators;

use Mantle\Framework\Console\Generators\Stub_Generator_Command;

Expand Down
2 changes: 1 addition & 1 deletion src/mantle/framework/console/generators/stubs/job.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package Mantle
*/

namespace App\Jobs;
namespace {{ namespace }}\Jobs;

use Mantle\Contracts\Queue\Can_Queue;
use Mantle\Contracts\Queue\Job;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package {{ namespace }}
*/

namespace App\Http\Middleware;
namespace {{ namespace }}\Http\Middleware;

use Closure;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package {{ namespace }}
*/

namespace App\Models;
namespace {{ namespace }}\Models;

use Mantle\Contracts\Database\Registrable;
use Mantle\Database\Model\Post;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package {{ namespace }}
*/

namespace App\Models;
namespace {{ namespace }}\Models;

use Mantle\Database\Model\Post;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package {{ namespace }}
*/

namespace App\Models;
namespace {{ namespace }}\Models;

use Mantle\Contracts\Database\Registrable;
use Mantle\Database\Model\Term;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package {{ namespace }}
*/

namespace App\Models;
namespace {{ namespace }}\Models;

use Mantle\Database\Model\Term;

Expand Down
9 changes: 7 additions & 2 deletions tests/framework/blocks/test-block-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ protected function setUp(): void {
parent::setUp();

// Mock a true Mantle application.
Environment::get_repository()->set( 'APP_NAMESPACE', 'Mantle\\Tests' );
$this->app->set_app_path( dirname( __DIR__, 2 ) );

$this->app['config']->set( 'app.namespace', 'Mantle\\Tests' );
}

protected function tearDown(): void {
Environment::get_repository()->clear( 'APP_NAMESPACE' );
$this->app['config']->set( 'app.namespace', 'App' );
$this->app->set_app_path( $this->app->get_base_path( 'app' ) );

parent::tearDown();
}

/**
Expand Down Expand Up @@ -58,6 +61,8 @@ public function testBlockProviderRegistersBlocks() {
$app->set_base_path( getcwd() );
$app->set_app_path( __DIR__ . '/fixtures' );

$app['config'] = $this->app['config'];

$this->assertEquals( 'Mantle\\Tests', $app->get_namespace() );

/**
Expand Down
6 changes: 4 additions & 2 deletions tests/framework/events/test-discover-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ protected function setUp(): void {
parent::setUp();

// Mock a true Mantle application.
Environment::get_repository()->set( 'APP_NAMESPACE', 'Mantle\\Tests' );
$this->app['config']->set( 'app.namespace', 'Mantle\\Tests' );
$this->app->set_app_path( dirname( __DIR__, 2 ) );
}

protected function tearDown(): void {
Environment::get_repository()->clear( 'APP_NAMESPACE' );
$this->app->set_app_path( $this->app->get_base_path( 'app' ) );
$this->app['config']->set( 'app.namespace', 'App' );

parent::tearDown();
}

public function test_events_can_be_discovered() {
Expand Down
5 changes: 3 additions & 2 deletions tests/http/routing/test-post-model-routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class Test_Post_Model_Routing extends Framework_Test_Case {
protected function setUp(): void {
parent::setUp();

update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
flush_rewrite_rules();
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );

add_filter( 'deprecated_file_trigger_error', '__return_false' );
}

public function test_post_type() {
Expand Down

0 comments on commit d3646bb

Please sign in to comment.