commit ba0e5fd7da6a9a2c355a354fc308735024afb3ac
parent 308ebad5d62e3c0bb010c0c579fcaec1ec79aef6
Author: Felicitus <felicitus@felicitus.org>
Date: Mon, 20 Jul 2015 01:42:43 +0200
Removed obsolete code
Diffstat:
6 files changed, 0 insertions(+), 740 deletions(-)
diff --git a/src/PartKeepr/DoctrineReflectionBundle/Controller/DoctrineRESTQueryController.php b/src/PartKeepr/DoctrineReflectionBundle/Controller/DoctrineRESTQueryController.php
@@ -1,343 +0,0 @@
-<?php
-
-
-namespace PartKeepr\DoctrineReflectionBundle\Controller;
-
-
-use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
-use Doctrine\ORM\EntityManager;
-use Doctrine\ORM\QueryBuilder;
-use Doctrine\ORM\Tools\Pagination\Paginator;
-use FOS\RestBundle\Controller\Annotations\QueryParam;
-use FOS\RestBundle\Controller\FOSRestController;
-use FOS\RestBundle\Request\ParamFetcher;
-use FOS\RestBundle\View\View;
-use JMS\Serializer\Serializer;
-use PartKeepr\DoctrineReflectionBundle\Filter\Filter;
-use PartKeepr\DoctrineReflectionBundle\Sorter\Sorter;
-use PartKeepr\Manager\Exceptions\EntityInUseException;
-use PartKeepr\Util\BaseEntity;
-use Symfony\Component\HttpFoundation\Request;
-
-class DoctrineRESTQueryController extends FOSRestController
-{
- /**
- * The target entity to operate on
- * @var string
- */
- protected $targetEntity;
-
- /**
- * An array which contains all entity aliases used for queries
- * @var array
- */
- protected $queryAliases = array();
-
- /**
- * Returns the target entity to operate on
- *
- * @return string The target entity
- */
- public function getTargetEntity()
- {
- return $this->targetEntity;
- }
-
- /**
- * Sets the target entity. Use a FQDN entity class
- *
- * @param string $targetEntity
- */
- public function setTargetEntity($targetEntity)
- {
- $this->targetEntity = $targetEntity;
- }
-
- /**
- * @QueryParam(name="start",default=0,requirements="\d+",description="Sets the start record")
- * @QueryParam(name="limit",default=-1,requirements="\d+",description="Sets the number of records to fetch. -1 means unlimited")
- * @QueryParam(name="sort", default=null)
- * @QueryParam(name="filter", default=null)
- */
- public function listAction (ParamFetcher $paramFetcher) {
- $qb = $this->getQueryBuilder();
-
- $qb->select($this->getQueryAlias())->from($this->getTargetEntity(), $this->getQueryAlias());
-
- $this->applyPagination($qb, $paramFetcher);
- $this->applySorting($qb, $paramFetcher);
- $this->applyFilters($qb, $paramFetcher);
-
- $query = $qb->getQuery();
-
- $paginator = new Paginator($query);
-
- $data = array();
- $data["data"] = $paginator->getIterator()->getArrayCopy();
- $data["_totalCount"] = count($paginator);
-
- $view = View::create()
- ->setStatusCode(200)
- ->setData($data);
- return $view;
- }
-
- /**
- * Applies filters to the specified query builder. Reads the "filter" parameter.
- *
- * @param QueryBuilder $qb
- * @param ParamFetcher $paramFetcher
- *
- * @throws \Exception
- */
- protected function applyFilters(QueryBuilder $qb, ParamFetcher $paramFetcher)
- {
- $filter = $paramFetcher->get("filter");
-
- if ($filter === null) {
- return;
- }
-
- $filters = $this->parseFilters($filter);
-
- $expr = array();
-
- foreach ($filters as $key => $filter) {
- $filterField = $this->getQueryAlias($filter->getTargetEntity()).".".$filter->getFilterField();
- $parameterName = ":parameter" . $key;
-
- $qb->setParameter($parameterName, $filter->getFilterValue());
- switch ($filter->getFilterOperator()) {
- case "<":
- $expr[] = $qb->expr()->lt($filterField, $parameterName);
- break;
- case "<=":
- $expr[] = $qb->expr()->lte($filterField, $parameterName);
- break;
- case "=":
- $expr[] = $qb->expr()->eq($filterField, $parameterName);
- break;
- case ">":
- $expr[] = $qb->expr()->gt($filterField, $parameterName);
- break;
- case ">=":
- $expr[] = $qb->expr()->gte($filterField, $parameterName);
- break;
- case "!=":
- $expr[] = $qb->expr()->neq($filterField, $parameterName);
- break;
- case "in":
- $expr[] = $qb->expr()->in($filterField, $parameterName);
- break;
- case "like":
- $expr[] = $qb->expr()->like($filterField, $parameterName);
- break;
- }
- }
-
- $qb->where(call_user_func_array(array($qb->expr(), "andX"), $expr));
- }
-
- /**
- * Applies sorting to the specified query builder. Reads the "sort" parameter.
- *
- * @param QueryBuilder $qb
- * @param ParamFetcher $paramFetcher
- *
- */
- protected function applySorting (QueryBuilder $qb, ParamFetcher $paramFetcher) {
- $sort = $paramFetcher->get("sort");
-
- if ($sort === NULL) {
- return;
- }
-
- $sorters = $this->parseSorters($sort);
-
- foreach ($sorters as $sorter) {
- $sort = $this->getQueryAlias($sorter->getTargetEntity()) .".".$sorter->getSortField();
- $qb->addOrderBy($sort, $sorter->getSortDirection());
- }
- }
-
- /**
- * Parses the sorters and returns an array of sorters.
- *
- * @param $sort string A json string which includes the sorters
- * @return Sorter[]
- * @throws \Exception
- */
- protected function parseSorters ($sort) {
- $decodedJson = json_decode($sort, true);
-
- if ($decodedJson === null) {
- throw new \Exception("sort parameter has an invalid format");
- }
-
- $sorters = array();
-
- foreach ($decodedJson as $sorter) {
- if (!array_key_exists("property", $sorter)) {
- throw new \Exception("property parameter has an invalid format");
- }
-
- if (!array_key_exists("direction", $sorter)) {
- throw new \Exception("direction parameter has an invalid format");
- }
-
- $sorters[] = new Sorter($this->getTargetEntity(), $sorter["property"], $sorter["direction"]);
- }
-
- return $sorters;
- }
-
- /**
- * Parses the sorters and returns an array of sorters.
- *
- * @param $sort string A json string which includes the sorters
- *
- * @return Filter[]
- * @throws \Exception
- */
- protected function parseFilters($filter)
- {
- $decodedJson = json_decode($filter, true);
-
- if ($decodedJson === null) {
- throw new \Exception("filter parameter has an invalid format");
- }
-
- $filters = array();
-
- foreach ($decodedJson as $filter) {
- if (!array_key_exists("property", $filter)) {
- throw new \Exception("property parameter has an invalid format");
- }
-
- if (!array_key_exists("value", $filter)) {
- throw new \Exception("value parameter has an invalid format");
- }
-
- if (!array_key_exists("operator", $filter)) {
- $filter["operator"] = "like";
- }
-
- $filters[] = new Filter($this->getTargetEntity(), $filter["property"], $filter["value"], $filter["operator"]);
- }
-
- return $filters;
- }
- /**
- * Applies pagination to the query builder
- *
- * @param QueryBuilder $qb
- * @param ParamFetcher $paramFetcher
- */
- protected function applyPagination(QueryBuilder $qb, ParamFetcher $paramFetcher)
- {
- $start = intval($paramFetcher->get("start"));
- $limit = intval($paramFetcher->get("limit"));
-
-
- $qb->setFirstResult($start);
-
- if ($limit > 0) {
- $qb->setMaxResults($limit);
- }
- }
-
- /**
- * Returns the query builder
- *
- * @return QueryBuilder The query builder
- */
- protected function getQueryBuilder()
- {
- return $this->getEM()->createQueryBuilder();
- }
-
- /**
- * Returns a query alias for the query builder.
- *
- * @param $entity string The FQDN for the entity
- *
- * @return string A short alias for use in queries
- */
- protected function getQueryAlias ($entity = NULL) {
- if ($entity === NULL) {
- $entity = $this->getTargetEntity();
- }
-
- if (!array_key_exists($entity, $this->queryAliases)) {
- $reflectionClass = new \ReflectionClass($entity);
- $this->queryAliases[$entity] = $reflectionClass->getShortName().count($this->queryAliases);
- }
-
- return $this->queryAliases[$entity];
- }
-
- public function getAction ($id) {
- return array("data" => $this->getEM()->find($this->getTargetEntity(), $id));
- }
-
- /**
- * Returns the entity manager
- * @return EntityManager
- */
- public function getEM () {
- return $this->get("doctrine")->getEntityManager();
- }
-
- public function putAction (Request $request, $id) {
- $serializer = $this->get("jms_serializer");
-
- /**
- * @var $serializer Serializer
- */
- $entity = $this->getEM()->find($this->getTargetEntity(), $id);
-
- $context = new \JMS\Serializer\DeserializationContext();
- $context->attributes->set('target', $entity);
-
- $updated = $serializer->deserialize($request->getContent(), $this->getTargetEntity(), 'json', $context);
-
- $this->getEM()->persist($updated);
- $this->getEM()->flush();
-
- return $entity;
- }
-
- public function postAction (Request $request) {
- $serializer = $this->get("jms_serializer");
-
- /**
- * @var $serializer Serializer
- */
-
- $newEntity = $serializer->deserialize($request->getContent(), $this->getTargetEntity(), 'json');
-
- $this->getEM()->persist($newEntity);
- $this->getEM()->flush();
-
- return $newEntity;
- }
-
- public function deleteAction ($id) {
- /** @var $entity BaseEntity */
- $entity = $this->getEM()->find($this->getTargetEntity(), $id);
-
- try {
- $this->getEM()->remove($entity);
- $this->getEM()->flush();
- } catch (ForeignKeyConstraintViolationException $e) {
- throw new EntityInUseException($entity);
- }
-
- $view = View::create()
- ->setStatusCode(200)
- ->setData(array("success" => true));
-
- return $view;
- }
-
-}-
\ No newline at end of file
diff --git a/src/PartKeepr/DoctrineReflectionBundle/Controller/DoctrineRESTTreeController.php b/src/PartKeepr/DoctrineReflectionBundle/Controller/DoctrineRESTTreeController.php
@@ -1,8 +0,0 @@
-<?php
-namespace PartKeepr\DoctrineReflectionBundle\Controller;
-
-
-class DoctrineRESTTreeController
-{
-
-}-
\ No newline at end of file
diff --git a/src/PartKeepr/DoctrineReflectionBundle/Filter/Filter.php b/src/PartKeepr/DoctrineReflectionBundle/Filter/Filter.php
@@ -1,141 +0,0 @@
-<?php
-namespace PartKeepr\DoctrineReflectionBundle\Filter;
-
-/**
- * Represents a filter
- *
- * This allows the developer to specify multiple filters.
- */
-class Filter
-{
- /**
- * The FQDN target entity to filter
- *
- * @var string
- */
-
- private $targetEntity;
-
- /**
- * The field to filter by
- *
- * @var string
- */
- private $filterField = null;
-
- /**
- * The value to filter for
- *
- * @var string
- */
- private $filterValue = null;
-
- /**
- * The operator to use
- * @var string
- */
- private $operator;
-
- /**
- * Constructs a new filter.
- *
- * @param string $field The field to filter for
- * @param string $value The value to filter for. Must be a scalar value, except if the operator is IN, where it may be an array
- * @param string $operator The operator to use. Supported operators are <, <=, =, >=, >, !=, in, like
- */
- public function __construct($targetEntity, $field, $value, $operator = "=")
- {
- $this->targetEntity = $targetEntity;
-
- $this->setFilterField($field);
- $this->setFilterOperator($operator);
- $this->setFilterValue($value);
- }
-
- /**
- * Sets the filter field for this filter
- *
- * @param string $field The field to filter by
- */
- public function setFilterField($field)
- {
- $this->filterField = $field;
- }
-
- /**
- * Sets the filter operator
- *
- * @param string $operator The operator to use. Supported operators are <, <=, =, >=, >, !=, in, like
- */
- public function setFilterOperator ($operator)
- {
- switch (strtolower($operator)) {
- case "<":
- $this->operator = "<";
- break;
- case ">":
- $this->operator = ">";
- break;
- case "=":
- $this->operator = "=";
- break;
- case "<=":
- $this->operator = "<=";
- break;
- case ">=":
- $this->operator = ">=";
- break;
- case "!=":
- $this->operator = "!=";
- break;
- case "in":
- $this->operator = "in";
- break;
- case "like":
- $this->operator = "like";
- break;
- }
- }
-
- /**
- * Sets the filter value
- * @param $value
- */
- public function setFilterValue ($value) {
- $this->filterValue = $value;
- }
-
- public function getFilterValue () {
- return $this->filterValue;
- }
-
- /**
- * Returns the target entity to sort
- *
- * @return string
- */
- public function getTargetEntity()
- {
- return $this->targetEntity;
- }
-
- /**
- * Returns the filter field
- *
- * @return string The field name
- */
- public function getFilterField()
- {
- return $this->filterField;
- }
-
- /**
- * Returns the operator for this filter
- *
- * @return string
- */
- public function getFilterOperator()
- {
- return $this->operator;
- }
-}-
\ No newline at end of file
diff --git a/src/PartKeepr/DoctrineReflectionBundle/Services/InitializedObjectConstructor.php b/src/PartKeepr/DoctrineReflectionBundle/Services/InitializedObjectConstructor.php
@@ -1,61 +0,0 @@
-<?php
-
-/*
- * Copyright 2013 Johannes M. Schmitt <schmittjoh@gmail.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-namespace PartKeepr\DoctrineReflectionBundle\Services;
-
-use JMS\Serializer\VisitorInterface;
-use JMS\Serializer\Metadata\ClassMetadata;
-use JMS\Serializer\DeserializationContext;
-use JMS\Serializer\Construction\ObjectConstructorInterface;
-
-/**
- * Object constructor that allows deserialization into already constructed
- * objects passed through the deserialization context
- */
-class InitializedObjectConstructor implements ObjectConstructorInterface
-{
- private $fallbackConstructor;
-
- /**
- * Constructor.
- *
- * @param ObjectConstructorInterface $fallbackConstructor Fallback object constructor
- */
- public function __construct(ObjectConstructorInterface $fallbackConstructor)
- {
- $this->fallbackConstructor = $fallbackConstructor;
- }
-
- /**
- * {@inheritdoc}
- */
- public function construct(
- VisitorInterface $visitor,
- ClassMetadata $metadata,
- $data,
- array $type,
- DeserializationContext $context
- ) {
- if ($context->attributes->containsKey('target') && $context->getDepth() === 1) {
- return $context->attributes->get('target')->get();
- }
-
- return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
- }
-
-}
diff --git a/src/PartKeepr/DoctrineReflectionBundle/Sorter/Sorter.php b/src/PartKeepr/DoctrineReflectionBundle/Sorter/Sorter.php
@@ -1,95 +0,0 @@
-<?php
-namespace PartKeepr\DoctrineReflectionBundle\Sorter;
-
-/**
- * Represents a sorter
- *
- * This allows the developer to specify multiple sorters. One sorter contains a sort field and a sort direction.
- */
-class Sorter {
- /**
- * The FQDN target entity to sort
- * @var string
- */
-
- private $targetEntity;
- /**
- * The field to sort by
- * @var string
- */
- private $sortField = null;
-
- /**
- * The direction to sort by
- * @var string
- */
- private $sortDirection = null;
-
- /**
- * Constructs a new sorter.
- *
- * @param string $field The field to sort by
- * @param string $direction The direction, either "asc" or "desc"
- */
- public function __construct ($targetEntity, $field = null, $direction = null) {
- $this->targetEntity = $targetEntity;
-
- if ($field !== null) {
- $this->setSortField($field);
- }
-
- if ($direction !== null) {
- $this->setSortDirection($direction);
- }
- }
-
- /**
- * Sets the sort field for this sorter
- * @param string $field The field to sort by
- */
- public function setSortField ($field) {
- $this->sortField = $field;
- }
-
- /**
- * Sets the sort direction for this sorter
- * @param string $direction Either "asc" or "desc"
- */
- public function setSortDirection ($direction) {
- switch (strtolower($direction)) {
- case "desc":
- case "d":
- $this->sortDirection = "desc";
- break;
- case "asc":
- case "a":
- default:
- $this->sortDirection = "asc";
- break;
- }
- }
-
- /**
- * Returns the target entity to sort
- * @return string
- */
- public function getTargetEntity () {
- return $this->targetEntity;
- }
-
- /**
- * Returns the sort field for this sorter
- * @return string The field name
- */
- public function getSortField () {
- return $this->sortField;
- }
-
- /**
- * Returns the sort order for this sorter
- * @return string Either "asc" or "desc"
- */
- public function getSortDirection () {
- return $this->sortDirection;
- }
-}-
\ No newline at end of file
diff --git a/src/PartKeepr/FootprintBundle/Controller/FootprintController.php b/src/PartKeepr/FootprintBundle/Controller/FootprintController.php
@@ -1,87 +0,0 @@
-<?php
-
-namespace PartKeepr\FootprintBundle\Controller;
-
-use FOS\RestBundle\Request\ParamFetcher;
-use PartKeepr\DoctrineReflectionBundle\Controller\DoctrineRESTQueryController;
-use Sensio\Bundle\FrameworkExtraBundle\Configuration as Routing;
-use JMS\Serializer\Annotation as JMS;
-use Nelmio\ApiDocBundle\Annotation\ApiDoc;
-use FOS\RestBundle\Controller\Annotations\View;
-use Symfony\Component\HttpFoundation\Request;
-
-class FootprintController extends DoctrineRESTQueryController
-{
- protected $targetEntity = "PartKeepr\\FootprintBundle\\Entity\\Footprint";
-
- /**
- * Retrieves footprint
- *
- * @Routing\Route("/footprint", defaults={"method" = "get","_format" = "json"})
- * @Routing\Method({"GET"})
- * @ApiDoc(section="footprint",output="array<PartKeepr\FootprintBundle\Entity\Footprint>")
- *
- * @View()
- *
- * {@inheritdoc}
- */
- public function listAction(ParamFetcher $paramFetcher)
- {
- return parent::listAction($paramFetcher);
- }
-
- /**
- * Retrieves a single footprint
- *
- * @Routing\Route("/footprint/{id}", defaults={"method" = "get","_format" = "json"})
- * @Routing\Method({"GET"})
- * @ApiDoc(section="footprint",output="PartKeepr\FootprintBundle\Entity\Footprint")
- * @View()
- */
- public function getAction($id)
- {
- return parent::getAction($id);
- }
-
- /**
- * Saves a single footprint
- *
- * @Routing\Route("/footprint/{id}", defaults={"_format" = "json"})
- * @Routing\Method({"PUT"})
- * @ApiDoc(section="footprint",input="PartKeepr\FootprintBundle\Entity\Footprint",output="PartKeepr\FootprintBundle\Entity\Footprint")
- *
- * @View()
- */
- public function putAction(Request $request, $id)
- {
- return parent::putAction($request, $id);
- }
-
- /**
- * Creates a single footprint
- *
- * @Routing\Route("/footprint", defaults={"_format" = "json"})
- * @Routing\Method({"POST"})
- * @ApiDoc(section="footprint",input="PartKeepr\FootprintBundle\Entity\Footprint",output="PartKeepr\FootprintBundle\Entity\Footprint")
- *
- * @View()
- */
- public function postAction(Request $request)
- {
- return parent::postAction($request);
- }
-
- /**
- * Deletes a single footprint
- *
- * @Routing\Route("/footprint/{id}", defaults={"_format" = "json"})
- * @Routing\Method({"DELETE"})
- * @ApiDoc(section="footprint")
- *
- * @View()
- */
- public function deleteAction($id)
- {
- return parent::deleteAction($id);
- }
-}-
\ No newline at end of file