kunicmarko20 / SonataAnnotationBundle

Annotations for Sonata Admin
MIT License
21 stars 7 forks source link

Skip matching namespace if not found #11

Closed kunicmarko20 closed 6 years ago

kunicmarko20 commented 6 years ago

I am targeting this branch because this is a BC fix.

Closes #10

Changelog

### Fixed
- Thorwing an error if namespace is not found in a file

Subject

There is no check if namespace line is not found and then if we try to use preg_match it throws an exception.

kunicmarko20 commented 6 years ago

@mohamedyasser can you check if this fixes your problem?

mohamedyasser commented 6 years ago

it's work but after enable bundle and use Annotation in entity and clear cache not generate a admin

kunicmarko20 commented 6 years ago

Hm, can you provide me the code of your enitity so I can reproduce it?

mohamedyasser commented 6 years ago
use Doctrine\ORM\Mapping as ORM;
use MediaBundle\Entity\Media;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * Service
 *
 * @Sonata\Admin("Service")
 *
 * @ORM\Table(name="services")
 * @ORM\HasLifecycleCallbacks
 * @ORM\Entity()
 */
class Service
{
    /**
     * @var int
     *
     * @Sonata\ListField()
     *
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @Sonata\FormField()
     * @Sonata\ListField()
     *
     * @ORM\Column(name="name", type="string", length=100)
     */
    private $name;

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

    /**
     * @return string
     */
    public function getName(): ?string
    {
        return $this->name;
    }

    /**
     * @param string $name
     */
    public function setName(string $name): void
    {
        $this->name = $name;
    }
}
kunicmarko20 commented 6 years ago

I tested and it works, not sure what problems you have, any kind of error?

repo: https://github.com/kunicmarko20/annotation-test-issue-10 entity: https://github.com/kunicmarko20/annotation-test-issue-10/blob/master/src/Entity/Service.php tests: https://github.com/kunicmarko20/annotation-test-issue-10/blob/master/tests/AdminExistTest.php travis build: https://travis-ci.org/kunicmarko20/annotation-test-issue-10/builds/363725432

mohamedyasser commented 6 years ago

are you tested in SY3 this issue on SY3 i'm tested in SY4 and work fine? there is no error in log

kunicmarko20 commented 6 years ago

Check repo, I tested on sf3.4 + flex, did you try with or without flex?

kunicmarko20 commented 6 years ago

I think i found error, check this line:

https://github.com/kunicmarko20/SonataAnnotationBundle/blob/8e7b1573293c9657285b7e240dc72c57c0306884/src/DependencyInjection/SonataAnnotationExtension.php#L24

If you are on flex kernel is in src folder but if you are not using flex it is in app so that could be a problem.

mohamedyasser commented 6 years ago

without flex