From: Thomas Müller Date: Sat, 31 Aug 2013 19:34:29 +0000 (+0200) Subject: move new interfaces into lib/public and OCP X-Git-Tag: v6.0.0alpha2~121^2~28 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=206f83941b26b16f89e695ae84b998e9cf11132a;p=nextcloud-server.git move new interfaces into lib/public and OCP --- diff --git a/lib/appframework/dependencyinjection/dicontainer.php b/lib/appframework/dependencyinjection/dicontainer.php index 43f6eee29b0..2ef885d7b2c 100644 --- a/lib/appframework/dependencyinjection/dicontainer.php +++ b/lib/appframework/dependencyinjection/dicontainer.php @@ -132,7 +132,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{ } /** - * @return \OCP\Core\IServerContainer + * @return \OCP\IServerContainer */ function getServer() { diff --git a/lib/appframework/http/request.php b/lib/appframework/http/request.php index ab72a8db697..4f1775182a1 100644 --- a/lib/appframework/http/request.php +++ b/lib/appframework/http/request.php @@ -22,7 +22,7 @@ namespace OC\AppFramework\Http; -use OCP\Core\IRequest; +use OCP\IRequest; /** * Class for accessing variables in the request. diff --git a/lib/appframework/utility/simplecontainer.php b/lib/appframework/utility/simplecontainer.php index 04b6cd727b8..a51ace83a37 100644 --- a/lib/appframework/utility/simplecontainer.php +++ b/lib/appframework/utility/simplecontainer.php @@ -10,7 +10,7 @@ require_once __DIR__ . '/../../../3rdparty/Pimple/Pimple.php'; * * SimpleContainer is a simple implementation of IContainer on basis of \Pimple */ -class SimpleContainer extends \Pimple implements \OCP\Core\IContainer { +class SimpleContainer extends \Pimple implements \OCP\IContainer { /** * @param string $name name of the service to query for diff --git a/lib/contactsmanager.php b/lib/contactsmanager.php index 59c413ec03b..fc6745b4505 100644 --- a/lib/contactsmanager.php +++ b/lib/contactsmanager.php @@ -22,7 +22,7 @@ namespace OC { - class ContactsManager implements \OCP\Core\Contacts\IManager { + class ContactsManager implements \OCP\Contacts\IManager { /** * This function is used to search and find contacts within the users address books. diff --git a/lib/public/appframework/iappcontainer.php b/lib/public/appframework/iappcontainer.php index db909241e5d..c8f6229dd9e 100644 --- a/lib/public/appframework/iappcontainer.php +++ b/lib/public/appframework/iappcontainer.php @@ -23,7 +23,7 @@ namespace OCP\AppFramework; use OCP\AppFramework\IApi; -use OCP\Core\IContainer; +use OCP\IContainer; /** * Class IAppContainer @@ -39,7 +39,7 @@ interface IAppContainer extends IContainer{ function getCoreApi(); /** - * @return \OCP\Core\IServerContainer + * @return \OCP\IServerContainer */ function getServer(); } diff --git a/lib/public/contacts/imanager.php b/lib/public/contacts/imanager.php new file mode 100644 index 00000000000..3bfbca7be50 --- /dev/null +++ b/lib/public/contacts/imanager.php @@ -0,0 +1,150 @@ +. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Contacts Class + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Contacts { + + /** + * This class provides access to the contacts app. Use this class exclusively if you want to access contacts. + * + * Contacts in general will be expressed as an array of key-value-pairs. + * The keys will match the property names defined in https://tools.ietf.org/html/rfc2426#section-1 + * + * Proposed workflow for working with contacts: + * - search for the contacts + * - manipulate the results array + * - createOrUpdate will save the given contacts overwriting the existing data + * + * For updating it is mandatory to keep the id. + * Without an id a new contact will be created. + * + */ + interface IManager { + + /** + * This function is used to search and find contacts within the users address books. + * In case $pattern is empty all contacts will be returned. + * + * Example: + * Following function shows how to search for contacts for the name and the email address. + * + * public static function getMatchingRecipient($term) { + * $cm = \OC::$server->getContactsManager(); + * // The API is not active -> nothing to do + * if (!$cm->isEnabled()) { + * return array(); + * } + * + * $result = $cm->search($term, array('FN', 'EMAIL')); + * $receivers = array(); + * foreach ($result as $r) { + * $id = $r['id']; + * $fn = $r['FN']; + * $email = $r['EMAIL']; + * if (!is_array($email)) { + * $email = array($email); + * } + * + * // loop through all email addresses of this contact + * foreach ($email as $e) { + * $displayName = $fn . " <$e>"; + * $receivers[] = array( + * 'id' => $id, + * 'label' => $displayName, + * 'value' => $displayName); + * } + * } + * + * return $receivers; + * } + * + * + * @param string $pattern which should match within the $searchProperties + * @param array $searchProperties defines the properties within the query pattern should match + * @param array $options - for future use. One should always have options! + * @return array of contacts which are arrays of key-value-pairs + */ + function search($pattern, $searchProperties = array(), $options = array()); + + /** + * This function can be used to delete the contact identified by the given id + * + * @param object $id the unique identifier to a contact + * @param $address_book_key + * @return bool successful or not + */ + function delete($id, $address_book_key); + + /** + * This function is used to create a new contact if 'id' is not given or not present. + * Otherwise the contact will be updated by replacing the entire data set. + * + * @param array $properties this array if key-value-pairs defines a contact + * @param $address_book_key string to identify the address book in which the contact shall be created or updated + * @return array representing the contact just created or updated + */ + function createOrUpdate($properties, $address_book_key); + + /** + * Check if contacts are available (e.g. contacts app enabled) + * + * @return bool true if enabled, false if not + */ + function isEnabled(); + + /** + * @param \OCP\IAddressBook $address_book + */ + function registerAddressBook(\OCP\IAddressBook $address_book); + + /** + * @param \OCP\IAddressBook $address_book + */ + function unregisterAddressBook(\OCP\IAddressBook $address_book); + + /** + * In order to improve lazy loading a closure can be registered which will be called in case + * address books are actually requested + * + * @param string $key + * @param \Closure $callable + */ + function register($key, \Closure $callable); + + /** + * @return array + */ + function getAddressBooks(); + + /** + * removes all registered address book instances + */ + function clear(); + } +} diff --git a/lib/public/core/contacts/imanager.php b/lib/public/core/contacts/imanager.php deleted file mode 100644 index e8bb7bfd8e4..00000000000 --- a/lib/public/core/contacts/imanager.php +++ /dev/null @@ -1,150 +0,0 @@ -. - * - */ - -/** - * Public interface of ownCloud for apps to use. - * Contacts Class - * - */ - -// use OCP namespace for all classes that are considered public. -// This means that they should be used by apps instead of the internal ownCloud classes -namespace OCP\Core\Contacts { - - /** - * This class provides access to the contacts app. Use this class exclusively if you want to access contacts. - * - * Contacts in general will be expressed as an array of key-value-pairs. - * The keys will match the property names defined in https://tools.ietf.org/html/rfc2426#section-1 - * - * Proposed workflow for working with contacts: - * - search for the contacts - * - manipulate the results array - * - createOrUpdate will save the given contacts overwriting the existing data - * - * For updating it is mandatory to keep the id. - * Without an id a new contact will be created. - * - */ - interface IManager { - - /** - * This function is used to search and find contacts within the users address books. - * In case $pattern is empty all contacts will be returned. - * - * Example: - * Following function shows how to search for contacts for the name and the email address. - * - * public static function getMatchingRecipient($term) { - * $cm = \OC::$server->getContactsManager(); - * // The API is not active -> nothing to do - * if (!$cm->isEnabled()) { - * return array(); - * } - * - * $result = $cm->search($term, array('FN', 'EMAIL')); - * $receivers = array(); - * foreach ($result as $r) { - * $id = $r['id']; - * $fn = $r['FN']; - * $email = $r['EMAIL']; - * if (!is_array($email)) { - * $email = array($email); - * } - * - * // loop through all email addresses of this contact - * foreach ($email as $e) { - * $displayName = $fn . " <$e>"; - * $receivers[] = array( - * 'id' => $id, - * 'label' => $displayName, - * 'value' => $displayName); - * } - * } - * - * return $receivers; - * } - * - * - * @param string $pattern which should match within the $searchProperties - * @param array $searchProperties defines the properties within the query pattern should match - * @param array $options - for future use. One should always have options! - * @return array of contacts which are arrays of key-value-pairs - */ - function search($pattern, $searchProperties = array(), $options = array()); - - /** - * This function can be used to delete the contact identified by the given id - * - * @param object $id the unique identifier to a contact - * @param $address_book_key - * @return bool successful or not - */ - function delete($id, $address_book_key); - - /** - * This function is used to create a new contact if 'id' is not given or not present. - * Otherwise the contact will be updated by replacing the entire data set. - * - * @param array $properties this array if key-value-pairs defines a contact - * @param $address_book_key string to identify the address book in which the contact shall be created or updated - * @return array representing the contact just created or updated - */ - function createOrUpdate($properties, $address_book_key); - - /** - * Check if contacts are available (e.g. contacts app enabled) - * - * @return bool true if enabled, false if not - */ - function isEnabled(); - - /** - * @param \OCP\IAddressBook $address_book - */ - function registerAddressBook(\OCP\IAddressBook $address_book); - - /** - * @param \OCP\IAddressBook $address_book - */ - function unregisterAddressBook(\OCP\IAddressBook $address_book); - - /** - * In order to improve lazy loading a closure can be registered which will be called in case - * address books are actually requested - * - * @param string $key - * @param \Closure $callable - */ - function register($key, \Closure $callable); - - /** - * @return array - */ - function getAddressBooks(); - - /** - * removes all registered address book instances - */ - function clear(); - } -} diff --git a/lib/public/core/icontainer.php b/lib/public/core/icontainer.php deleted file mode 100644 index 88ebc6cf64d..00000000000 --- a/lib/public/core/icontainer.php +++ /dev/null @@ -1,64 +0,0 @@ -. - * - */ - -namespace OCP\Core; - -/** - * Class IContainer - * - * IContainer is the basic interface to be used for any internal dependency injection mechanism - * - * @package OCP\Core - */ -interface IContainer { - - /** - * Look up a service for a given name in the container. - * - * @param string $name - * @return mixed - */ - function query($name); - - /** - * A value is stored in the container with it's corresponding name - * - * @param string $name - * @param mixed $value - * @return void - */ - function registerParameter($name, $value); - - /** - * A service is registered in the container where a closure is passed in which will actually - * create the service on demand. - * In case the parameter $shared is set to true (the default usage) the once created service will remain in - * memory and be reused on subsequent calls. - * In case the parameter is false the service will be recreated on every call. - * - * @param string $name - * @param callable $closure - * @param bool $shared - * @return void - */ - function registerService($name, \Closure $closure, $shared = true); -} diff --git a/lib/public/core/irequest.php b/lib/public/core/irequest.php deleted file mode 100644 index be60978a3c3..00000000000 --- a/lib/public/core/irequest.php +++ /dev/null @@ -1,105 +0,0 @@ -. - * - */ - -namespace OCP\Core; - - -interface IRequest { - - function getHeader($name); - - /** - * Lets you access post and get parameters by the index - * In case of json requests the encoded json body is accessed - * - * @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 - * @param mixed $default If the key is not found, this value will be returned - * @return mixed the content of the array - */ - public function getParam($key, $default = null); - - - /** - * Returns all params that were received, be it from the request - * - * (as GET or POST) or through the URL by the route - * @return array the array with all parameters - */ - public function getParams(); - - /** - * Returns the method of the request - * - * @return string the method of the request (POST, GET, etc) - */ - public function getMethod(); - - /** - * Shortcut for accessing an uploaded file through the $_FILES array - * - * @param string $key the key that will be taken from the $_FILES array - * @return array the file in the $_FILES element - */ - public function getUploadedFile($key); - - - /** - * Shortcut for getting env variables - * - * @param string $key the key that will be taken from the $_ENV array - * @return array the value in the $_ENV element - */ - public function getEnv($key); - - - /** - * Shortcut for getting session variables - * - * @param string $key the key that will be taken from the $_SESSION array - * @return array the value in the $_SESSION element - */ - function getSession($key); - - - /** - * Shortcut for getting cookie variables - * - * @param string $key the key that will be taken from the $_COOKIE array - * @return array the value in the $_COOKIE element - */ - function getCookie($key); - - - /** - * Returns the request body content. - * - * @param Boolean $asResource If true, a resource will be returned - * @return string|resource The request body content or a resource to read the body stream. - * @throws \LogicException - */ - function getContent($asResource = false); -} diff --git a/lib/public/core/iservercontainer.php b/lib/public/core/iservercontainer.php deleted file mode 100644 index 0517cc53e09..00000000000 --- a/lib/public/core/iservercontainer.php +++ /dev/null @@ -1,51 +0,0 @@ -. - * - */ - -namespace OCP\Core; - - -/** - * Class IServerContainer - * @package OCP\Core - * - * This container holds all ownCloud services - */ -interface IServerContainer { - - /** - * The contacts manager will act as a broker between consumers for contacts information and - * providers which actual deliver the contact information. - * - * @return \OCP\Core\Contacts\IManager - */ - function getContactsManager(); - - /** - * The current request object holding all information about the request currently being processed - * is returned from this method. - * In case the current execution was not initiated by a web request null is returned - * - * @return \OCP\Core\IRequest|null - */ - function getRequest(); - -} diff --git a/lib/public/icontainer.php b/lib/public/icontainer.php new file mode 100644 index 00000000000..d43c1c90f11 --- /dev/null +++ b/lib/public/icontainer.php @@ -0,0 +1,64 @@ +. + * + */ + +namespace OCP; + +/** + * Class IContainer + * + * IContainer is the basic interface to be used for any internal dependency injection mechanism + * + * @package OCP + */ +interface IContainer { + + /** + * Look up a service for a given name in the container. + * + * @param string $name + * @return mixed + */ + function query($name); + + /** + * A value is stored in the container with it's corresponding name + * + * @param string $name + * @param mixed $value + * @return void + */ + function registerParameter($name, $value); + + /** + * A service is registered in the container where a closure is passed in which will actually + * create the service on demand. + * In case the parameter $shared is set to true (the default usage) the once created service will remain in + * memory and be reused on subsequent calls. + * In case the parameter is false the service will be recreated on every call. + * + * @param string $name + * @param callable $closure + * @param bool $shared + * @return void + */ + function registerService($name, \Closure $closure, $shared = true); +} diff --git a/lib/public/irequest.php b/lib/public/irequest.php new file mode 100644 index 00000000000..cd39855950b --- /dev/null +++ b/lib/public/irequest.php @@ -0,0 +1,105 @@ +. + * + */ + +namespace OCP; + + +interface IRequest { + + function getHeader($name); + + /** + * Lets you access post and get parameters by the index + * In case of json requests the encoded json body is accessed + * + * @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 + * @param mixed $default If the key is not found, this value will be returned + * @return mixed the content of the array + */ + public function getParam($key, $default = null); + + + /** + * Returns all params that were received, be it from the request + * + * (as GET or POST) or through the URL by the route + * @return array the array with all parameters + */ + public function getParams(); + + /** + * Returns the method of the request + * + * @return string the method of the request (POST, GET, etc) + */ + public function getMethod(); + + /** + * Shortcut for accessing an uploaded file through the $_FILES array + * + * @param string $key the key that will be taken from the $_FILES array + * @return array the file in the $_FILES element + */ + public function getUploadedFile($key); + + + /** + * Shortcut for getting env variables + * + * @param string $key the key that will be taken from the $_ENV array + * @return array the value in the $_ENV element + */ + public function getEnv($key); + + + /** + * Shortcut for getting session variables + * + * @param string $key the key that will be taken from the $_SESSION array + * @return array the value in the $_SESSION element + */ + function getSession($key); + + + /** + * Shortcut for getting cookie variables + * + * @param string $key the key that will be taken from the $_COOKIE array + * @return array the value in the $_COOKIE element + */ + function getCookie($key); + + + /** + * Returns the request body content. + * + * @param Boolean $asResource If true, a resource will be returned + * @return string|resource The request body content or a resource to read the body stream. + * @throws \LogicException + */ + function getContent($asResource = false); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php new file mode 100644 index 00000000000..5f5b9677549 --- /dev/null +++ b/lib/public/iservercontainer.php @@ -0,0 +1,51 @@ +. + * + */ + +namespace OCP; + + +/** + * Class IServerContainer + * @package OCP + * + * This container holds all ownCloud services + */ +interface IServerContainer { + + /** + * The contacts manager will act as a broker between consumers for contacts information and + * providers which actual deliver the contact information. + * + * @return \OCP\Contacts\IManager + */ + function getContactsManager(); + + /** + * The current request object holding all information about the request currently being processed + * is returned from this method. + * In case the current execution was not initiated by a web request null is returned + * + * @return \OCP\IRequest|null + */ + function getRequest(); + +} diff --git a/lib/server.php b/lib/server.php index 72c82efe16b..ad955bf5c65 100644 --- a/lib/server.php +++ b/lib/server.php @@ -3,7 +3,7 @@ namespace OC; use OC\AppFramework\Utility\SimpleContainer; -use OCP\Core\IServerContainer; +use OCP\IServerContainer; /** * Class Server @@ -20,9 +20,21 @@ class Server extends SimpleContainer implements IServerContainer { } /** - * @return \OCP\Core\Contacts\IManager + * @return \OCP\Contacts\IManager */ function getContactsManager() { return $this->query('ContactsManager'); } + + /** + * The current request object holding all information about the request currently being processed + * is returned from this method. + * In case the current execution was not initiated by a web request null is returned + * + * @return \OCP\IRequest|null + */ + function getRequest() + { + return $this->query('Request'); + } }