Skip to content

Commit

Permalink
[7.x] Publish resources.stub in stub:publish command (#33862)
Browse files Browse the repository at this point in the history
* [7.x] Add a new helper to determine the true parent of a class.

Some examples of use are:

```php
class_parent_initial(HasMany::class); // Returns Relation::class
class_parent_initial(HasOne::class); // Returns Relation::class
class_parent_initial(HasOneOrMany::class); // Returns Relation::class
```

* [7.x] Publish resources.stub in stub:publish command

* Remove parent_class helper

* Update stub resources to match the format of the other publishable stubs.
  • Loading branch information
gregorip02 committed Aug 13, 2020
1 parent 7cd8ca8 commit 4d0d883
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
17 changes: 15 additions & 2 deletions src/Illuminate/Foundation/Console/ResourceMakeCommand.php
Expand Up @@ -51,8 +51,8 @@ public function handle()
protected function getStub()
{
return $this->collection()
? __DIR__.'/stubs/resource-collection.stub'
: __DIR__.'/stubs/resource.stub';
? $this->resolveStubPath('/stubs/resource-collection.stub')
: $this->resolveStubPath('/stubs/resource.stub');
}

/**
Expand All @@ -66,6 +66,19 @@ protected function collection()
Str::endsWith($this->argument('name'), 'Collection');
}

/**
* Resolve the fully-qualified path to the stub.
*
* @param string $stub
* @return string
*/
protected function resolveStubPath($stub)
{
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
? $customPath
: __DIR__.$stub;
}

/**
* Get the default namespace for the class.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Foundation/Console/StubPublishCommand.php
Expand Up @@ -38,6 +38,8 @@ public function handle()
__DIR__.'/stubs/model.pivot.stub' => $stubsPath.'/model.pivot.stub',
__DIR__.'/stubs/model.stub' => $stubsPath.'/model.stub',
__DIR__.'/stubs/request.stub' => $stubsPath.'/request.stub',
__DIR__.'/stubs/resource.stub' => $stubsPath.'/resource.stub',
__DIR__.'/stubs/resource-collection.stub' => $stubsPath.'/resource-collection.stub',
__DIR__.'/stubs/test.stub' => $stubsPath.'/test.stub',
__DIR__.'/stubs/test.unit.stub' => $stubsPath.'/test.unit.stub',
realpath(__DIR__.'/../../Database/Console/Factories/stubs/factory.stub') => $stubsPath.'/factory.stub',
Expand Down
@@ -1,10 +1,10 @@
<?php

namespace DummyNamespace;
namespace {{ namespace }};

use Illuminate\Http\Resources\Json\ResourceCollection;

class DummyClass extends ResourceCollection
class {{ class }} extends ResourceCollection
{
/**
* Transform the resource collection into an array.
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Console/stubs/resource.stub
@@ -1,10 +1,10 @@
<?php

namespace DummyNamespace;
namespace {{ namespace }};

use Illuminate\Http\Resources\Json\JsonResource;

class DummyClass extends JsonResource
class {{ class }} extends JsonResource
{
/**
* Transform the resource into an array.
Expand Down

0 comments on commit 4d0d883

Please sign in to comment.