PHP code example of mero / base-bundle

1. Go to this page and download the library: Download mero/base-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mero / base-bundle example snippets




use Mero\Bundle\BaseBundle\Validator\Constraints as MeroAssert;

class Payment
{
    /**
     * @var \DateTime Payment date
     *
     * @MeroAssert\DateRange(min="2017-01-01", max="today")
     */
    private $date;
}

namespace Acme\Bundle\BlogBundle\Controller;

use Mero\Bundle\BaseBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class NewsController extends AbstractController
{

    /**
     * @Route("/", name="news")
     */
    public function indexAction(Request $request)
    {
        $routeName = $this->getRouteName($request); // Return "news"
        $actionName = $this->getActionName($request); // Return "indexAction"
        $bundleName = $this->getBundleName(); // Return "AcmeBlogBundle"
        $data = [
            'data' => [
                'news' => [
                    [
                        'title' => 'Lorem ipsum'
                    ]
                ]
            ]
        ];
        
        //to return JSON
        return $this->wsResponse($data, 200, [], AbstractController::WS_RESPONSE_JSON);
        
        //to return XML
        return $this->wsResponse($data, 200, [], AbstractController::WS_RESPONSE_XML);
    }

}

namespace Acme\Bundle\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Mero\Bundle\BaseBundle\Entity\AbstractEntity;

/**
 * @ORM\Entity()
 * @ORM\Table(name="post")
 */
class Post extends AbstractEntity
{
    // Entity class with IdTrait, CreatedTrait and ModifiedTrait implemented
}

namespace Acme\Bundle\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Mero\Bundle\BaseBundle\Entity\AbstractEntityWithUuid;

/**
 * @ORM\Entity()
 * @ORM\Table(name="post")
 */
class Post extends AbstractEntityWithUuid
{
    // Entity class with UuidTrait, CreatedTrait and ModifiedTrait implemented
}

namespace Acme\Bundle\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Mero\Bundle\BaseBundle\Entity\IdTrait;

/**
 * @ORM\Entity()
 * @ORM\Table(name="post")
 */
class Post
{
    use IdTrait;
}

namespace Acme\Bundle\BlogBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Mero\Bundle\BaseBundle\Helper\ClassNameTrait;

/**
 * @ORM\Entity()
 * @ORM\Table(name="post")
 */
class Post
{
    use ClassNameTrait;
}

Post::className(); // Return "Post" using ClassNameTrait for PHP 5.4
Post::class // Return "Post" if you are using PHP 5.5 or above