示例#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'));
 }
示例#2
0
 /**
  * Returns the URI of a nested resource
  *
  * @param string $resourceKey
  * @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $model
  * @return string
  */
 public function getUriToNestedResource($resourceKey, $model)
 {
     $currentUri = '/rest/';
     $currentUri .= Utility::getPathForClassName(get_class($model)) . '/' . $model->getUid() . '/' . $resourceKey;
     $host = filter_var($_SERVER['HTTP_HOST'], FILTER_SANITIZE_URL);
     $protocol = !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ? 'http' : 'https';
     return $protocol . '://' . $host . $currentUri;
 }
示例#3
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;
 }
示例#4
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
 }
示例#5
0
文件: Cache.php 项目: tritumRz/rest
 /**
  * Returns the tags for the current request
  *
  * @return array[string]
  */
 protected function _getTags()
 {
     $currentPath = $this->currentRequest->path();
     list($vendor, $extension, $model) = Utility::getClassNamePartsForPath($currentPath);
     return array($vendor . '_' . $extension . '_' . $model, $extension . '_' . $model, $currentPath);
 }
示例#6
0
文件: Handler.php 项目: pkerling/rest
 /**
  * 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;
 }
示例#7
0
 /**
  * Returns the Handler which is responsible for handling the current request
  *
  * @return HandlerInterface
  */
 public function getHandler()
 {
     /** @var \Cundd\Rest\HandlerInterface $handler */
     list($vendor, $extension, ) = Utility::getClassNamePartsForPath($this->getRequest()->path());
     // Check if an extension provides a Handler
     $handlerClass = 'Tx_' . $extension . '_Rest_Handler';
     if (!class_exists($handlerClass)) {
         $handlerClass = ($vendor ? $vendor . '\\' : '') . $extension . '\\Rest\\Handler';
     }
     // Get the specific builtin handler
     if (!class_exists($handlerClass)) {
         $handlerClass = 'Cundd\\Rest\\Handler\\' . $extension . 'Handler';
         // Get the default handler
         if (!class_exists($handlerClass)) {
             $handlerClass = 'Cundd\\Rest\\HandlerInterface';
         }
     }
     return $this->get($handlerClass);
 }
示例#8
0
 /**
  * @test
  */
 public function getPathForClassNameTest()
 {
     $this->assertEquals('my_ext-my_model2', Utility::getPathForClassName('Tx_MyExt_Domain_Model_MyModel2'));
     $this->assertEquals('my_ext-my_model2', Utility::getPathForClassName('MyExt\\Domain\\Model\\MyModel2'));
     $this->assertEquals('my_ext-my_model2', Utility::getPathForClassName('Vendor\\MyExt\\Domain\\Model\\MyModel2'));
     $this->assertEquals('my_ext-my_second_model2', Utility::getPathForClassName('Tx_MyExt_Domain_Model_MySecondModel2'));
     $this->assertEquals('my_ext-my_second_model2', Utility::getPathForClassName('MyExt\\Domain\\Model\\MySecondModel2'));
     $this->assertEquals('my_ext-my_second_model2', Utility::getPathForClassName('Vendor\\MyExt\\Domain\\Model\\MySecondModel2'));
 }