Skip to content
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

Symfony Web Profiler error: property name on SourcePropertyMetadata #123

Closed
damienalexandre opened this issue May 10, 2024 · 1 comment · Fixed by #124
Closed

Symfony Web Profiler error: property name on SourcePropertyMetadata #123

damienalexandre opened this issue May 10, 2024 · 1 comment · Fixed by #124

Comments

@damienalexandre
Copy link
Member

When displaying the Web Profiler panel I get this exception:

Neither the property "name" nor one of the methods "name()", "getname()"/"isname()"/"hasname()" or "__call()" exist and have public access in class "AutoMapper\Metadata\SourcePropertyMetadata".

If coming from here:

{% if property.source.accessor %}
<span class="badge">{{ property.source.name }}</span> ->
<span class="badge">{{ property.target.name }}</span>
{% else %}
<span class="badge">{{ property.target.name }}</span>
{% endif %}

There is "name" on property.source and property.target. Replacing "name" by "property" works but I don't know if it's the right fix for this.

Target

class PostView {
    #[MapFrom(property: 'title')]
    public string $name;
    public string $slug;
    public string $lang;
    public string $content;
}

Source

#[ORM\Entity(repositoryClass: PostRepository::class)]
class Post
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 255, unique: true)]
    private ?string $slug = null;

    #[ORM\Column(length: 255)]
    private ?string $title = null;

    #[ORM\Column(type: Types::TEXT)]
    private ?string $content = null;

    #[ORM\Column(length: 6)]
    private ?string $lang = null;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function __construct()
    {
        $this->lang = 'fr';
    }

    public function getSlug(): ?string
    {
        return $this->slug;
    }

    public function setSlug(string $slug): self
    {
        $this->slug = $slug;

        return $this;
    }

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function setTitle(string $title): self
    {
        $this->title = $title;

        return $this;
    }

    public function getContent(): ?string
    {
        return $this->content;
    }

    public function setContent(string $content): self
    {
        $this->content = $content;

        return $this;
    }

    public function getLang(): ?string
    {
        return $this->lang;
    }

    public function setLang(?string $lang): self
    {
        $this->lang = $lang;

        return $this;
    }
}

Code

// Symfony Bundle service
// AutoMapperInterface $autoMapper

$autoMapper->map($post, PostView::class);
@damienalexandre
Copy link
Member Author

The mini-toolbar is also crashing with this error:

Key "mapperMetadata" for array with keys "registered, source, target, className, checkAttributes, useConstructor, provider, usedProperties, notUsedProperties, fileCode" does not exist.

From vendor/jolicode/automapper/src/Symfony/Bundle/Resources/views/DataCollector/metadata.html.twig (line 14).

Korbeil added a commit that referenced this issue May 10, 2024
Fixes #123 

We changed some stuff about Metadata which was not impacted within the
Symfony WebProfiler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant