/** * Get an array of all defined properties * * @return array */ public function toArray() { $result = ['browser' => $this->browser->toArray(), 'engine' => $this->engine->toArray(), 'os' => $this->os->toArray(), 'device' => $this->device->toArray()]; if (!count($result['browser'])) { unset($result['browser']); } if (!count($result['engine'])) { unset($result['engine']); } if (!count($result['os'])) { unset($result['os']); } if (!count($result['device'])) { unset($result['device']); } if ($this->camouflage) { $result['camouflage'] = true; } return $result; }
public function testToArray() { $device = new Device(); $this->assertEquals([], $device->toArray()); $device->setIdentification(['manufacturer' => 'Sony', 'model' => 'Playstation 4', 'type' => Constants\DeviceType::GAMING, 'subtype' => Constants\DeviceSubType::CONSOLE]); $this->assertEquals(['manufacturer' => 'Sony', 'model' => 'Playstation 4', 'type' => Constants\DeviceType::GAMING, 'subtype' => Constants\DeviceSubType::CONSOLE], $device->toArray()); $device->setIdentification(['manufacturer' => 'NEC', 'model' => 'N2002', 'carrier' => 'DoCoMo', 'type' => Constants\DeviceType::MOBILE, 'subtype' => Constants\DeviceSubType::FEATURE]); $this->assertEquals(['manufacturer' => 'NEC', 'model' => 'N2002', 'carrier' => 'DoCoMo', 'type' => Constants\DeviceType::MOBILE, 'subtype' => Constants\DeviceSubType::FEATURE], $device->toArray()); }
/** * * @param Model\Device $device * @param \WhichBrowser\Model\Device $deviceRaw * @param WhichBrowserParser $parser */ private function hydrateDevice(Model\Device $device, \WhichBrowser\Model\Device $deviceRaw, WhichBrowserParser $parser) { $device->setModel($this->getRealResult($deviceRaw->getModel())); $device->setBrand($this->getRealResult($deviceRaw->getManufacturer())); $device->setType($this->getRealResult($parser->getType())); if ($parser->isMobile() === true) { $device->setIsMobile(true); } }