diff --git a/01-classes.php b/Example/01-classes.php similarity index 100% rename from 01-classes.php rename to Example/01-classes.php diff --git a/02-properties.php b/Example/02-properties.php similarity index 100% rename from 02-properties.php rename to Example/02-properties.php diff --git a/03-methods.php b/Example/03-methods.php similarity index 100% rename from 03-methods.php rename to Example/03-methods.php diff --git a/04-getters.php b/Example/04-getters.php similarity index 100% rename from 04-getters.php rename to Example/04-getters.php diff --git a/05-setters.php b/Example/05-setters.php similarity index 100% rename from 05-setters.php rename to Example/05-setters.php diff --git a/06-constructors.php b/Example/06-constructors.php similarity index 100% rename from 06-constructors.php rename to Example/06-constructors.php diff --git a/07-inheritance-problem.php b/Example/07-inheritance-problem.php similarity index 100% rename from 07-inheritance-problem.php rename to Example/07-inheritance-problem.php diff --git a/08-inheritance-solution.php b/Example/08-inheritance-solution.php similarity index 100% rename from 08-inheritance-solution.php rename to Example/08-inheritance-solution.php diff --git a/09-public-private-protected.php b/Example/09-public-private-protected.php similarity index 100% rename from 09-public-private-protected.php rename to Example/09-public-private-protected.php diff --git a/10-static.php b/Example/10-static.php similarity index 100% rename from 10-static.php rename to Example/10-static.php diff --git a/11-const.php b/Example/11-const.php similarity index 100% rename from 11-const.php rename to Example/11-const.php diff --git a/12-abstract-classes.php b/Example/12-abstract-classes.php similarity index 100% rename from 12-abstract-classes.php rename to Example/12-abstract-classes.php diff --git a/13-interfaces.php b/Example/13-interfaces.php similarity index 100% rename from 13-interfaces.php rename to Example/13-interfaces.php diff --git a/14-overriding.php b/Example/14-overriding.php similarity index 100% rename from 14-overriding.php rename to Example/14-overriding.php diff --git a/15-overloading.php b/Example/15-overloading.php similarity index 100% rename from 15-overloading.php rename to Example/15-overloading.php diff --git a/16-namespaces.php b/Example/16-namespaces.php similarity index 100% rename from 16-namespaces.php rename to Example/16-namespaces.php diff --git a/assets/img/xampp-app.png b/Example/assets/img/xampp-app.png similarity index 100% rename from assets/img/xampp-app.png rename to Example/assets/img/xampp-app.png diff --git a/assets/img/xampp-download.png b/Example/assets/img/xampp-download.png similarity index 100% rename from assets/img/xampp-download.png rename to Example/assets/img/xampp-download.png diff --git a/assets/img/xampp-homepage.png b/Example/assets/img/xampp-homepage.png similarity index 100% rename from assets/img/xampp-homepage.png rename to Example/assets/img/xampp-homepage.png diff --git a/mobileLibs.php b/Example/mobileLibs.php similarity index 100% rename from mobileLibs.php rename to Example/mobileLibs.php diff --git a/admin.php b/admin.php new file mode 100644 index 0000000..57a2248 --- /dev/null +++ b/admin.php @@ -0,0 +1,56 @@ +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)); diff --git a/devices.php b/devices.php new file mode 100644 index 0000000..0c8d095 --- /dev/null +++ b/devices.php @@ -0,0 +1,75 @@ +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 "
 $this->brand 
 $this->model 
 $this->serialNumber 
 $this->capacity 
";
+    }
+}
+
+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 "
";
+echo ($device->getDeviceSerialNumber($tablet));
+echo "
"; +echo $mobile->getMobileData(); diff --git a/index.php b/index.php new file mode 100644 index 0000000..42f60f4 --- /dev/null +++ b/index.php @@ -0,0 +1,68 @@ +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);