for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Nextcloud - OCR
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
* @author Janis Koehr <[email protected]>
* @copyright Janis Koehr 2017
*/
namespace OCA\Ocr\Service;
use \OCP\IConfig;
use OCP\IL10N;
class AppConfigService {
* @var string
private $appName = 'ocr';
* @var IConfig
private $config;
* @var IL10N
private $l10n;
* Constructor
* @param IConfig $config
* @param IL10N $l10n
public function __construct(IConfig $config, IL10N $l10n) {
$this->config = $config;
$this->l10n = $l10n;
}
* Get a value by key
* @param string $key
* @return string
public function getAppValue($key) {
return $this->config->getAppValue ( $this->appName, $key );
* Set a value by key
* @param string $value
public function setAppValue($key, $value) {
if ($key === 'languages') {
if (! preg_match ( '/^(([a-z]{3,4}|[a-z]{3,4}\-[a-z]{3,4});)*([a-z]{3,4}|[a-z]{3,4}\-[a-z]{3,4})$/', $value )) {
throw new NotFoundException ( $this->l10n->t ( 'The languages are not specified in the correct format.' ) );
return $this->config->setAppValue ( $this->appName, $key, $value );