public function testToArray() { $browser = new Browser(); $this->assertEquals([], $browser->toArray()); $browser->set(['name' => '']); $this->assertEquals([], $browser->toArray()); $browser->reset(['name' => 'Chrome', 'version' => new Version(['value' => '47.0.2526.73', 'details' => 1])]); $this->assertEquals(['name' => 'Chrome', 'version' => '47'], $browser->toArray()); $browser->reset(['name' => 'Opera', 'family' => new Family(['name' => 'Chrome'])]); $this->assertEquals(['name' => 'Opera', 'family' => 'Chrome'], $browser->toArray()); $browser->reset(['name' => 'TestBrowser', 'using' => new Using(['name' => 'Crosswalk WebView'])]); $this->assertEquals(['name' => 'TestBrowser', 'using' => 'Crosswalk WebView'], $browser->toArray()); }
/** * * @param Model\Browser $browser * @param \WhichBrowser\Model\Browser $browserRaw */ private function hydrateBrowser(Model\Browser $browser, \WhichBrowser\Model\Browser $browserRaw) { if ($this->isRealResult($browserRaw->getName(), 'browser', 'name') === true) { $browser->setName($browserRaw->getName()); $browser->getVersion()->setComplete($this->getRealResult($browserRaw->getVersion())); return; } if (isset($browserRaw->using) && $browserRaw->using instanceof \WhichBrowser\Model\Using) { /* @var $usingRaw \WhichBrowser\Model\Using */ $usingRaw = $browserRaw->using; if ($this->isRealResult($usingRaw->getName()) === true) { $browser->setName($usingRaw->getName()); $browser->getVersion()->setComplete($this->getRealResult($usingRaw->getVersion())); } } }
/** * 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; }