<?php namespace Eae\Backoffice\Generic;

use Illuminate\Support\Collection;
use DirectoryIterator;
use Eae\Exception\InvalidConfigurationException;

class ContentTypeCollection extends Collection{
 
    public function find($type){
        $contentType = $this->filter(function(ContentType $contentTypeItem) use($type){
            return ($contentTypeItem->getType() == $type);
        })->first();
        
        if(empty($contentType)){
            if(empty($config) || !is_array($config)){
                throw new InvalidConfigurationException("The content type {$type} doesn't exists");    
            }    
        }
        
        return $contentType;        
    }  
}