1 <?php
 2 
 3 // component provides some functionality needed in various objects
 4 interface Component
 5 {
 6     public function isFoo(BarInterface $bar, $baz = null);
 7 }
 8 
 9 
10 // component helper is a trait that defines no public methods
11 trait ComponentHelper
12 {
13     // getBar is also required by BarInterface
14     // defining it here doesnt ENSURE the INTERFACE is implemented in parent,
15     // but seems right here?
16     abstract public function getBar();
17 
18     abstract protected function getFoo();
19 
20     protected function isFoo($baz) {
21         return $this->getFoo()->foo($this, $baz);
22     }
23 }
24 
25 // interface required by component
26 interface BarInterface
27 {
28     public function getBar();
29 }
30 
31 // Is this an acceptable use of traits? or am i missing it.
32 class BarImpl implements BarInterface
33 {
34     use ComponentHelper;
35 
36     protected $component;
37 
38     public function __construct(Component $component)
39     {
40         $this->component = $component;
41     }
42 
43     protected function getFoo()
44     {
45         return $this->foo;
46     }
47 
48     public function doBing()
49     {
50         if ($this->isFoo('some-baz')) {
51             // do something;
52         }
53         // do something else
54     }
55 
56     public function getBar()
57     {
58         return 'bar';
59     }
60 }