Skip to content

Commit

Permalink
syntax ammendments
Browse files Browse the repository at this point in the history
  • Loading branch information
leedavis81 committed Jun 13, 2014
1 parent 9994548 commit 2bb4ff9
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 69 deletions.
10 changes: 7 additions & 3 deletions src/Drest/ClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ protected function recurseParams(array $expose, $fullClassName)
$short = 'This class was generated by the drest-client tool, and should be treated as a plain data object';
$long = <<<EOT
ANY ALTERATIONS WILL BE OVERWRITTEN if the classes are regenerated
The variables declared are exposed by the rest endpoint provided when generating these classes. However depending on the operation (GET/POST/PUT etc) used some of these may not be populated / operational.
The variables declared are exposed by the rest endpoint provided when generating these classes.
However depending on the operation (GET/POST/PUT etc) used some of these may not be populated / operational.
EOT;
$docBlock = new Generator\DocBlockGenerator($short, $long);
$cg->setDocBlock($docBlock);
Expand All @@ -119,7 +120,8 @@ protected function recurseParams(array $expose, $fullClassName)
}
} else {
if ($ormClassMetaData->hasAssociation($value)) {
// This is an association field with no explicit include fields, include add data field (no relations)
// This is an association field with no explicit include fields,
// include add data field (no relations)
$this->handleAssocProperty($value, $cg, $ormClassMetaData);

$assocMapping = $ormClassMetaData->getAssociationMapping($value);
Expand Down Expand Up @@ -218,7 +220,9 @@ private function getSetterMethods(&$cg, $name, $type, $targetClass = null)

$pluralMethod->setName('add' . $this->camelCaseMethodName($pluralName));
$pluralMethod->setParameter(new ParameterGenerator($pluralName, 'array'));
$pluralMethod->setBody("foreach (\$$pluralName as \$$singledName) \n{\n \$this->$singleMethodName(\$$singledName);\n}");
$body = "foreach (\$$pluralName as \$$singledName) \n{\n";
$body .= " \$this->$singleMethodName(\$$singledName);\n}";
$pluralMethod->setBody($body);

$methods[] = $pluralMethod;
break;
Expand Down
16 changes: 9 additions & 7 deletions src/Drest/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public function __construct()
}

/**
* Set the debug mode - when on all DrestExceptions are rethrown, otherwise 500 errors are returned from the REST service
* Set the debug mode - when on all DrestExceptions are rethrown,
* otherwise 500 errors are returned from the REST service
* Should be switched off in production
* @param boolean $setting
*/
Expand Down Expand Up @@ -124,10 +125,10 @@ public function setMetadataCacheImpl(Cache $cacheImpl)
/**
* Set the methods to be used for detecting content type to be used to pull requests, overwrites previous settings
* Eg ->setDetectContentOptions(array(self::DETECT_CONTENT_HEADER => $headerName))
* self::DETECT_CONTENT_HEADER = Uses the a header to detect the required content (typically use Accept)
* self::DETECT_CONTENT_HEADER = Uses the a header to detect the required content (typically use Accept)
* self::DETECT_CONTENT_EXTENSION = Uses an extension on the url eg .xml
* self::DETECT_CONTENT_PARAM = Uses a the "format" parameter
* @param array - pass in either a single array value using the constant value as a key, or a multi-dimensional array.
* @param array - pass either a single array value using the constant value as a key, or a multi-dimensional array.
*/
public function setDetectContentOptions(array $options)
{
Expand All @@ -154,7 +155,8 @@ public function setDetectContentOption($option, $value)
}

/**
* Get detect content options. Returns an array indexed using constants as array key (value will be the value to be used for the content options)
* Get detect content options. Returns an array indexed using constants as array key
* (value will be the value to be used for the content options)
* Eg array(self::DETECT_CONTENT_HEADER => 'Accept')
* @return array
*/
Expand Down Expand Up @@ -507,7 +509,8 @@ public function getDefaultRepresentations()
}

