/** * @test */ public function arrayUnderscoreKeyToCameCaseKey() { $underscoreKey = array('do_some_thing_else' => 'test', 'something_else' => 'test', 'camel_case' => 'test'); $excepted = array('doSomeThingElse' => 'test', 'somethingElse' => 'test', 'camelCase' => 'test'); $this->assertEquals($excepted, RegexHelper::arrayUnderscoreKeyToCameCaseKey($underscoreKey)); }
/** * Provide general create, update, and delete rest functionality for all controllers that set the rest full model name * * @param \Symfony\Component\HttpFoundation\Request $request * @param null|mixed $objectId * @param string $dataType * * @throws \Exception * * @return mixed */ public function restProcessDataAction(Request $request, $objectId = null, $dataType = 'json') { $objectName = $this->getRestFullModelName(); $httpMethod = $request->getMethod(); $user = new $objectName($objectId); $message = null; if ($httpMethod == 'DELETE') { if (!$user instanceof $objectName) { throw new \Exception('Unable to load record for deletion'); } $user->delete(); $status = 'success'; } else { $parsedData = $this->restProcessData($request); $data = RegexHelper::arrayUnderscoreKeyToCameCaseKey($parsedData['contentData']); $user->loadByArray($data, false); $user->save(); $status = 'success'; } $data = array($this->getRestObjectNameSingular() => $httpMethod !== 'DELETE' ? $user->toArray() : array()); $method = 'render' . ucfirst($dataType); return $this->{$method}(array('status' => $status, 'data' => $data, 'message' => $message)); }