aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/avatar/manager.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/avatar/manager.php')
-rw-r--r--phpBB/phpbb/avatar/manager.php76
1 files changed, 37 insertions, 39 deletions
diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php
index c28380a401..6ce924d2eb 100644
--- a/phpBB/phpbb/avatar/manager.php
+++ b/phpBB/phpbb/avatar/manager.php
@@ -10,14 +10,6 @@
namespace phpbb\avatar;
/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
* @package avatar
*/
class manager
@@ -42,12 +34,6 @@ class manager
protected $avatar_drivers;
/**
- * Service container object
- * @var object
- */
- protected $container;
-
- /**
* Default avatar data row
* @var array
*/
@@ -63,13 +49,27 @@ class manager
*
* @param \phpbb\config\config $config phpBB configuration
* @param array $avatar_drivers Avatar drivers passed via the service container
- * @param object $container Container object
*/
- public function __construct(\phpbb\config\config $config, $avatar_drivers, $container)
+ public function __construct(\phpbb\config\config $config, $avatar_drivers)
{
$this->config = $config;
- $this->avatar_drivers = $avatar_drivers;
- $this->container = $container;
+ $this->register_avatar_drivers($avatar_drivers);
+ }
+
+ /**
+ * Register avatar drivers
+ *
+ * @param array $avatar_drivers Service collection of avatar drivers
+ */
+ protected function register_avatar_drivers($avatar_drivers)
+ {
+ if (!empty($avatar_drivers))
+ {
+ foreach ($avatar_drivers as $driver)
+ {
+ $this->avatar_drivers[$driver->get_name()] = $driver;
+ }
+ }
}
/**
@@ -112,7 +112,7 @@ class manager
* There is no need to handle invalid avatar types as the following code
* will cause a ServiceNotFoundException if the type does not exist
*/
- $driver = $this->container->get($avatar_type);
+ $driver = $this->avatar_drivers[$avatar_type];
return $driver;
}
@@ -178,14 +178,16 @@ class manager
}
/**
- * Strip out user_ and group_ prefixes from keys
+ * Strip out user_, group_, or other prefixes from array keys
*
- * @param array $row User data or group data
+ * @param array $row User data or group data
+ * @param string $prefix Prefix of data keys (e.g. user), should not include the trailing underscore
*
- * @return array User data or group data with keys that have been
- * stripped from the preceding "user_" or "group_"
+ * @return array User or group data with keys that have been
+ * stripped from the preceding "user_" or "group_"
+ * Also the group id is prefixed with g, when the prefix group is removed.
*/
- static public function clean_row($row)
+ static public function clean_row($row, $prefix = '')
{
// Upon creation of a user/group $row might be empty
if (empty($row))
@@ -193,23 +195,19 @@ class manager
return self::$default_row;
}
- $keys = array_keys($row);
- $values = array_values($row);
-
- $keys = array_map(array('\phpbb\avatar\manager', 'strip_prefix'), $keys);
+ $output = array();
+ foreach ($row as $key => $value)
+ {
+ $key = preg_replace("#^(?:{$prefix}_)#", '', $key);
+ $output[$key] = $value;
+ }
- return array_combine($keys, $values);
- }
+ if ($prefix === 'group' && isset($output['id']))
+ {
+ $output['id'] = 'g' . $output['id'];
+ }
- /**
- * Strip prepending user_ or group_ prefix from key
- *
- * @param string Array key
- * @return string Key that has been stripped from its prefix
- */
- static protected function strip_prefix($key)
- {
- return preg_replace('#^(?:user_|group_)#', '', $key);
+ return $output;
}
/**