1000 search results

For anyone getting Error in Evaluate() method of arraysubset inside src/ApiPlatform/Test/ Check your api version if it is greater than 2.4 using composer show api-platform/core instead of pasting ApiPlatform inside App just Use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase…
Sakshi G.
Sakshi G.
Read Full Comment
…like : * /transactions/{id}/comments provide data from Postgresql database where id is a column inside the database (but not the Primary Key). We tried with a @ApiSubresource for property Comments inside Entity but it doesn't work. How can we do that with API Platform
26 lines | src/ApiResource/DragonTreasureApi.php
// ... lines 1 - 2
namespace App\ApiResource;
use ApiPlatform\Doctrine\Orm\State\Options;
// ... line 6
use ApiPlatform\Metadata\ApiResource;
use App\Entity\DragonTreasure;
use App\State\EntityClassDtoStateProcessor;
use App\State\EntityToDtoStateProvider;
#[ApiResource(
shortName: 'Treasure',
paginationItemsPerPage: 10,
provider: EntityToDtoStateProvider::class,
processor: EntityClassDtoStateProcessor::class,
stateOptions: new Options(entityClass: DragonTreasure::class),
)]
class DragonTreasureApi
{
// ... lines 21 - 24
}
See Code Block in Script
26 lines | src/ApiResource/DragonTreasureApi.php
// ... lines 1 - 2
namespace App\ApiResource;
use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\DragonTreasure;
use App\State\EntityClassDtoStateProcessor;
use App\State\EntityToDtoStateProvider;
#[ApiResource(
shortName: 'Treasure',
paginationItemsPerPage: 10,
provider: EntityToDtoStateProvider::class,
processor: EntityClassDtoStateProcessor::class,
stateOptions: new Options(entityClass: DragonTreasure::class),
)]
class DragonTreasureApi
{
#[ApiProperty(readable: false, writable: false, identifier: true)]
public ?int $id = null;
public ?string $name = null;
}
See Code Block in Script
15 lines | src/State/EntityClassDtoStateProcessor.php
// ... lines 1 - 2
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
class EntityClassDtoStateProcessor implements ProcessorInterface
{
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void
{
// Handle the state
}
}
See Code Block in Script
12 lines | src/ApiResource/UserApi.php
// ... lines 1 - 2
namespace App\ApiResource;
use ApiPlatform\Metadata\ApiResource;
#[ApiResource]
class UserApi
{
}
See Code Block in Script
12 lines | src/ApiResource/UserApi.php
// ... lines 1 - 2
namespace App\ApiResource;
use ApiPlatform\Metadata\ApiResource;
#[ApiResource]
class UserApi
{
public ?int $id = null;
}
See Code Block in Script
15 lines | src/State/DailyQuestStateProvider.php
// ... lines 1 - 2
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
class DailyQuestStateProvider implements ProviderInterface
{
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
// Retrieve the state from somewhere
}
}
See Code Block in Script
12 lines | src/ApiResource/DailyQuest.php
// ... lines 1 - 2
namespace App\ApiResource;
use ApiPlatform\Metadata\ApiResource;
#[ApiResource]
class DailyQuest
{
}
See Code Block in Script
// ... lines 1 - 2
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
class DragonTreasureSetOwnerProcessor implements ProcessorInterface
{
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void
{
// Handle the state
}
}
See Code Block in Script
// ... lines 1 - 2
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
class UserHashPasswordStateProcessor implements ProcessorInterface
{
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void
{
// Handle the state
}
}
See Code Block in Script
…using PHP8 and SF 5.3.9 ApiPlatform 2.6 When I run the tests, I get an error message: ``` App\Tests\Functional\UserResourceTest::testUpdateUser Failed asserting that an array has the subset Array &0 ( 'username' => 'zanoni' ). --- Expected +++ Actual @@ @@ '@id' => '/api/users/149', …
namespace App\Entity; use ApiPlatform\Core\Annotation\ApiFilter; use ApiPlatform\Core\Annotation\ApiResource; use ApiPlatform\Core\Serializer\Filter\PropertyFilter; use App\Repository\UserRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints…
JavierMendezK
JavierMendezK
Read Full Comment
21 lines | src/DataPersister/DailyStatsPersister.php
// ... lines 1 - 2
namespace App\DataPersister;
use ApiPlatform\Core\DataPersister\DataPersisterInterface;
class DailyStatsPersister implements DataPersisterInterface
{
// ... lines 9 - 19
}
See Code Block in Script
// ... lines 1 - 2
namespace App\DataPersister;
use ApiPlatform\Core\DataPersister\DataPersisterInterface;
class CheeseListingDataPersister implements DataPersisterInterface
{
// ... lines 9 - 19
}
See Code Block in Script
// ... lines 1 - 2
namespace App\Serializer;
use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
final class AdminGroupsContextBuilder implements SerializerContextBuilderInterface
{
private $decorated;
private $authorizationChecker;
public function __construct(SerializerContextBuilderInterface $decorated, AuthorizationCheckerInterface $authorizationChecker)
{
$this->decorated = $decorated;
$this->authorizationChecker = $authorizationChecker;
}
public function createFromRequest(Request $request, bool $normalization, ?array $extractedAttributes = null): array
{
$context = $this->decorated->createFromRequest($request, $normalization, $extractedAttributes);
$resourceClass = $context['resource_class'] ?? null;
if ($resourceClass === Book::class && isset($context['groups']) && $this->authorizationChecker->isGranted('ROLE_ADMIN') && false === $normalization) {
$context['groups'][] = 'admin:input';
}
return $context;
}
}
See Code Block in Script
…I am on api platform 4.3 and currently it is possible to do the following using the `openapi` parameter and a `Parameter` definition for the input ``` #[ApiResource( uriTemplate: '/treasures/{treasure_id}/owner.{_format}', operations: [new Get()], uriVariables: [ 'treasure_id' => new Link( fromProperty: 'owner…
HiddeHiddema
HiddeHiddema
Read Full Comment
Hey |mention:78989| I think you can access that data through an ApiPlatform state provider. Here are the docs about them: https://api-platform.com/docs/core/state-providers/ Cheers!
MolloKhan
MolloKhan
Read Full Comment
I got it. Instead of `api_platform.open_api.factory` should be `api_platform.openapi.factory`. But I still don't realize where the `factory` option is coming from, it doesn't exists in the config.
Hi |mention:3768| , Thanks for the answer. Still not sure how to configure API Platform to avoid this duplication? Here is my ApiResource enabled Symfony Entity class: ```