1. Go to this page and download the library: Download ops-talent/apibundle 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/ */
ops-talent / apibundle example snippets
namespace AppBundle\Entity;
use AppBundle\Serializer\Annotation as AppSerializer;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class Page
* @package AppBundle\Entity
*
* @ORM\Entity(repositoryClass="AppBundle\Repository\PageRepository")
* @ORM\Table(name="pages")
* @ORM\Table(indexes={@ORM\Index(name="slug_idx", columns={"slug"})})
*/
class Page
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"show", "update", "list"})
*/
protected $id;
/**
* @var string
* @ORM\Column(type="string")
* @Assert\NotBlank()
* @Assert\Length(
* min = 1,
* max = 128,
* minMessage = "Your Title must be at least {{ limit }} digits long",
* maxMessage = "Your Title cannot be longer than {{ limit }} digits"
* )
* @Serializer\Groups({"show", "update", "list"})
*/
protected $title;
/**
* @var string
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(length=128, unique=true)
* @Serializer\Groups({"show", "update", "list"})
*/
protected $slug;
/**
* @var string
* @ORM\Column(type="text", nullable=true)
* @Serializer\Groups({"show", "update", "list"})
*/
protected $body;
/**
* @var array
* @ORM\Column(type="array", nullable=true)
* @Serializer\Groups({"show", "update", "list"})
*/
protected $data;
/**
* @var \DateTime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
* @Serializer\Groups({"show", "update", "list"})
*/
protected $created;
/**
* @var \DateTime $updated
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
* @Serializer\Groups({"show", "update", "list"})
*/
protected $updated;
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
* @return Page
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return \DateTime
*/
public function getCreated(): \DateTime
{
return $this->created;
}
/**
* @param \DateTime $created
* @return Page
*/
public function setCreated(\DateTime $created): Page
{
$this->created = $created;
return $this;
}
/**
* @return \DateTime
*/
public function getUpdated(): \DateTime
{
return $this->updated;
}
/**
* @param \DateTime $updated
* @return Page
*/
public function setUpdated(\DateTime $updated): Page
{
$this->updated = $updated;
return $this;
}
public function getSlug()
{
return $this->slug;
}
/**
* @param string $slug
*/
public function setSlug(string $slug)
{
$this->slug = $slug;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
* @return Page
*/
public function setTitle(string $title): Page
{
$this->title = $title;
return $this;
}
/**
* @return string
*/
public function getBody()
{
return $this->body;
}
/**
* @param string $body
* @return Page
*/
public function setBody($body): Page
{
$this->body = $body;
return $this;
}
/**
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* @param array $data
*/
public function setData($data)
{
$this->data = $data;
return $this;
}
}
namespace AppBundle\Repository;
use Doctrine\ORM\QueryBuilder;
use Opstalent\ApiBundle\Repository\BaseRepository;
class PageRepository extends BaseRepository
{
protected $filters = [];
protected $repositoryName='AppBundle:Page';
protected $repositoryAlias='page';
protected $entityName='\AppBundle\Entity\Page';
}
namespace AppBundle\Form\Page;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use AppBundle\Entity\Page;
class AddType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('title', TextType::class, [';
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Page::class,
]);
}
}
namespace AppBundle\Form\Page;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class EditType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->setMethod("PUT");
/** @var FormBuilderInterface $field */
foreach ($builder->all() as $field) {
$field->setRequired(false);
}
}
}
namespace AppBundle\Form\Page;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
class FilterType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('title', TextType::class, ['