PHP code example of mittax / objectcollection
1. Go to this page and download the library: Download mittax/objectcollection library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mittax / objectcollection example snippets
composer
/**
* Created by PhpStorm.
* User: pboethig
* Date: 14.12.16
* Time: 20:10
*/
namespace Mittax\MediaConverterBundle\Collection;
use Mittax\ObjectCollection\CollectionAbstract;
/**
* Class StorageItem
* @package Mittax\MediaConverterBundle\Collection
*/
class StorageItem extends CollectionAbstract
{
/**
* StorageItem constructor.
* @param \Mittax\MediaConverterBundle\Entity\Storage\StorageItem[] $items
*/
public function __construct(Array $items)
{
parent::__construct();
foreach ($items as $item)
{
$this->add($item);
}
}
/**
* @param $filename
* @return \Mittax\MediaConverterBundle\Entity\Storage\StorageItem[]
*/
public function filterByFilename( string $filename) : Array
{
return $this->filterByPropertyNameAndValue('filename', $filename);
}
/**
* @return \Mittax\MediaConverterBundle\Entity\Storage\StorageItem
*/
public function getFirstItem() : \Mittax\MediaConverterBundle\Entity\Storage\StorageItem
{
return parent::getFirstItem();
}
/**
* @return \Mittax\MediaConverterBundle\Entity\Storage\StorageItem[]
*/
public function getAllItems() : Array
{
return parent::getAllItems();
}
}
$items = [$fileStorageItem, $fileStorageItem1, $fileStorageItem1];
$collection = new Collection\StorageItem($items);
$collection->filter($fileStorageItem->getFilename());