Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Api/Skill.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ public function getById(int $id): Entity
throw new \Exception('Did not get proper response for skill.', 1600694312);
}

return Entity::createFromJson((string) $result->getBody());
return Entity::createFromJson((string) $result->getBody(), $this->settings);
}
}
2 changes: 1 addition & 1 deletion src/Api/SkillSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ public function getById(int $id): Entity
throw new \Exception('Did not get proper response for SkillSet. SkillSet with id "' . $id . '" does probably not exist.', 1600694312);
}

return Entity::createFromJson($body);
return Entity::createFromJson($body, $this->settings);
}
}
86 changes: 86 additions & 0 deletions src/Entity/Brand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

namespace SkillDisplay\PHPToolKit\Entity;

/*
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/

use SkillDisplay\PHPToolKit\Configuration\Settings;

class Brand
{
/**
* @var array
*/
private $data;

/**
* @var Settings
*/
private $settings;

private function __construct(array $data, Settings $settings)
{
$this->data = $data;
$this->settings = $settings;
}

public function getId(): int
{
return $this->data['uid'];
}

public function getName(): string
{
return $this->data['name'] ?? '';
}

public function getUrl(): string
{
return $this->data['url'] ?? '';
}

public function getLogoPublicUrl(): string
{
$mediaUrl = $this->data['logoPublicUrl'] ?? '';
if ($mediaUrl === '') {
return '';
}

return $this->settings->getMySkillDisplayUrl() . '/' . $mediaUrl;
}

// In order to support frameworks / APIs that expect "getter".
public function getAsArray(): array
{
return $this->toArray();
}

public function toArray(): array
{
return $this->data;
}

public static function createFromJson(string $json, Settings $settings): Brand
{
return new Brand(json_decode($json, true), $settings);
}
}
41 changes: 38 additions & 3 deletions src/Entity/Skill.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,29 @@
* 02110-1301, USA.
*/

use SkillDisplay\PHPToolKit\Configuration\Settings;

class Skill
{
/**
* @var array
*/
private $data;

private function __construct(array $data)
/**
* @var Settings
*/
private $settings;

/**
* @var array
*/
private $brands = [];

private function __construct(array $data, Settings $settings)
{
$this->data = $data;
$this->settings = $settings;
}

public function getId(): int
Expand All @@ -55,13 +68,35 @@ public function getGoals(): string
return $this->data['goals'] ?? '';
}

/**
* @return Brand[]
*/
public function getBrands(): array
{
if ($this->brands !== []) {
return $this->brands;
}

foreach ($this->data['brands'] as $brand) {
$this->brands[] = Brand::createFromJson(json_encode($brand), $this->settings);
}

return $this->brands;
}

// In order to support frameworks / APIs that expect "getter".
public function getAsArray(): array
{
return $this->toArray();
}

public function toArray(): array
{
return $this->data;
}

public static function createFromJson(string $json): Skill
public static function createFromJson(string $json, Settings $settings): Skill
{
return new Skill(json_decode($json, true));
return new Skill(json_decode($json, true), $settings);
}
}
48 changes: 44 additions & 4 deletions src/Entity/SkillSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,34 @@
* 02110-1301, USA.
*/

use SkillDisplay\PHPToolKit\Configuration\Settings;

class SkillSet
{
/**
* @var array
*/
private $data;

/**
* @var Settings
*/
private $settings;

/**
* @var array
*/
private $skills = [];

private function __construct(array $data)
/**
* @var Brand|null
*/
private $brand = null;

private function __construct(array $data, Settings $settings)
{
$this->data = $data;
$this->settings = $settings;
}

public function getId(): int
Expand All @@ -55,6 +68,27 @@ public function getDescription(): string
return $this->data['description'] ?? '';
}

public function getBrand(): Brand
{
if ($this->brand instanceof Brand) {
return $this->brand;
}

$this->brand = Brand::createFromJson(json_encode($this->data['brand']), $this->settings);

return $this->brand;
}

public function getMediaPublicUrl(): string
{
$mediaUrl = $this->data['mediaPublicUrl'] ?? '';
if ($mediaUrl === '') {
return '';
}

return $this->settings->getMySkillDisplayUrl() . '/' . $mediaUrl;
}

/**
* @return Skill[]
*/
Expand All @@ -65,19 +99,25 @@ public function getSkills(): array
}

foreach ($this->data['skills'] as $skill) {
$this->skills[] = Skill::createFromJson(json_encode($skill));
$this->skills[] = Skill::createFromJson(json_encode($skill), $this->settings);
}

return $this->skills;
}

// In order to support frameworks / APIs that expect "getter".
public function getAsArray(): array
{
return $this->toArray();
}

public function toArray(): array
{
return $this->data;
}

public static function createFromJson(string $json): SkillSet
public static function createFromJson(string $json, Settings $settings): SkillSet
{
return new SkillSet(json_decode($json, true));
return new SkillSet(json_decode($json, true), $settings);
}
}
Loading