Plop
A simple logging library for PHP
Name.php
1 <?php
2 /*
3  This file is part of Plop, a simple logging library for PHP.
4 
5  Copyright © 2010-2014 François Poirotte
6 
7  Plop is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Plop is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Plop. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 namespace Plop\Filter;
22 
28 class Name implements \Plop\FilterInterface
29 {
31  protected $name;
32 
34  protected $nlen;
35 
45  public function __construct($name = '')
46  {
47  $this->name = $name;
48  $this->nlen = strlen($name);
49  }
50 
52  public function filter(\Plop\RecordInterface $record)
53  {
54  if (!$this->nlen) {
55  return true;
56  }
57 
58  list(, , $name) = explode($record['name'], 3);
59  if (strncmp($name, $this->name, $this->nlen)) {
60  return false;
61  }
62 
63  return (
64  strlen($name) == $this->nlen ||
65  $name[$this->nlen] == DIRECTORY_SEPARATOR
66  );
67  }
68 }
Interface for a log record.
$nlen
Length of the identifier.
Definition: Name.php:34
filter(\Plop\RecordInterface $record)
Definition: Name.php:52
$name
Identifier of the logger whose records will be handled.
Definition: Name.php:31
A filter that only accepts records from a specific logger.
Definition: Name.php:28
Interface for a filter.
__construct($name= '')
Definition: Name.php:45