/**
  * Finds all leaf nodes, in a flat array.
  * Leaf nodes are nodes which do not have
  * any children.
  *
  * @param  int  $tree
  * @return array
  */
 public function allLeaf($tree = null)
 {
     $me = $this;
     // Leaf nodes are nodes with no children, therefore the
     // right limit will be one greater than the left limit.
     return array_filter($this->baseNode->findAll(), function ($node) use($me, $tree) {
         $right = $node->getAttribute($me->getReservedAttributeName('right'));
         $left = $node->getAttribute($me->getReservedAttributeName('left'));
         $size = $right - $left;
         // If we have no tree, simply check the size
         if ($tree === null) {
             return $size == 1;
         }
         // Otherwise, check our tree constraint matches as well.
         return $size == 1 and $node->getAttribute($me->getReservedAttributeName('tree')) == $tree;
     });
 }