Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ev Copy Bundle Laravel Package

ev/ev-copy-bundle

View on GitHub
Deep Wiki
Context7

EVCopyBundle

This is a Symfony Bundle helps you to copy an entity with its dependencies

Features

  • Easily configure the copying behavior of entities

Installation

In composer.json file, add :

{
    "require": {
        "ev/ev-copy-bundle": "^1.2"
    }
}

In app/AppKernel.php file, add :

public function registerBundles()
{
    return array(
        // ...
        new EV\CopyBundle\EVCopyBundle(),
        // ...
    );
}

Entity configuration

Annotations

  • @Copy\Simple : Takes the value and adding to the copy

  • @Copy\Variable : Set the value based on parameters given to Cloner

    Required attributes:

    • name
  • @Copy\Collection : Copy each entity of collection

    Optional attributes:

    • memorizeMatching : Enable the matching memory and define a name of the memory bag
  • @Copy\Entity : Copy the entity

  • @Copy\UseMatching : Takes an entity copied previously. It uses the matching memory system

    Required attributes:

    • name : Name of the memory bag
  • @Copy\Construct : Gives parameters to the constructor based on parameters given to Cloner

    Required attributes:

    • variables : Array of parameters

Example

namespace EV\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use EV\CopyBundle\Annotation as Copy;

class Article
{

    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(name="title", type="string", length=255)
     * @Copy\Variable(name="articleTitle")
     */
    private $title;

    /**
     * @ORM\Column(name="content", type="text")
     * @Copy\Simple
     */
    private $content;

    /**
     * @ORM\Column(name="date", type="datetime")
     */
    private $date;

    /**
     * @ORM\OneToOne(targetEntity="EV\BlogBundle\Entity\Options", cascade={"persist","remove"})
     * @ORM\JoinColumn(name="optionsId", referencedColumnName="id")
     * @Copy\Entity
     */
    private $options;

    /**
     * @ORM\ManyToOne(targetEntity="EV\BlogBundle\Entity\Author", inversedBy="articles")
     * @ORM\JoinColumn(name="authorId", referencedColumnName="id", nullable=false)
     * @Copy\Simple
     */
    private $author;

    /**
     * @ORM\OneToMany(targetEntity="EV\BlogBundle\Entity\Comment", mappedBy="article", cascade={"persist"})
     * @Copy\Collection
     */
    private $comments

    /**
     * @ORM\ManyToOne(targetEntity="EV\BlogBundle\Entity\Blog", inversedBy="articles")
     * @ORM\JoinColumn(name="blogId", referencedColumnName="id", onDelete="cascade")
     */
    protected $blog;

    /**
     * @Copy\Construct(variables={"blog"})
     */
    public function __construct(Blog $blog)
    {
        $this->blog = $blog;
        $this->date = new \DateTime('now');
    }

    // Getters, Setters and Adders methods...

    public function addComment(\EV\BlogBundle\Entity\Comment $comment)
    {
        $this->comments[] = $comment;

        // IMPORTANT : without this line, the copy won't work
        $comment->setArticle($this);

        return $this;
    }

}
namespace EV\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use EV\CopyBundle\Annotation as Copy;

class Comment
{

    /**
     * @ORM\Column(name="pseudo", type="string", length=255)
     * @Copy\Simple
     */
    $pseudo;

    /**
     * @ORM\Column(name="content", type="text")
     * @Copy\Simple
     */
    $content;

    /**
     * @ORM\ManyToOne(targetEntity="EV\BlogBundle\Entity\Article", inversedBy="comments")
     * @ORM\JoinColumn(name="articleId", referencedColumnName="id", nullable=false)
     */
    protected $article;

    // Getters, Setters and Adders methods...

}

Usage example


public function articleCopyAction() {

    //...

    $params = array(
        'blog' => $blog,
        'articleTitle' => $article->getTitle().' - Copy'
    );

    $articleCopy = $this->get('ev_copy.factory.cloner')->copy($article, $params);

    //...

}

Future features

  • Add an annotation in order to condition the copy of a parameter
  • Define an order to copy parameters

How to contribute

To contribute just open a Pull Request with your new code taking into account that if you add new features or modify existing ones you have to document in this README what they do.

License

EVCopyBundle is licensed under MIT

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel