From 1576126e79420becc41f0bf5919e4a9150c8fe92 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 23 Mar 2013 19:15:55 +0100 Subject: [PATCH] updated api docs --- developer_manual/app/app/api/view.rst | 142 +++++++++--------- .../api/controller_controller.rst | 48 ++++-- .../app/appframework/api/core_api.rst | 30 +++- .../app/appframework/api/db_entity.rst | 80 ++++++++++ .../app/appframework/api/db_mapper.rst | 64 ++++---- .../api/http_forbiddenresponse.rst | 11 +- .../api/http_notfoundresponse.rst | 11 +- .../app/appframework/api/http_request.rst | 78 +++++++++- .../api/utility_controllertestutility.rst | 22 +-- .../api/utility_mappertestutility.rst | 63 ++++++++ .../appframework/api/utility_testutility.rst | 24 +++ 11 files changed, 437 insertions(+), 136 deletions(-) create mode 100644 developer_manual/app/appframework/api/db_entity.rst create mode 100644 developer_manual/app/appframework/api/utility_mappertestutility.rst create mode 100644 developer_manual/app/appframework/api/utility_testutility.rst diff --git a/developer_manual/app/app/api/view.rst b/developer_manual/app/app/api/view.rst index 2d623245d..1aa3a8e6f 100644 --- a/developer_manual/app/app/api/view.rst +++ b/developer_manual/app/app/api/view.rst @@ -13,20 +13,20 @@ View .. php:method:: __construct($root) - :param mixed $root: + :param mixed $root: .. php:method:: getAbsolutePath($path='/') - :param mixed $path: + :param mixed $path: .. php:method:: chroot($fakeRoot) - :param string $fakeRoot: - :returns bool: + :param string $fakeRoot: + :returns bool: change the root to a fake root @@ -34,7 +34,7 @@ View .. php:method:: getRoot() - :returns string: + :returns string: get the fake root @@ -42,8 +42,8 @@ View .. php:method:: getRelativePath($path) - :param string $path: - :returns string: + :param string $path: + :returns string: get path relative to the root of the view @@ -51,8 +51,8 @@ View .. php:method:: getMountPoint($path) - :param string $path: - :returns string: + :param string $path: + :returns string: get the mountpoint of the storage object for a path( note: because a storage is not always mounted inside the fakeroot, thereturned mountpoint is relative to the absolute root of the filesystemand doesn't take the chroot into account ) @@ -60,7 +60,7 @@ View .. php:method:: resolvePath($path) - :param string $path: + :param string $path: :returns array: consisting of the storage and the internal path @@ -69,8 +69,8 @@ View .. php:method:: getLocalFile($path) - :param string $path: - :returns string: + :param string $path: + :returns string: return the path to a local version of the filewe need this because we can't know if a file is stored local or not fromoutside the filestorage and for some purposes a local file is needed @@ -78,14 +78,14 @@ View .. php:method:: getLocalFolder($path) - :param string $path: - :returns string: + :param string $path: + :returns string: .. php:method:: mkdir($path) - :param mixed $path: + :param mixed $path: the following functions operate with arguments and return values identicalto those of their PHP built-in equivalents. @@ -94,192 +94,192 @@ View .. php:method:: rmdir($path) - :param mixed $path: + :param mixed $path: .. php:method:: opendir($path) - :param mixed $path: + :param mixed $path: .. php:method:: readdir($handle) - :param mixed $handle: + :param mixed $handle: .. php:method:: is_dir($path) - :param mixed $path: + :param mixed $path: .. php:method:: is_file($path) - :param mixed $path: + :param mixed $path: .. php:method:: stat($path) - :param mixed $path: + :param mixed $path: .. php:method:: filetype($path) - :param mixed $path: + :param mixed $path: .. php:method:: filesize($path) - :param mixed $path: + :param mixed $path: .. php:method:: readfile($path) - :param mixed $path: + :param mixed $path: .. php:method:: isCreatable($path) - :param mixed $path: + :param mixed $path: .. php:method:: isReadable($path) - :param mixed $path: + :param mixed $path: .. php:method:: isUpdatable($path) - :param mixed $path: + :param mixed $path: .. php:method:: isDeletable($path) - :param mixed $path: + :param mixed $path: .. php:method:: isSharable($path) - :param mixed $path: + :param mixed $path: .. php:method:: file_exists($path) - :param mixed $path: + :param mixed $path: .. php:method:: filemtime($path) - :param mixed $path: + :param mixed $path: .. php:method:: touch($path, $mtime=null) - :param mixed $path: - :param mixed $mtime: + :param mixed $path: + :param mixed $mtime: .. php:method:: file_get_contents($path) - :param mixed $path: + :param mixed $path: .. php:method:: file_put_contents($path, $data) - :param mixed $path: - :param mixed $data: + :param mixed $path: + :param mixed $data: .. php:method:: unlink($path) - :param mixed $path: + :param mixed $path: .. php:method:: deleteAll($directory, $empty=false) - :param mixed $directory: - :param mixed $empty: + :param mixed $directory: + :param mixed $empty: .. php:method:: rename($path1, $path2) - :param mixed $path1: - :param mixed $path2: + :param mixed $path1: + :param mixed $path2: .. php:method:: copy($path1, $path2) - :param mixed $path1: - :param mixed $path2: + :param mixed $path1: + :param mixed $path2: .. php:method:: fopen($path, $mode) - :param mixed $path: - :param mixed $mode: + :param mixed $path: + :param mixed $mode: .. php:method:: toTmpFile($path) - :param mixed $path: + :param mixed $path: .. php:method:: fromTmpFile($tmpFile, $path) - :param mixed $tmpFile: - :param mixed $path: + :param mixed $tmpFile: + :param mixed $path: .. php:method:: getMimeType($path) - :param mixed $path: + :param mixed $path: .. php:method:: hash($type, $path, $raw=false) - :param mixed $type: - :param mixed $path: - :param mixed $raw: + :param mixed $type: + :param mixed $path: + :param mixed $raw: .. php:method:: free_space($path='/') - :param mixed $path: + :param mixed $path: .. php:method:: hasUpdated($path, $time) - :param string $path: - :param int $time: - :returns bool: + :param string $path: + :param int $time: + :returns bool: check if a file or folder has been updated since $time @@ -287,7 +287,7 @@ View .. php:method:: getFileInfo($path) - :param string $path: + :param string $path: :returns array: returns an associative array with the following keys:- size- mtime- mimetype- encrypted- versioned @@ -297,8 +297,8 @@ View .. php:method:: getDirectoryContent($directory, $mimetype_filter='') :param string $directory: path under datadirectory - :param mixed $mimetype_filter: - :returns array: + :param mixed $mimetype_filter: + :returns array: get the content of a directory @@ -306,8 +306,8 @@ View .. php:method:: putFileInfo($path, $data) - :param string $path: - :param array $data: + :param string $path: + :param array $data: :returns int: returns the fileid of the updated file @@ -316,8 +316,8 @@ View .. php:method:: search($query) - :param string $query: - :returns array: + :param string $query: + :returns array: search for files with the name matching $query @@ -325,8 +325,8 @@ View .. php:method:: searchByMime($mimetype) - :param mixed $mimetype: - :returns array: + :param mixed $mimetype: + :returns array: search for files by mimetype @@ -334,8 +334,8 @@ View .. php:method:: getOwner($path) - :param string $path: - :returns string: + :param string $path: + :returns string: Get the owner for a file or folder @@ -343,8 +343,8 @@ View .. php:method:: getETag($path) - :param string $path: - :returns string: + :param string $path: + :returns string: get the ETag for a file or folder @@ -352,8 +352,8 @@ View .. php:method:: getPath($id) - :param int $id: - :returns string: + :param int $id: + :returns string: Get the path of a file by id, relative to the view diff --git a/developer_manual/app/appframework/api/controller_controller.rst b/developer_manual/app/appframework/api/controller_controller.rst index 783bf7650..374052d85 100644 --- a/developer_manual/app/appframework/api/controller_controller.rst +++ b/developer_manual/app/appframework/api/controller_controller.rst @@ -26,14 +26,6 @@ Baseclass to inherit your controllers from - .. php:method:: setURLParams($urlParams=array()) - - :param array $urlParams: - - - URL params are passed to this method from the routes dispatcher to be available via the $this->params - - .. php:method:: params($key, $default=null) :param string $key: the key which you want to access in the URL Parameter placeholder, $_POST or $_GET array. The priority how they're returned is the following: 1. URL parameters 2. POST parameters 3. GET parameters @@ -52,6 +44,14 @@ Baseclass to inherit your controllers from Returns all params that were received, be it from the request(as GET or POST) or throuh the URL by the route + .. php:method:: method() + + :returns string: the method of the request (POST, GET, etc) + + + Returns the method of the request + + .. php:method:: getUploadedFile($key) :param string $key: the key that will be taken from the $_FILES array @@ -61,6 +61,34 @@ Baseclass to inherit your controllers from Shortcut for accessing an uploaded file through the $_FILES array + .. php:method:: env($key) + + :param string $key: the key that will be taken from the $_ENV array + :returns array: the value in the $_ENV element + + + Shortcut for getting env variables + + + .. php:method:: session($key, $value=null) + + :param string $key: the key that will be taken from the $_SESSION array + :param string $value: if given sets a new session variable + :returns array: the value in the $_SESSION element + + + Shortcut for getting and setting session variables + + + .. php:method:: cookie($key) + + :param string $key: the key that will be taken from the $_COOKIE array + :returns array: the value in the $_COOKIE element + + + Shortcut for getting and setting cookie variables + + .. php:method:: render($templateName, $params=array(), $renderAs='user', $headers=array()) :param string $templateName: the name of the template @@ -73,9 +101,9 @@ Baseclass to inherit your controllers from Shortcut for rendering a template - .. php:method:: renderJSON($data, $errorMsg=null) + .. php:method:: renderJSON($data=array(), $errorMsg=null) - :param array $data: the PHP array that will be put into the JSON data index + :param array $data: the PHP array that will be put into the JSON data indexempty by default :param string $errorMsg: If you want to return an error message, pass one :returns \\OCA\\AppFramework\\Http\\JSONResponse: containing the values diff --git a/developer_manual/app/appframework/api/core_api.rst b/developer_manual/app/appframework/api/core_api.rst index 683368203..dc40d70a5 100644 --- a/developer_manual/app/appframework/api/core_api.rst +++ b/developer_manual/app/appframework/api/core_api.rst @@ -29,6 +29,14 @@ class and add your methods used to return the appname of the set application + .. php:method:: addNavigationEntry($entry) + + :param array $entry: containing: id, name, order, icon and href key + + + Creates a new navigation entry + + .. php:method:: getUserId() :returns string: the user id of the current user @@ -84,7 +92,7 @@ class and add your methods :returns string: the saved value - Looks up a systemwide defined value from the config/config.php + Looks up a systemwide defined value .. php:method:: setSystemValue($key, $value) @@ -93,7 +101,7 @@ class and add your methods :param string $value: the value that should be stored - Writes a new systemwide value into the config/config.php + Sets a new systemwide value .. php:method:: getAppValue($key, $appName=null) @@ -173,6 +181,24 @@ class and add your methods Returns the URL for a route + .. php:method:: linkTo($file, $appName=null) + + :param string $file: the name of the file + :param string $appName: the name of the app, defaults to the current one + + + Returns an URL for an image or file + + + .. php:method:: imagePath($file, $appName=null) + + :param string $file: the name of the file + :param string $appName: the name of the app, defaults to the current one + + + Returns the link to an image, like link to but only with prepending img/ + + .. php:method:: getAbsoluteURL($url) :param string $url: the url diff --git a/developer_manual/app/appframework/api/db_entity.rst b/developer_manual/app/appframework/api/db_entity.rst new file mode 100644 index 000000000..85e96c648 --- /dev/null +++ b/developer_manual/app/appframework/api/db_entity.rst @@ -0,0 +1,80 @@ +Entity +====== + + + + + +.. php:namespace:: OCA\AppFramework\Db +.. php:class:: Entity + + * **Abstract** + + + .. php:attr:: $id + + + + + + .. php:method:: __construct() + + + + + .. php:method:: resetUpdatedFields() + + + + Marks the entity as clean needed for setting the id after the insertion + + + .. php:method:: __call($methodName, $args) + + :param mixed $methodName: + :param mixed $args: + + + Each time a setter is called, push the part after setinto an array: for instance setId will save Id in theupdated fields array so it can be easily used to create thegetter method + + + .. php:method:: markFieldUpdated($attribute) + + :param string $attribute: the name of the attribute + + * **Protected** + + + Mark am attribute as updated + + + .. php:method:: columnToProperty($columnName) + + :param string $columnName: the name of the column + :returns string: the property name + + + Transform a database columnname to a property + + + .. php:method:: propertyToColumn($property) + + :param string $property: the name of the property + :returns string: the column name + + + Transform a property to a database column name + + + .. php:method:: getUpdatedFields() + + :returns array: array of updated fields for update query + + + + .. php:method:: fromRow($row) + + :param array $row: the row to map onto the entity + + + Maps the keys of the row array to the attributes diff --git a/developer_manual/app/appframework/api/db_mapper.rst b/developer_manual/app/appframework/api/db_mapper.rst index bd2a57c11..4ef2f6130 100644 --- a/developer_manual/app/appframework/api/db_mapper.rst +++ b/developer_manual/app/appframework/api/db_mapper.rst @@ -14,45 +14,55 @@ may be subject to change in the future - .. php:method:: __construct($api) + .. php:method:: __construct($api, $tableName) :param \\OCA\\AppFramework\\Core\\API $api: Instance of the API abstraction layer + :param string $tableName: the name of the table. set this to allow entity queries without using sql - .. php:method:: findQuery($tableName, $id) + .. php:method:: getTableName() - :param string $tableName: the name of the table to query - :param int $id: the id of the item + :returns string: the table name + + + + .. php:method:: delete($entity) + + :param \\OCA\\AppFramework\\Db\\Entity $entity: + + + Deletes an entity from the table + + + .. php:method:: insert($entity) + + :param \\OCA\\AppFramework\\Db\\Entity $entity: + :returns \\OCA\\AppFramework\\Db\\the: saved entity with the set id + + + Creates a new entry in the db from an entity + + + .. php:method:: update($entity) + + :param \\OCA\\AppFramework\\Db\\Entity $entity: + + + Updates an entry in the db from an entity + + + .. php:method:: findOneQuery($sql, $params) + + :param string $sql: the sql query + :param array $params: the parameters of the sql query :throws \\OCA\\AppFramework\\Db\\DoesNotExistException: if the item does not exist :returns array: the result as row * **Protected** - Returns an db result by id - - - .. php:method:: findAllQuery($tableName) - - :param string $tableName: the name of the table to query - :returns \\PDOStatement: the result - - * **Protected** - - - Returns all entries of a table - - - .. php:method:: deleteQuery($tableName, $id) - - :param string $tableName: the name of the table to query - :param int $id: the id of the item - - * **Protected** - - - Deletes a row in a table by id + Returns an db result and throws exceptions when there are more or lessresults .. php:method:: execute($sql, $params=array(), $limit=null, $offset=null) diff --git a/developer_manual/app/appframework/api/http_forbiddenresponse.rst b/developer_manual/app/appframework/api/http_forbiddenresponse.rst index 086001d83..8b4b14512 100644 --- a/developer_manual/app/appframework/api/http_forbiddenresponse.rst +++ b/developer_manual/app/appframework/api/http_forbiddenresponse.rst @@ -2,11 +2,7 @@ ForbiddenResponse ================= -Returns 403 Forbidden status to user. - -This Class renders response with HTTP/1.1 403 Forbidden header and empty -content. If you want to return specified content, please extend it with your -own class. +Pure hader response, Just return 403 status to the browser .. php:namespace:: OCA\AppFramework\Http @@ -14,6 +10,9 @@ own class. + .. php:method:: __construct() - Creates a response that returns HTTP 403 Forbidden status. + + + Creates a response that just returns 404 status diff --git a/developer_manual/app/appframework/api/http_notfoundresponse.rst b/developer_manual/app/appframework/api/http_notfoundresponse.rst index dd50def45..20cde35a5 100644 --- a/developer_manual/app/appframework/api/http_notfoundresponse.rst +++ b/developer_manual/app/appframework/api/http_notfoundresponse.rst @@ -2,11 +2,7 @@ NotFoundResponse ================ -Returns 404 Not Found status to user. - -This Class renders response with HTTP/1.1 404 Not Found header and empty -content. If you want to return specified content, please extend it with your -own class. +Pure hader response, Just return 404 status to the browser .. php:namespace:: OCA\AppFramework\Http @@ -14,6 +10,9 @@ own class. + .. php:method:: __construct() - Creates a response that returns HTTP 404 Not Found status. + + + Creates a response that just returns 404 status diff --git a/developer_manual/app/appframework/api/http_request.rst b/developer_manual/app/appframework/api/http_request.rst index 110756a6a..a263ec7a9 100644 --- a/developer_manual/app/appframework/api/http_request.rst +++ b/developer_manual/app/appframework/api/http_request.rst @@ -11,20 +11,25 @@ Encapsulates $_GET, $_FILES and $_POST arrays for better testability - .. php:method:: __construct($get=array(), $post=array(), $files=array()) + .. php:method:: __construct($get=array(), $post=array(), $files=array(), $server=array(), $env=array(), $session=array(), $cookie=array(), $urlParams=array()) :param array $get: the $_GET array :param array $post: the $_POST array :param array $files: the $_FILES array + :param array $server: the $_SERVER array + :param array $env: the $_ENV array + :param array $session: the $_SESSION array + :param array $cookie: the $_COOKIE array + :param array $urlParams: the parameters which were matched from the URL - .. php:method:: getGETAndPOST() + .. php:method:: getRequestParams() :returns array: the merged array - Returns the merged GET and POST array + Returns the merged urlParams, GET and POST array .. php:method:: getGET($key, $default=null) @@ -54,3 +59,70 @@ Encapsulates $_GET, $_FILES and $_POST arrays for better testability Returns the get value of the files array + + + .. php:method:: getSERVER($key, $default=null) + + :param string $key: the array key that should be looked up + :param string $default: if the key is not found, return this value + :returns mixed: the value of the stored array or the default + + + Returns the get value of the server array + + + .. php:method:: getENV($key, $default=null) + + :param string $key: the array key that should be looked up + :param string $default: if the key is not found, return this value + :returns mixed: the value of the stored array or the default + + + Returns the get value of the env array + + + .. php:method:: getSESSION($key, $default=null) + + :param string $key: the array key that should be looked up + :param string $default: if the key is not found, return this value + :returns mixed: the value of the stored array or the default + + + Returns the get value of the session array + + + .. php:method:: getCOOKIE($key, $default=null) + + :param string $key: the array key that should be looked up + :param string $default: if the key is not found, return this value + :returns mixed: the value of the stored array or the default + + + Returns the get value of the cookie array + + + .. php:method:: getURLParams($key, $default=null) + + :param string $key: the array key that should be looked up + :param string $default: if the key is not found, return this value + :returns mixed: the value of the stored array or the default + + + Returns the get value of the urlParams array + + + .. php:method:: getMethod() + + :returns string: request method of the server array + + + Returns the request method + + + .. php:method:: setSESSION($key, $value) + + :param string $key: the key of the session variable + :param string $value: the value of the session variable + + + Sets a session variable diff --git a/developer_manual/app/appframework/api/utility_controllertestutility.rst b/developer_manual/app/appframework/api/utility_controllertestutility.rst index 46d9a47f5..c385669a2 100644 --- a/developer_manual/app/appframework/api/utility_controllertestutility.rst +++ b/developer_manual/app/appframework/api/utility_controllertestutility.rst @@ -13,17 +13,6 @@ Simple utility class for testing controllers - .. php:method:: getAPIMock($apiClass='OCA\AppFramework\Core\API', $constructor=array('appname')) - - :param string $apiClass: the class inclusive namespace of the api that we want to use - :param array $constructor: constructor parameters of the api class - - * **Protected** - - - Boilerplate function for getting an API Mock class - - .. php:method:: assertAnnotations($controller, $method, $expected, $valid=array()) :param \\OCA\\AppFramework\\Utility\\Controller/string $controller: name or instance of the controller @@ -46,3 +35,14 @@ Simple utility class for testing controllers Shortcut for testing expected headers of a response + + + .. php:method:: getRequest($params) + + :param array $params: a hashmap with the parameters for request + :returns \\OCA\\AppFramework\\Http\\Request: a request instance + + * **Protected** + + + Instead of using positional parameters this function instantiatesa request by using a hashmap so its easier to only set specific params diff --git a/developer_manual/app/appframework/api/utility_mappertestutility.rst b/developer_manual/app/appframework/api/utility_mappertestutility.rst new file mode 100644 index 000000000..cd186ec47 --- /dev/null +++ b/developer_manual/app/appframework/api/utility_mappertestutility.rst @@ -0,0 +1,63 @@ +MapperTestUtility +================= + + +Simple utility class for testing mappers + + +.. php:namespace:: OCA\AppFramework\Utility +.. php:class:: MapperTestUtility + + * **Abstract** + + + .. php:attr:: $api + + * **Protected** + + + + + + .. php:method:: beforeEach() + + + * **Protected** + + + Run this function before the actual test to either set or initialize theapi. + After this the api can be accessed by using $this->api + + + .. php:method:: setMapperResult($sql, $arguments=array(), $returnRows=array()) + + :param string $sql: the sql query that you expect to receive + :param array $arguments: the expected arguments for the prepare querymethod + :param array $returnRows: the rows that should be returned for the resultof the database query. If not provided, it wont be assumed that fetchRowwill be called on the result + + * **Protected** + + + Create mocks and set expected results for database queries +ArgumentIterator +================ + + + + + +.. php:namespace:: OCA\AppFramework\Utility +.. php:class:: ArgumentIterator + + + + + .. php:method:: __construct($arguments) + + :param mixed $arguments: + + + + .. php:method:: next() + + diff --git a/developer_manual/app/appframework/api/utility_testutility.rst b/developer_manual/app/appframework/api/utility_testutility.rst new file mode 100644 index 000000000..594a02b57 --- /dev/null +++ b/developer_manual/app/appframework/api/utility_testutility.rst @@ -0,0 +1,24 @@ +TestUtility +=========== + + +Simple utility class for testing anything using an api + + +.. php:namespace:: OCA\AppFramework\Utility +.. php:class:: TestUtility + + * **Abstract** + + + + + .. php:method:: getAPIMock($apiClass='OCA\AppFramework\Core\API', $constructor=array('appname')) + + :param string $apiClass: the class inclusive namespace of the api that we want to use + :param array $constructor: constructor parameters of the api class + + * **Protected** + + + Boilerplate function for getting an API Mock class