Esempio n. 1
0
 /**
  * @test
  */
 public function singularizeTest()
 {
     $this->assertEquals('tree', Utility::singularize('trees'));
     $this->assertEquals('friend', Utility::singularize('friends'));
     $this->assertEquals('hobby', Utility::singularize('hobbies'));
     $this->assertEquals('news', Utility::singularize('news'));
     $this->assertEquals('equipment', Utility::singularize('equipment'));
     $this->assertEquals('species', Utility::singularize('species'));
     $this->assertEquals('series', Utility::singularize('series'));
     $this->assertEquals('Tree', Utility::singularize('Trees'));
     $this->assertEquals('Friend', Utility::singularize('Friends'));
     $this->assertEquals('Hobby', Utility::singularize('Hobbies'));
     $this->assertEquals('News', Utility::singularize('News'));
     $this->assertEquals('Equipment', Utility::singularize('Equipment'));
     $this->assertEquals('Species', Utility::singularize('Species'));
     $this->assertEquals('Series', Utility::singularize('Series'));
 }
Esempio n. 2
0
 /**
  * Returns the sent data
  *
  * @return mixed
  */
 public function getSentData()
 {
     $request = $this->getRequest();
     /** @var \Cundd\Rest\Request $request */
     $data = $request->post();
     /*
      * If no form url-encoded body is sent check if a JSON
      * payload is sent with the singularized root object key as
      * the payload's root object key
      */
     if (!$data) {
         $data = $request->get(Utility::singularize($this->getRootObjectKey()));
         if (!$data) {
             $data = json_decode($request->raw(), TRUE);
         }
     }
     return $data;
 }
Esempio n. 3
0
 /**
  * Returns the Document database name for the given path
  *
  * @param string $path
  * @return string
  */
 public function getDatabaseNameFromPath($path)
 {
     return Utility::singularize(strtolower(substr($path, 9)));
     // Strip 'Document-' and singularize
 }
Esempio n. 4
0
 /**
  * Creates a new Model with the data from the request
  *
  * @return array|integer Returns the Model's data on success, otherwise a descriptive error code
  */
 public function create()
 {
     /* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWM */
     /* CREATE																	 */
     /* MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWM */
     $dispatcher = Dispatcher::getSharedDispatcher();
     $dataProvider = $this->getDataProvider();
     /** @var \Cundd\Rest\Request $request */
     $data = $dispatcher->getSentData();
     $dispatcher->logRequest('create request', array('body' => $data));
     /**
      * @var \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $model
      */
     $model = $dataProvider->getModelWithDataForPath($data, $this->getPath());
     if (!$model) {
         return Dispatcher::getSharedDispatcher()->createSuccessResponse(NULL, 400);
     }
     $dataProvider->saveModelForPath($model, $this->getPath());
     $result = $dataProvider->getModelData($model);
     if ($this->objectManager->getConfigurationProvider()->getSetting('addRootObjectForCollection')) {
         return array(Utility::singularize($dispatcher->getRootObjectKey()) => $result);
     }
     return $result;
 }