Skip to content

added a new feature to scan folders where entities are located #3283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

flug
Copy link
Contributor

@flug flug commented Nov 21, 2019

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tickets fixes #...
License MIT
Doc PR api-platform/docs#...

@flug flug changed the title added a new feature to scan folders where entities are located [WIP] added a new feature to scan folders where entities are located Nov 21, 2019
@flug flug force-pushed the feature/add/scan-entities/directory branch 19 times, most recently from 9c897ae to 2c04a58 Compare November 22, 2019 13:00
@flug flug changed the title [WIP] added a new feature to scan folders where entities are located added a new feature to scan folders where entities are located Nov 22, 2019
@teohhanhui
Copy link
Contributor

What is this for? We already support loading from directories, be it XML, YAML or annotations.

@flug
Copy link
Contributor Author

flug commented Nov 23, 2019

@soyuka wanted me to bring this feature to see with him and @dunglas

@dunglas
Copy link
Member

dunglas commented Nov 23, 2019

@teohhanhui Basically with this and defaults, you don't need the any annotations to expose a simple API, just pure PHP classes.

->prototype('scalar')->end()
->end()
->prototype('scalar')->end()
->end()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad indentation.

<services>
<service id="api_platform.metadata.resource.name_collection_factory.directory" decorates="api_platform.metadata.resource.name_collection_factory"
class="ApiPlatform\Core\Metadata\Resource\Factory\DirectoryResourceNameCollectionFactory" public="false">
<argument>%api_platform.resource_class_directories%</argument>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<argument>%api_platform.resource_class_directories%</argument>
<argument>%api_platform.resource_class_directories%</argument>

use Doctrine\ORM\Mapping as ORM;
use Psr\Container\ContainerInterface;

class ClassExtractor extends AbstractExtractor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final?


protected function extractPath(string $path)
{
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

parent::__construct($paths, $container);
}

protected function extractPath(string $path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected function extractPath(string $path)
protected function extractPath(string $path): void

return;
}
/**
* @var string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove.

@flug flug force-pushed the feature/add/scan-entities/directory branch 10 times, most recently from 955badc to 457ca33 Compare December 2, 2019 09:08
*/
private function update(ResourceMetadata $resourceMetadata, array $metadata): ResourceMetadata
{
foreach (['shortName'] as $property) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this if there's one property? Let's simplify the code.

@flug flug force-pushed the feature/add/scan-entities/directory branch 2 times, most recently from c82f0ff to 932e93b Compare December 2, 2019 15:41
}
$resource['shortName'] = (new \ReflectionClass($resourceClass))->getShortName();

return $this->update($parentResourceMetadata ?: new ResourceMetadata(), $resource);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$resourceMetadata = $parentResourceMetadata ?: new ResourceMetadata();

if (null !== $resourceMetadata->getShortname()) {
    return $resourceMetadata;
}

return $resourceMetadata->withShortname((new \ReflectionClass($resourceClass))->getShortName());

update method isn't required, as isn't the array

@flug flug force-pushed the feature/add/scan-entities/directory branch from 932e93b to 71366ef Compare December 2, 2019 15:43
@flug flug force-pushed the feature/add/scan-entities/directory branch from 71366ef to 00bcfed Compare December 2, 2019 16:16
@@ -14,6 +14,7 @@
<service id="ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface" alias="api_platform.metadata.resource.name_collection_factory" />

<!-- Resource metadata -->

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line can be removed

Copy link
Member

@soyuka soyuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me, we just need to validate the new configuration name (auto_mapping), ping @dunglas

@flug flug force-pushed the feature/add/scan-entities/directory branch from 00bcfed to 8ad7f4b Compare December 5, 2019 12:10
Base automatically changed from master to main January 23, 2021 21:59
@stale
Copy link

stale bot commented Nov 4, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 4, 2022
@stale
Copy link

stale bot commented Jan 3, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 3, 2023
@stale stale bot closed this Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants