2017 © Pedro Peláez
 

library symfony-finder-factory

Symfony Finder Factory

image

dflydev/symfony-finder-factory

Symfony Finder Factory

  • Friday, November 9, 2012
  • by simensen
  • Repository
  • 1 Watchers
  • 6 Stars
  • 39,976 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 2 Versions
  • 4 % Grown

The README.md

Symfony Finder Factory

A factory for Symfony Finder (symfony/finder) Finder instances., (*1)

The idea being able to inject a factory to create Finder instances into services rather than calling new Finder in each service., (*2)

Requirements

  • PHP 5.3+
  • Symfony Finder ~2.0

Installation

Through Composer as dflydev/symfony-finder-factory, (*3)

Usage

<?php
namespace My;

use Dflydev\Symfony\FinderFactory;
use Dflydev\Symfony\FinderFactoryInterface;

class Service
{
    public function __construct(FinderFactoryInterface $finderFactory = null)
    {
        $this->finderFactory = $finderFactory ?: new FinderFactory;
    }

    public function doThingsWithTempFiles()
    {
        $finder = $this->finderFactory->create();

        $finder->in(sys_get_temp_dir());

        // do stuff with temp files
    }
}

Use Case

Mocking Finder has proven to be extremely difficult if new Finder is called inside of a class. By injecting a mocked Finder Factory we can have the opportunity to get mocked Finder instances inside our classes for the purpose of testing., (*4)

This is best shown by example:, (*5)

<?php
namespace My;

use Dflydev\Symfony\FinderFactory;
use Dflydev\Symfony\FinderFactoryInterface;
use Symfony\Component\Finder\Finder;

class Service
{
    public function __construct(FinderFactoryInterface $finderFactory = null)
    {
        $this->finderFactory = $finderFactory ?: new FinderFactory;
    }

    public function findTmpFilesNew()
    {
        // Potential for mocked injected Finder Factory to return
        // a mocked Finder instance.
        $finder = $this->finderFactory->create();

        return $finder->in(sys_get_temp_dir());
    }

    public function findTmpFilesOld()
    {
        // Difficult to Mock
        $finder = new Finder;

        return $finder->in(sys_get_temp_dir());
    }
}

License

MIT, see LICENSE., (*6)

Community

If you have questions or want to help out, join us in the #dflydev channel on irc.freenode.net., (*7)

Not Invented Here

This project is based on work previously submitted to Symfony core ([symfony/symfony#5650][4]) but rejected., (*8)

The Versions

09/11 2012

dev-master

9999999-dev

Symfony Finder Factory

  Sources   Download

MIT

The Requires

 

factory finder syfony

09/11 2012

v1.0.0

1.0.0.0

Symfony Finder Factory

  Sources   Download

MIT

The Requires

 

factory finder syfony