Xhgui_Profile::getWatched PHP Method

getWatched() public method

Find a function matching a watched function.
public getWatched ( string $pattern ) : null | array
$pattern string The pattern to look for.
return null | array An list of matching functions or null.
    public function getWatched($pattern)
    {
        if (isset($this->_collapsed[$pattern])) {
            $data = $this->_collapsed[$pattern];
            $data['function'] = $pattern;
            return array($data);
        }
        $matches = array();
        $keys = array_keys($this->_collapsed);
        foreach ($keys as $func) {
            if (preg_match('`^' . $pattern . '$`', $func)) {
                $data = $this->_collapsed[$func];
                $data['function'] = $func;
                $matches[] = $data;
            }
        }
        return $matches;
    }

Usage Example

Example #1
0
 public function testGetWatched()
 {
     $fixture = $this->_fixture[0];
     $profile = new Xhgui_Profile($fixture);
     $data = $profile->getProfile();
     $this->assertEmpty($profile->getWatched('not there'));
     $matches = $profile->getWatched('strpos.*');
     $this->assertCount(1, $matches);
     $this->assertEquals('strpos()', $matches[0]['function']);
     $this->assertEquals($data['strpos()']['wt'], $matches[0]['wt']);
     $matches = $profile->getWatched('str.*');
     $this->assertCount(1, $matches);
     $this->assertEquals('strpos()', $matches[0]['function']);
     $this->assertEquals($data['strpos()']['wt'], $matches[0]['wt']);
     $matches = $profile->getWatched('[ms].*');
     $this->assertCount(2, $matches);
     $this->assertEquals('strpos()', $matches[0]['function']);
     $this->assertEquals($data['strpos()']['wt'], $matches[0]['wt']);
     $this->assertEquals('main()', $matches[1]['function']);
     $this->assertEquals($data['main()']['wt'], $matches[1]['wt']);
 }