Skip to content
Open
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
56 changes: 56 additions & 0 deletions admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

abstract class Device
{

public $id;

public function __construct(int $id, string $brand, string $model, string $serialNumber)
{
$this->id = $id;
$this->brand = $brand;
$this->model = $model;
$this->serialNumber = $serialNumber;
}


public $brand;
public $model;
public $serialNumber;
public function getId()
{
return $this->model;
}

public function getSerialNumber()
{
return $this->serialNumber;
}

public function getDetail($device)
{
return $device->id;
}
}

class Mobile extends Device
{

public $capacity;
public $price;

public function __construct(string $id, string $brand, string $model, string $serialNumber, string $capacity, string $price)
{
$this->capacity = $capacity;
$this->price = $price;
parent::__construct($id, $brand, $model, $serialNumber);
}

public function getDetail($device)
{
return Device::getDetail($device);
}
}

$mobile = new Mobile(5, 'Samsung', 'S20', 123456, '120GB', 1200);
var_dump($mobile->getDetail($mobile));
75 changes: 75 additions & 0 deletions devices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
class Device
{

public $brand;
public $model;
public $serialNumber;

public function __construct(string $brand, string $model, string $serialNumber)
{
$this->brand = $brand;
$this->model = $model;
$this->serialNumber = $serialNumber;
}

public function getSerialNumber()
{
return $this->serialNumber;
}
}

class DeviceManager
{
public $serialNumber;

public function __construct(Device $device)
{
$this->serialNumber = $this->getDeviceSerialNumber($device);
}

public function getDeviceSerialNumber(Device $device)
{
return $device->getSerialNumber();
}
}

class Mobile extends Device
{
public $capacity;
public $price;


public function __construct(string $brand, string $model, string $serialNumber, string $capacity, string $price)
{
$this->capacity = $capacity;
$this->price = $price;
parent::__construct($brand, $model, $serialNumber);
}

public function getMobileData()
{
return "<pre> $this->brand <pre> $this->model <pre> $this->serialNumber <pre/> $this->capacity <pre/>";
}
}

class Tablet extends Device
{

public function __construct(string $brand, string $model, string $serialNumber, string $capacity, string $price)
{

parent::__construct($brand, $model, $serialNumber, $capacity, $price);
}
}

$mobile = new Mobile('iphone', '14S', '5678HP', '560GB', '1800');
$tablet = new Tablet('IPad', 'ProMax', 'IP45236', '500GB', '2300');
$device = new DeviceManager($mobile);


echo ($device->getDeviceSerialNumber($mobile));
echo "<pre>";
echo ($device->getDeviceSerialNumber($tablet));
echo "</pre>";
echo $mobile->getMobileData();
68 changes: 68 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

interface DeviceRepository
{
public function createDevice(Device $device);
public function findId($deviceId, $array);
}

class Device
{

public $id;
public $brand;
public $model;
public $serialNumber;
public function __construct(string $id, string $brand, string $model, string $serialNumber)
{
$this->id = $id;
$this->brand = $brand;
$this->model = $model;
$this->serialNumber = $serialNumber;
}
}

class MemoryRepository implements DeviceRepository
{
public $devices = array();

public function createDevice(Device $device)
{
$this->devices[] = $device;
}
public function findId($deviceId, $array)
{
if (in_array($deviceId, $array)) {
return $deviceId;
}
}
}


class DeviceManager extends MemoryRepository
{
public $repository;
public $device;
function __construct(MemoryRepository $repository, Device $device)
{
$this->repository = $repository;
$this->device = $device;
}

function addDevice($repository, $device)
{
$repository->createDevice($device);
return $repository;
}
}

$device1 = new Device(1, 'Samsung', 'S20', 'SG3454');
$device2 = new Device(2, 'iPhone', 'X', 'IP7849');
$device3 = new Device(3, 'Xiamoi', 'MI30', 'XM0948');

$memory = new MemoryRepository();
$addDevice = new DeviceManager($memory, $device2);
$addDevice->addDevice($memory, $device1);
$addDevice->addDevice($memory, $device2);

var_dump($memory);