Giter Club home page Giter Club logo

Comments (8)

burzum avatar burzum commented on June 15, 2024

@jippi since there is such an overwhelming interest from other people here is my implementation.

Please let me know if this will work for you and I'll add it to my branch.

/**
 * Gets all filters in a given collection.
 *
 * @param string $collection Name of the filter collection.
 * @return array Array of filter instances.
 */
    public function getFilters($collection = 'default')
    {
        return $this->_filters[$collection];
    }

/**
 * Sets or gets the filter collection name.
 *
 * @param string $name Name of the active filter collection to set.
 * @return mixed Returns $this or the name of the active collection if no $name was provided.
 */
    public function collection($name = null) {
        if ($name === null) {
            return $this->_collection;
        }
        if (!isset($this->_filters[$name])) {
            $this->_filters[$name] = [];
        }
        $this->_collection = $name;
        return $this;
    }

/**
 * Adds a new filter to the active collection.
 *
 * @param string $name
 * @param string $filter
 * @param array $options
 * @return $this
 */
    public function add($name, $filter, array $options = [])
    {
        $this->_filters[$this->_collection][$name] = $this->_loadFilter($filter, $options);
        return $this;
    }

/**
 * Loads a search filter instance.
 *
 * @param string $name Name of the filter class to load.
 * @param array $options Filter options.
 * @return \Search\Search\Type\Base
 * @throws \InvalidArgumentException When no filter was found.
 */
    public function _loadFilter($name, array $options = [])
    {
        list($plugin, $name) = pluginSplit($name);
        if (!empty($plugin)) {
            $className = '\\' . $plugin . '\Search\Type\\' . $name;
            if (class_exists($className)) {
                return new $className($name, $options, $this);
            }
        }
        if (isset($config['typeClasses'][$name])) {
            return new $config['typeClasses'][$name]($name, $options, $this);
        }
        if (class_exists('\FOC\Search\Search\Type\\' . $name)) {
            $className = '\FOC\Search\Search\Type\\' . $name;
            return new $className($name, $options, $this);
        }
        if (class_exists('\App\Search\Type\\' . $name)) {
            $className = '\App\Search\Type\\' . $name;
            return new $className($name, $options, $this);
        }
        throw new \InvalidArgumentException(sprintf('Can\'t find filter class %s!', $name));
    }

from search.

burzum avatar burzum commented on June 15, 2024

@jippi I've implented this proposal in my fork of the plugin, feel free to take it from there or just close this ticket.

from search.

davidyell avatar davidyell commented on June 15, 2024

Why a trait and not a behaviour? It makes more sense to be that if it's dealing with the table classes it should be a behaviour. Using a trait feels like a hack to me, like it's sidestepping the framework.

from search.

burzum avatar burzum commented on June 15, 2024

@davidyell where do you see a trait?

from search.

davidyell avatar davidyell commented on June 15, 2024

Sorry, I should have tagged Jippi,
@jippi said

in the table class I think a trait that

Oh, but it looks like it's quoting you. So my question was why use a trait to return the manager rather than a behaviour.

from search.

burzum avatar burzum commented on June 15, 2024

@jippi you can close this.

from search.

burzum avatar burzum commented on June 15, 2024

See #46

from search.

ADmad avatar ADmad commented on June 15, 2024

Closing as PR is open.

from search.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.