Skip to content

Commit

Permalink
fixup! Refactoring to use dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltan committed Feb 4, 2019
1 parent 479a4b1 commit d785b00
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ composer update colourbox-account/i18n
$api = new CBX\API("https://test-tb.cbx.xyz");
$config = new CBX\Config("en_GB", "i18n-develop-test");
$collections = new CBX\Collections($config);
$i18n = new i18nClass($collections);
$i18n = new CBX\I18nClass($collections);
```

### Create instance with factory

```php
$i18n = CBX\i18n::create("en_GB", "i18n-develop-test", "https://test-tb.cbx.xyz");
$i18n = CBX\I18nFactory::create("en_GB", "i18n-develop-test", "https://test-tb.cbx.xyz");
```

### Getting simple translation
Expand Down
2 changes: 1 addition & 1 deletion src/CBX/i18nClass.php → src/CBX/I18nClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace CBX;

class i18nClass
class I18nClass
{
private $collections;

Expand Down
6 changes: 3 additions & 3 deletions src/CBX/i18n.php → src/CBX/I18nFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace CBX;

class i18n
class I18nFactory
{
public static function create($language, $domain, $apiUrl) {
return new i18nClass(new Collections(new Config($language, $domain, new API($apiUrl))));
return new I18nClass(new Collections(new Config($language, $domain, new API($apiUrl))));
}

public static function createOffline($language, $domain, $jsonDir) {
return new i18nClass(new Collections(new Config($language, $domain, new APIOffline($jsonDir))));
return new I18nClass(new Collections(new Config($language, $domain, new APIOffline($jsonDir))));
}
}
16 changes: 8 additions & 8 deletions test/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
require_once __DIR__ . '/../src/'.str_replace('\\', '/', $class_name).'.php';
});

CBX\i18n::initialize("en_GB", "i18n-develop-example", "https://tb.colourbox.com");
$i18n = CBX\I18nFactory::create("en_GB", "i18n-develop-example", "https://tb.colourbox.com");

$output = [
"API Host: ".CBX\i18n::getAPIURL(),
"Language: ".CBX\i18n::getLanguage(),
"Domain: ".CBX\i18n::getDomain(),
"API Host: ".$i18n->getAPIURL(),
"Language: ".$i18n->getLanguage(),
"Domain: ".$i18n->getDomain(),
"\n",
"companyAddress: ".CBX\i18n::_('companyAddress'),
"html escaped: ".CBX\i18n::_htmlEscaped('htmlText'),
'placeholder: '.CBX\i18n::_('addNumber', [ 'nr1' => 1, 'nr2' => 2, 'nr3' => 3 ]),
"notExistingIndex: ".CBX\i18n::_('notExistingIndex'),
"companyAddress: ".$i18n->_('companyAddress'),
"html escaped: ".$i18n->_htmlEscaped('htmlText'),
'placeholder: '.$i18n->_('addNumber', [ 'nr1' => 1, 'nr2' => 2, 'nr3' => 3 ]),
"notExistingIndex: ".$i18n->_('notExistingIndex'),
"\n",
];

Expand Down
6 changes: 3 additions & 3 deletions test/offline-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function testCanInstantiateCollectionsObject(): void {

public function testCanInstantiateMainObject(): void {
global $api, $config, $collections, $i18n;
$i18n = new CBX\i18nClass($collections);
$i18n = new CBX\I18nClass($collections);
$this->assertInstanceOf(
CBX\i18nClass::class,
CBX\I18nClass::class,
$i18n
);
}
Expand Down Expand Up @@ -82,7 +82,7 @@ public function testCanHandleIfTranslationMissing(): void {

public function testCanCreateObjectWithFactory(): void {
global $i18nFromFactory;
$i18nFromFactory = CBX\i18n::create(LANGUAGE, DOMAIN, APIURL);
$i18nFromFactory = CBX\I18nFactory::create(LANGUAGE, DOMAIN, APIURL);
$this->assertEquals(
APIURL,
$i18nFromFactory->getAPIURL()
Expand Down
6 changes: 3 additions & 3 deletions test/online-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function testCanInstantiateCollectionsObject(): void {

public function testCanInstantiateMainObject(): void {
global $api, $config, $collections, $i18n;
$i18n = new CBX\i18nClass($collections);
$i18n = new CBX\I18nClass($collections);
$this->assertInstanceOf(
CBX\i18nClass::class,
CBX\I18nClass::class,
$i18n
);
}
Expand Down Expand Up @@ -82,7 +82,7 @@ public function testCanHandleIfTranslationMissing(): void {

public function testCanCreateObjectWithFactory(): void {
global $i18nFromFactory;
$i18nFromFactory = CBX\i18n::create(LANGUAGE, DOMAIN, APIURL);
$i18nFromFactory = CBX\I18nFactory::create(LANGUAGE, DOMAIN, APIURL);
$this->assertEquals(
APIURL,
$i18nFromFactory->getAPIURL()
Expand Down

0 comments on commit d785b00

Please sign in to comment.