rapemer/sonata-admin-annotation-bundle
Composer 安装命令:
composer require rapemer/sonata-admin-annotation-bundle
包简介
Manage Sonata Form, Data, List and ShowMapper over annotations
关键字:
README 文档
README
Manage Sonata Form, Data, List and ShowMapper over annotations
Known issues
Version 1.1.*
- Using oneToMany/manyToOne relations produces an "entity not managed" doctrine error. Reason is that FormMapper-Annotation per default sets by_reference to false, using @FormMapper(options={"by_reference"=true}) will fix that.
New features
Version 1.2
- Allow reorder of FormMapper/ShowMapper and ListMapper with @Order/FormReorder, @Order/ShowReorder, @Order/ListReorder or @Order/ShowAndFormReorder annotations
Version 1.1
- New "with" and "withOptions" in FormMapper and ShowMapper Annotation for grouping -> @FormMapper(with="Main")
- Allow configuration of static callback methods in entity with @FormCallback on Method (see @FormCallback example)
How to install
Add Bundle to your composer.json
// composer.json { "require": { "ibrows/sonata-admin-annotation-bundle": "*" } }
Install the bundle from console with composer.phar
$ php composer.phar update ibrows/sonata-admin-annotation-bundle
Enable the bundle in AppKernel.php
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Ibrows\Bundle\SonataAdminAnnotationBundle\IbrowsSonataAdminAnnotationBundle(), ); }
The Annotations
- Ibrows\Bundle\SonataAdminAnnotationBundle\Annotation\Order on classes for global orders like "show me all properties"
- Ibrows\Bundle\SonataAdminAnnotationBundle\Annotation on properties for specific configurations and excludes if orders are used
If any FormMapperExclude Annotation is found on a property the reader assumes that there es an Order/FormMapperAll on the class (same goes for the other annotations - List/Form/Datagrid)
Have a look on the Annotations to see what options they accept
Example
<?php namespace YourApp\Entity; use Ibrows\Bundle\SonataAdminAnnotationBundle\Annotation as Sonata; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection; /** * @ORM\Entity * @Sonata\Order\ListMapperAll * @Sonata\Order\ShowMapperAll * @Sonata\Order\FormMapperAll * * @Sonata\Order\ShowAndFormreorder(with="General", keys={"name"}) * @Sonata\Order\ShowAndFormreorder(keys={"taxRate"}) */ class Country { /** * @var integer $id * @ORM\Column(type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") * @Sonata\ListMapper(identifier=true) * @Sonata\Order\FormMapperExclude * @Sonata\ShowMapper(with="General") */ protected $id; /** * @var string $name * @ORM\Column(type="string") * @Sonata\ShowMapper(with="General") */ protected $name; /** * @var float * @ORM\Column(type="float", name="shipping_free_limit") */ protected $shippingFreeLimit; /** * @var float * @ORM\Column(type="float", name="shipping_fixed_rate") */ protected $shippingFixedRate; /** * @var float * @ORM\Column(type="float", name="tax_rate") */ protected $taxRate; /** * @ORM\ManyToMany(targetEntity="Article", inversedBy="countries") * @ORM\JoinTable(name="article_country") * @Sonata\Order\ListMapperExclude * @Sonata\FormMapper(options={"required"=false}) **/ protected $articles; }
<?php namespace YourApp\Entity; use Ibrows\Bundle\SonataAdminAnnotationBundle\Annotation as Sonata; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Show\ShowMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; use Application\Sonata\MediaBundle\Entity\Gallery; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection; /** * @ORM\Entity * @Sonata\Order\ShowAndFormreorder(keys={"name"}) */ class Article { /** * @var string $number * @ORM\Column(name="number", type="string", unique=true) */ protected $number; /** * @var string $name * @ORM\Column(type="string") * @Sonata\DatagridMapper */ protected $name; /** * @var string $description * @ORM\Column(type="text") * @Sonata\Order\ListMapperExclude */ protected $description; /** * @var string $matchCode * @ORM\Column(name="match_code", type="string") * @Sonata\Order\ListMapperExclude */ protected $matchCode; /** * @var string $articleGroup * @ORM\Column(name="article_group", type="string") * @Sonata\Order\ListMapperExclude * @Sonata\Order\ShowMapperExclude */ protected $articleGroup; /** * @var ArrayCollection * @ORM\OneToMany(targetEntity="ArticlePrice", mappedBy="articleEntity") * @Sonata\Order\ListMapperExclude */ protected $prices; /** * @ORM\ManyToMany(targetEntity="Country", mappedBy="articles") **/ protected $countries; /** * @var Gallery $pictures * @ORM\ManyToOne( * targetEntity="Application\Sonata\MediaBundle\Entity\Gallery", * cascade={"persist"} * ) * @Sonata\FormMapper( * type="sonata_type_model_list", * options={"required"=false}, * fieldDescriptionOptions={ * "link_parameters"={ * "context":"article", * "provider":"sonata.media.provider.image" * } * } * ) */ protected $pictures; /** * @param \Sonata\AdminBundle\Form\FormMapper $formMapper * @Sonata\FormCallback */ public static function configureFormFields(FormMapper $formMapper) { $formMapper->add('countries'); } }
Using in the Admin (maybe in an AbstractAdmin.php)
With the AbstractSonataAdminAnnotationAdmin
<?php namespace YourApp\Admin; use Ibrows\Bundle\SonataAdminAnnotationBundle\Admin\AbstractSonataAdminAnnotationAdmin; abstract class AbstractAdmin extends AbstractSonataAdminAnnotationAdmin { }
With Traits (PHP >=5.4)
<?php namespace YourApp\Admin; use Ibrows\Bundle\SonataAdminAnnotationBundle\Admin\SonataAdminAnnotationAllTrait; use Sonata\AdminBundle\Admin\Admin; abstract class AbstractAdmin extends Admin { use SonataAdminAnnotationAllTrait; }
Own implementation
<?php namespace YourApp\Admin; use Ibrows\Bundle\SonataAdminAnnotationBundle\Reader\SonataAdminAnnotationReaderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Sonata\AdminBundle\Admin\Admin; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Show\ShowMapper; abstract class AbstractAdmin extends Admin { /** * @param ListMapper $listMapper */ protected function configureListFields(ListMapper $listMapper) { $this->getSonataAnnotationReader()->configureListFields($this->getClass(), $listMapper); } /** * @param FormMapper $formMapper */ protected function configureFormFields(FormMapper $formMapper) { $this->getSonataAnnotationReader()->configureFormFields($this->getClass(), $formMapper); } /** * @param ShowMapper $showMapper */ protected function configureShowFields(ShowMapper $showMapper) { $this->getSonataAnnotationReader()->configureShowFields($this->getClass(), $showMapper); } /** * @param DatagridMapper $datagridMapper */ protected function configureDatagridFilters(DatagridMapper $datagridMapper) { $this->getSonataAnnotationReader()->configureDatagridFilters($this->getClass(), $datagridMapper); } /** * @return ContainerInterface */ protected function getContainer() { return $this->getConfigurationPool()->getContainer(); } /** * @return SonataAdminAnnotationReaderInterface */ protected function getSonataAnnotationReader() { return $this->getContainer()->get('ibrows_sonataannotation.reader'); } }
rapemer/sonata-admin-annotation-bundle 适用场景与选型建议
rapemer/sonata-admin-annotation-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 12 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sonata」 「annotation」 「ibrows」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rapemer/sonata-admin-annotation-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rapemer/sonata-admin-annotation-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rapemer/sonata-admin-annotation-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Sonata Extra admin features
ACL list filtering for SonataAdmin
Manage Sonata Form, Data, List and ShowMapper over annotations
Symfony bundle to add arbitrary metadata to classes and their constants by annotation
This bundle track command execution in the database.
统计信息
- 总下载量: 33
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-20