diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-08-29 16:44:08 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-08-29 16:44:08 +0200 |
commit | 723f8c8f1ba8c9859ec2d46515dc06e7236f89c0 (patch) | |
tree | 5cff022dc72e1a8511545888e489efef6dd21344 | |
parent | faa62d17993b9467f0041cbca2cafccdcb243385 (diff) | |
parent | 37b00b7443bec09aac84b359a1c2f77caf143b30 (diff) | |
download | nextcloud-server-723f8c8f1ba8c9859ec2d46515dc06e7236f89c0.tar.gz nextcloud-server-723f8c8f1ba8c9859ec2d46515dc06e7236f89c0.zip |
Merge pull request #18620 from owncloud/add-public-interface-for-factory
Add a public interface for the language factory so apps can use it
-rw-r--r-- | lib/private/l10n.php | 9 | ||||
-rw-r--r-- | lib/private/l10n/factory.php | 24 | ||||
-rw-r--r-- | lib/private/server.php | 9 | ||||
-rw-r--r-- | lib/public/il10n.php | 2 | ||||
-rw-r--r-- | lib/public/l10n/ifactory.php | 36 | ||||
-rw-r--r-- | tests/lib/server.php | 1 |
6 files changed, 64 insertions, 17 deletions
diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 17acaac1692..168011cfcec 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -81,14 +81,11 @@ class OC_L10N implements \OCP\IL10N { * get an L10N instance * @param string $app * @param string|null $lang - * @return \OC_L10N + * @return \OCP\IL10N + * @deprecated Use \OC::$server->getL10NFactory()->get() instead */ public static function get($app, $lang=null) { - if (is_null($lang)) { - return OC::$server->getL10N($app); - } else { - return new \OC_L10N($app, $lang); - } + return \OC::$server->getL10NFactory()->get($app, $lang); } /** diff --git a/lib/private/l10n/factory.php b/lib/private/l10n/factory.php index 4424d014f47..a9ac4da42a2 100644 --- a/lib/private/l10n/factory.php +++ b/lib/private/l10n/factory.php @@ -25,29 +25,35 @@ namespace OC\L10N; +use OCP\L10N\IFactory; + /** - * TODO: Description + * A factory that generates language instances */ -class Factory { +class Factory implements IFactory { /** * cached instances */ protected $instances = array(); /** - * get an L10N instance + * Get a language instance * * @param string $app * @param string|null $lang - * @return \OC_L10N + * @return \OCP\IL10N */ public function get($app, $lang = null) { - if (!is_null($lang)) { - return new \OC_L10N($app, $lang); - } else if (!isset($this->instances[$app])) { - $this->instances[$app] = new \OC_L10N($app); + $key = $lang; + if ($key === null) { + $key = 'null'; + } + + if (!isset($this->instances[$key][$app])) { + $this->instances[$key][$app] = new \OC_L10N($app, $lang); } - return $this->instances[$app]; + + return $this->instances[$key][$app]; } } diff --git a/lib/private/server.php b/lib/private/server.php index 287b70eb806..a47fa2e43f9 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -674,6 +674,13 @@ class Server extends SimpleContainer implements IServerContainer { } /** + * @return \OCP\L10N\IFactory + */ + public function getL10NFactory() { + return $this->query('L10NFactory'); + } + + /** * get an L10N instance * * @param string $app appid @@ -681,7 +688,7 @@ class Server extends SimpleContainer implements IServerContainer { * @return \OC_L10N */ public function getL10N($app, $lang = null) { - return $this->query('L10NFactory')->get($app, $lang); + return $this->getL10NFactory()->get($app, $lang); } /** diff --git a/lib/public/il10n.php b/lib/public/il10n.php index e1d0102105b..c6e076a21f8 100644 --- a/lib/public/il10n.php +++ b/lib/public/il10n.php @@ -100,7 +100,7 @@ interface IL10N { /** - * The code (en, de, ...) of the language that is used for this OC_L10N object + * The code (en, de, ...) of the language that is used for this IL10N object * * @return string language * @since 7.0.0 diff --git a/lib/public/l10n/ifactory.php b/lib/public/l10n/ifactory.php new file mode 100644 index 00000000000..b784505a68b --- /dev/null +++ b/lib/public/l10n/ifactory.php @@ -0,0 +1,36 @@ +<?php +/** + * @author Joas Schilling <nickvergessen@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCP\L10N; + +/** + * @since 8.2.0 + */ +interface IFactory { + /** + * Get a language instance + * + * @param string $app + * @param string|null $lang + * @return \OCP\IL10N + * @since 8.2.0 + */ + public function get($app, $lang = null); +} diff --git a/tests/lib/server.php b/tests/lib/server.php index bc44c50a22a..e73fc8b3ab1 100644 --- a/tests/lib/server.php +++ b/tests/lib/server.php @@ -90,6 +90,7 @@ class Server extends \Test\TestCase { ['JobList', '\OCP\BackgroundJob\IJobList'], ['L10NFactory', '\OC\L10N\Factory'], + ['L10NFactory', '\OCP\L10N\IFactory'], ['LockingProvider', '\OCP\Lock\ILockingProvider'], ['Logger', '\OC\Log'], ['Logger', '\OCP\ILogger'], |