/**
* Set the default representation classes to be used across the entire API. Any representations defined locally on a resource will take precedence
* Set the default representation classes to be used across the entire API.
* Any representations defined locally on a resource will take precedence
* @param array $representations
*/
public function setDefaultRepresentations(array $representations)
Expand All @@ -528,8 +531,7 @@ public function getDefaultErrorHandlerClass()
* Ensures that this Configuration instance contains settings that are
* suitable for a production environment.
*
* @throws DrestException If a configuration setting has a value that is not
* suitable for a production environment.
* @throws DrestException If a configuration setting has a value that is not suitable for a production.
*/
public function ensureProductionSettings()
{
Expand Down
80 changes: 55 additions & 25 deletions src/Drest/DrestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,80 @@ class DrestException extends Exception
// Set up and configuration
public static function metadataCacheNotConfigured()
{
return new self('Class Metadata Cache is not configured, ensure an instance of Doctrine\Common\Cache\Cache is passed to the Drest\Configuration::setMetadataCacheImpl()');
return new self(
'Class Metadata Cache is not configured, ensure an instance of Doctrine\Common\Cache\Cache' .
'is passed to the Drest\Configuration::setMetadataCacheImpl()');
}

public static function currentlyRunningDebugMode()
{
return new self('Debug mode is set to on. This will cause configuration exceptions to be displayed and should be switched off in production');
return new self(
'Debug mode is set to on. This will cause configuration exceptions to be' .
' displayed and should be switched off in production');
}

public static function annotatedResourceRequiresAtLeastOneServiceDefinition($className)
{
return new self('The annotated resource on class ' . $className . ' doesn\'t have any service definitions. Ensure you have "services={@Drest\Service(..)} set');
return new self(
'The annotated resource on class ' . $className . ' doesn\'t have any service definitions.' .
' Ensure you have "services={@Drest\Service(..)} set');
}

public static function routeAlreadyDefinedWithName($class, $name)
{
return new self('Route on class ' . $class . ' already exists with the name ' . $name . '. These must be unique');
return new self(
'Route on class ' . $class . ' already exists with the name ' . $name . '. These must be unique');
}

public static function routeNameIsEmpty()
{
return new self('Route name used cannot be blank, and must only contain alphanumerics or underscore');
return new self(
'Route name used cannot be blank, and must only contain alphanumerics or underscore');
}

public static function invalidHttpVerbUsed($verb)
{
return new self('Used an unknown HTTP verb of "' . $verb . '"');
return new self(
'Used an unknown HTTP verb of "' . $verb . '"');
}

public static function unknownDetectContentOption()
{
return new self('Content option used is invalid. Please see DETECT_CONTENT_* options in Drest\Configuration');
return new self(
'Content option used is invalid. Please see DETECT_CONTENT_* options in Drest\Configuration');
}

public static function pathToConfigFilesRequired()
{
return new self('Path to your configuration files are required for the driver to retrieve all class names');
return new self(
'Path to your configuration files are required for the driver to retrieve all class names');
}

public static function unableToLoadMetaDataFromDriver()
{
return new self('Unable to load metadata using supplied driver');
return new self(
'Unable to load metadata using supplied driver');
}

public static function invalidExposeRelationFetchType()
{
return new self('Invalid relation fetch type used. Please see Doctrine\ORM\Mapping\ClassMetadataInfo::FETCH_* for available options');
return new self(
'Invalid relation fetch type used. ' .
'Please see Doctrine\ORM\Mapping\ClassMetadataInfo::FETCH_* for available options');
}

public static function unknownExposeRequestOption()
{
return new self('Unknown expose request option used. Please see EXPOSE_REQUEST_* options in Drest\Configuration');
return new self(
'Unknown expose request option used. ' .
'Please see EXPOSE_REQUEST_* options in Drest\Configuration');
}

public static function invalidAllowedOptionsValue()
{
return new self('Invalid Allow Options value, must be -1 to unset, 0 for no or 1 for yes. Or you can use boolean values');
return new self(
'Invalid Allow Options value, must be -1 to unset,' .
' 0 for no or 1 for yes. Or you can use boolean values');
}

public static function basePathMustBeAString()
Expand All @@ -80,17 +98,23 @@ public static function basePathMustBeAString()

public static function alreadyHandleDefinedForRoute(Mapping\RouteMetaData $route)
{
return new self('There is a handle already defined for the route ' . $route->getName() . ' on class ' . $route->getClassMetaData()->getClassName());
return new self(
'There is a handle already defined for the route '
. $route->getName() . ' on class ' . $route->getClassMetaData()->getClassName());
}

public static function handleAnnotationDoesntMatchRouteName($name)
{
return new self('The configured handle "' . $name . '" doesn\'t match any route of that name. Ensure @Drest\Handle(for="my_route") matches @Drest\Route(name="my_route")');
return new self(
'The configured handle "' . $name . '" doesn\'t match any route of that name. ' .
'Ensure @Drest\Handle(for="my_route") matches @Drest\Route(name="my_route")');
}

public static function routeRequiresHandle($name)
{
return new self('Route requires a handle. Ensure a @Drest\Handle(for="' . $name . '") function is set. These are required for all push type routes (POST/PUT/PATCH)');
return new self(
'Route requires a handle. Ensure a @Drest\Handle(for="' . $name . '") function is set.' .
' These are required for all push type routes (POST/PUT/PATCH)');
}

public static function handleForCannotBeEmpty()
Expand All @@ -100,12 +124,15 @@ public static function handleForCannotBeEmpty()

public static function invalidNamedRouteSyntax()
{
return new self('Invalid named route syntax. Must use a formatted string of: {EntityClassName}::{RouteName}. Eg "Entities\\User::get_users"');
return new self(
'Invalid named route syntax. ' .
'Must use a formatted string of: {EntityClassName}::{RouteName}. Eg "Entities\\User::get_users"');
}

public static function unableToFindRouteByName($routeName, $className)
{
return new self('Unable to find the named route "' . $routeName . '" on class ' . $className);
return new self(
'Unable to find the named route "' . $routeName . '" on class ' . $className);
}

public static function resourceCanOnlyHaveOneRouteSetAsOrigin()
Expand All @@ -115,13 +142,16 @@ public static function resourceCanOnlyHaveOneRouteSetAsOrigin()

public static function unableToHandleACollectionPush()
{
return new self('Requests to push data (PUT/POST/PATCH) can only be used on individual elements. Data collections cannot be pushed');
return new self(
'Requests to push data (PUT/POST/PATCH) can only be used on individual elements.' .
' Data collections cannot be pushed');
}

// Service Exceptions
public static function actionClassNotAnInstanceOfActionAbstract($class)
{
return new self('Action class "' . $class . '" is not an instance of Drest\Service\Action\ActionAbstract.');
return new self(
'Action class "' . $class . '" is not an instance of Drest\Service\Action\ActionAbstract.');
}

public static function unknownActionClass($class)
Expand All @@ -131,14 +161,14 @@ public static function unknownActionClass($class)

public static function noMatchedRouteSet()
{
return new self('No matched route has been set on this service class. The content type is needed for a default service method call');
return new self(
'No matched route has been set on this service class.' .
' The content type is needed for a default service method call');
}

public static function dataWrapNameMustBeAString()
{
return new self('Data wrap name must be a string value. Eg array(\'user\' => array(...))');
return new self(
'Data wrap name must be a string value. Eg array(\'user\' => array(...))');
}
}



}
3 changes: 1 addition & 2 deletions src/Drest/Event/PostRoutingArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public function getService()
{
return $this->service;
}
}

}
3 changes: 1 addition & 2 deletions src/Drest/Event/PostServiceActionArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public function getService()
{
return $this->service;
}
}

}
3 changes: 1 addition & 2 deletions src/Drest/Event/PreRoutingArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public function getService()
{
return $this->service;
}
}

}
3 changes: 1 addition & 2 deletions src/Drest/Event/PreServiceActionArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public function getService()
{
return $this->service;
}
}

}
Loading

0 comments on commit 2bb4ff9

Please sign in to comment.