--- /dev/null
+<?php
+/**
+ * A Horde_Injector:: based Horde_Share:: factory.
+ *
+ * @category Horde
+ * @package Core
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ */
+
+/**
+ * A Horde_Injector:: based Horde_Identity:: factory.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Core
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ */
+class Horde_Core_Factory_Share
+{
+ /**
+ * Instances.
+ *
+ * @var array
+ */
+ private $_instances = array();
+
+ /**
+ * The injector.
+ *
+ * @var Horde_Injector
+ */
+ private $_injector;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Injector $injector The injector to use.
+ */
+ public function __construct(Horde_Injector $injector)
+ {
+ $this->_injector = $injector;
+ }
+
+ /**
+ * Return the Horde_Share:: instance.
+ *
+ * @param string $app The application scope to use, if not the current
+ * app.
+ * @param string $driver The share driver. Either empty (use default
+ * driver from $conf) or a driver name.
+ *
+ * @return Horde_Share The Horde_Share instance.
+ * @throws Horde_Exception
+ */
+ public function getScope($app = null, $driver = null)
+ {
+ if (empty($driver)) {
+ $driver = $GLOBALS['conf']['share']['driver'];
+ }
+ if (empty($app)) {
+ $app = $this->_injector->getInstance('Horde_Registry')->getApp();
+ }
+
+ $class = 'Horde_Share_' . ucfirst(basename($driver));
+ $signature = $app . '_' . $driver;
+ if (!isset($this->_instances[$signature]) &&
+ !empty($GLOBALS['conf']['share']['cache'])) {
+
+ $session = new Horde_SessionObjects();
+ $shares[$signature] = $session->query('horde_share_' . $app . '_' . $driver . '1');
+ }
+
+ if (empty($shares[$signature])) {
+ if (!class_exists($class)) {
+ throw new Horde_Exception((sprintf(_("\"%s\" share driver not found."), $driver)));
+ }
+
+ $shares[$signature] = new $class($app);
+ }
+
+ if (!isset($shares[$signature]) &&
+ !empty($GLOBALS['conf']['share']['cache'])) {
+ $session = new Horde_SessionObjects();
+ $shares[$signature] = $session->query('horde_share_' . $app . '_' . $driver . '1');
+ }
+
+ if (!empty($GLOBALS['conf']['share']['cache'])) {
+ register_shutdown_function(array($shares[$signature], 'shutdown'));
+ }
+
+ return $shares[$signature];
+ }
+
+}
/**
* Adds a share to the shares system.
*
- * @param string $shareRoot The name of the share root, e.g. the
+ * @param string $scope The name of the share root, e.g. the
* application that the share belongs to.
* @param string $shareName The share's name.
* @param string $shareTitle The share's human readable title.
* @param string $userName The share's owner.
*/
- public function addShare($shareRoot, $shareName, $shareTitle, $userName)
+ public function addShare($scope, $shareName, $shareTitle, $userName)
{
if (!Horde_Auth::isAdmin()) {
return PEAR::raiseError(_("You are not allowed to add shares."));
}
- $shares = Horde_Share::singleton($shareRoot);
+ $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope);
if (is_a($share = &$shares->newShare($shareName), 'PEAR_Error')) {
return $share;
/**
* Removes a share from the shares system permanently.
*
- * @param string $shareRoot The name of the share root, e.g. the
+ * @param string $scope The name of the share root, e.g. the
* application that the share belongs to.
* @param string $shareName The share's name.
*/
- public function removeShare($shareRoot, $shareName)
+ public function removeShare($scope, $shareName)
{
if (!Horde_Auth::isAdmin()) {
return PEAR::raiseError(_("You are not allowed to delete shares."));
}
- $shares = Horde_Share::singleton($shareRoot);
+ $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope);
if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
return $share;
/**
* Returns an array of all shares that $userName is the owner of.
*
- * @param string $shareRoot The name of the share root, e.g. the
+ * @param string $scope The name of the share root, e.g. the
* application that the share belongs to.
* @param string $userName The share's owner.
*
* @return array The list of shares.
*/
- public function listSharesOfOwner($shareRoot, $userName)
+ public function listSharesOfOwner($scope, $userName)
{
if (!Horde_Auth::isAdmin()) {
return PEAR::raiseError(_("You are not allowed to list shares."));
}
- $shares = Horde_Share::singleton($shareRoot);
+ $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope);
$share_list = &$shares->listShares($userName, Horde_Perms::SHOW, $userName);
$myshares = array();
/**
* Gives a user certain privileges for a share.
*
- * @param string $shareRoot The name of the share root, e.g. the
+ * @param string $scope The name of the share root, e.g. the
* application that the share belongs to.
* @param string $shareName The share's name.
* @param string $userName The user's name.
* @param array $permissions A list of permissions (show, read, edit, delete).
*/
- public function addUserPermissions($shareRoot, $shareName, $userName,
+ public function addUserPermissions($scope, $shareName, $userName,
$permissions)
{
if (!Horde_Auth::isAdmin()) {
return PEAR::raiseError(_("You are not allowed to change shares."));
}
- $shares = Horde_Share::singleton($shareRoot);
+ $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope);
if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
return $share;
/**
* Gives a group certain privileges for a share.
*
- * @param string $shareRoot The name of the share root, e.g. the
+ * @param string $scope The name of the share root, e.g. the
* application that the share belongs to.
* @param string $shareName The share's name.
* @param string $groupName The group's name.
* @param array $permissions A list of permissions (show, read, edit, delete).
*/
- public function addGroupPermissions($shareRoot, $shareName, $groupName,
+ public function addGroupPermissions($scope, $shareName, $groupName,
$permissions)
{
if (!Horde_Auth::isAdmin()) {
}
require_once 'Horde/Group.php';
- $shares = Horde_Share::singleton($shareRoot);
+ $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope);
$groups = Group::singleton();
if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
/**
* Removes a user from a share.
*
- * @param string $shareRoot The name of the share root, e.g. the
+ * @param string $scope The name of the share root, e.g. the
* application that the share belongs to.
* @param string $shareName The share's name.
* @param string $userName The user's name.
*/
- public function removeUserPermissions($shareRoot, $shareName, $userName)
+ public function removeUserPermissions($scope, $shareName, $userName)
{
if (!Horde_Auth::isAdmin()) {
return PEAR::raiseError(_("You are not allowed to change shares."));
}
- $shares = Horde_Share::singleton($shareRoot);
+ $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope);
if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
return $share;
/**
* Removes a group from a share.
*
- * @param string $shareRoot The name of the share root, e.g. the
+ * @param string $scope The name of the share root, e.g. the
* application that the share belongs to.
* @param string $shareName The share's name.
* @param string $groupName The group's name.
*/
- public function removeGroupPermissions($shareRoot, $shareName, $groupName)
+ public function removeGroupPermissions($scope, $shareName, $groupName)
{
if (!Horde_Auth::isAdmin()) {
return PEAR::raiseError(_("You are not allowed to change shares."));
}
require_once 'Horde/Group.php';
- $shares = Horde_Share::singleton($shareRoot);
+ $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope);
$groups = Group::singleton();
if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
/**
* Returns an array of all user permissions on a share.
*
- * @param string $shareRoot The name of the share root, e.g. the
+ * @param string $scope The name of the share root, e.g. the
* application that the share belongs to.
* @param string $shareName The share's name.
* @param string $userName The user's name.
*
* @return array All user permissions for this share.
*/
- public function listUserPermissions($shareRoot, $shareName, $userName)
+ public function listUserPermissions($scope, $shareName, $userName)
{
if (!Horde_Auth::isAdmin()) {
return PEAR::raiseError(_("You are not allowed to list share permissions."));
Horde_Perms::EDIT => 'edit',
Horde_Perms::DELETE => 'delete');
- $shares = Horde_Share::singleton($shareRoot);
+ $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope);
if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
return $share;
/**
* Returns an array of all group permissions on a share.
*
- * @param string $shareRoot The name of the share root, e.g. the
+ * @param string $scope The name of the share root, e.g. the
* application that the share belongs to.
* @param string $shareName The share's name.
* @param string $groupName The group's name.
*
* @return array All group permissions for this share.
*/
- public function listGroupPermissions($shareRoot, $shareName, $groupName)
+ public function listGroupPermissions($scope, $shareName, $groupName)
{
if (!Horde_Auth::isAdmin()) {
return PEAR::raiseError(_("You are not allowed to list share permissions."));
Horde_Perms::EDIT => 'edit',
Horde_Perms::DELETE => 'delete');
- $shares = Horde_Share::singleton($shareRoot);
+ $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope);
if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
return $share;
/**
* Returns a list of users which have have certain permissions on a share.
*
- * @param string $shareRoot The name of the share root, e.g. the
+ * @param string $scope The name of the share root, e.g. the
* application that the share belongs to.
* @param string $shareName The share's name.
* @param array $permissions A list of permissions (show, read, edit, delete).
*
* @return array List of users with the specified permissions.
*/
- public function listUsersOfShare($shareRoot, $shareName, $permissions)
+ public function listUsersOfShare($scope, $shareName, $permissions)
{
if (!Horde_Auth::isAdmin()) {
return PEAR::raiseError(_("You are not allowed to list users of shares."));
}
- $shares = Horde_Share::singleton($shareRoot);
+ $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope);
if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
return $share;
/**
* Returns a list of groups which have have certain permissions on a share.
*
- * @param string $shareRoot The name of the share root, e.g. the
+ * @param string $scope The name of the share root, e.g. the
* application that the share belongs to.
* @param string $shareName The share's name.
* @param array $permissions A list of permissions (show, read, edit, delete).
*
* @return array List of groups with the specified permissions.
*/
- public function listGroupsOfShare($shareRoot, $shareName, $permissions)
+ public function listGroupsOfShare($scope, $shareName, $permissions)
{
if (!Horde_Auth::isAdmin()) {
return PEAR::raiseError(_("You are not allowed to list groups of shares."));
}
- $shares = Horde_Share::singleton($shareRoot);
+ $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope);
if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) {
return $share;