2017 © Pedro Peláez
 

library feed-source

This package contains models to supply feed data.

image

widefocus/feed-source

This package contains models to supply feed data.

  • Thursday, April 27, 2017
  • by sjokki
  • Repository
  • 1 Watchers
  • 0 Stars
  • 30 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

WideFocus Feed Source

Build Status Latest Stable Version License, (*1)

This package contains models to use a feed source., (*2)

Identity source

An identity source provides identities. This would most likely be a list of primary keys from a database., (*3)

<?php
use WideFocus\Feed\Source\IdentitySourceInterface;

/** @var IdentitySourceInterface $idSource */
$idSource  = new CustomIdSource();
$entityIds = $idSource->getEntityIds();

Value source

A value source provides the values for identities. The values are fetched for a single attribute., (*4)

<?php
use WideFocus\Feed\Source\ValueSourceInterface;

/** @var ValueSourceInterface $valueSource */
$valueSource = new CustomValueSource();
$names       = $valueSource->getEntityValues($entityIds, 'name');

Source conditions

Identities can be filtered by conditions. A condition decides based on the identity whether an item should be used in a feed. It collects the item data by itself, for example using a value source., (*5)

<?php
use WideFocus\Feed\Source\Condition\SourceConditionInterface;

/** @var SourceConditionInterface $condition */
$condition = new CustomCondition();
$condition->prepare($entityIds);
foreach ($entityIds as $entityId) {
    if ($condition->matches($entityId)) {
        // The entity is validated.
    }
}

Use SourceConditionCombination to create a combination of conditions., (*6)

Source fields

A source field provides a feed item with data. It always gets the data of just one attribute. It is able to get the data by itself, for example using a value source., (*7)

<?php
use WideFocus\Feed\Source\Field\SourceFieldInterface;

/** @var SourceFieldInterface $field */
$field = new CustomField();
$field->prepare($entityIds);

foreach ($entityIds as $entityId) {
    $item = new ArrayObject();
    $item->offsetSet(
        'name',
        $field->getValue($entityId)
    );
    // The name has been set on the item.
}

Use SourceFieldCombinationInterface to create a combination of fields., (*8)

Source iterators

This package provides a number of iterators that apply conditions and fields on a source., (*9)

Identity source iterator

The identity source iterator iterates over the values of an identity source., (*10)

<?php
use WideFocus\Feed\Source\Iterator\IdentitySourceIterator;

$identityIterator = new IdentitySourceIterator($idSource);
foreach ($identityIterator as $identity) {
    // An identity.
}

Validated identity iterator

The validated identity iterator validates identities according to conditions while iterating over them. It only returns the identities which comply to the conditions., (*11)

<?php
use WideFocus\Feed\Source\Condition\SourceConditionInterface;
use WideFocus\Feed\Source\Iterator\ValidatedIdentityIterator;

/** @var SourceConditionInterface $conditions */
$condition = new CustomCondition();

$validatedIterator = new ValidatedIdentityIterator(
    $identityIterator,
    $condition,
    500
);

foreach ($validatedIterator as $identity) {
    // A validated identity.
}

Identity to item iterator

The identity to item iterator iterates converts identities to items with values while iterating over them. The returned items are instances of ArrayAccess., (*12)

<?php
use WideFocus\Feed\Source\Field\SourceFieldCombinationInterface;
use WideFocus\Feed\Source\Field\SourceFieldCombination;
use WideFocus\Feed\Source\Iterator\IdentityToItemIterator;

/** @var SourceFieldCombinationInterface $fields */
$fields = new SourceFieldCombination([]);

$idToItemIterator = new IdentityToItemIterator(
    $identityIterator,
    $fields,
    500
);

foreach ($idToItemIterator as $item) {
    // An item with values.
}

Combined iterator

A combined iterator can be created with the source iterator factory. It returns an iterator that gets values from an identity source, validates them and converts them to items with values., (*13)

<?php
use WideFocus\Feed\Source\IdentitySourceInterface;
use WideFocus\Feed\Source\Condition\SourceConditionCombinationInterface;
use WideFocus\Feed\Source\Field\SourceFieldCombinationInterface;
use WideFocus\Feed\Source\Iterator\SourceIteratorFactory;

/** @var IdentitySourceInterface $idSource */
$idSource = new CustomSource();

/** @var SourceConditionCombinationInterface $conditions */
$conditions = new CustomConditionCombination();

/** @var SourceFieldCombinationInterface $fields */
$fields = new CustomFieldCombination();

$factory  = new SourceIteratorFactory(500);
$iterator = $factory->create(
    $idSource,
    $conditions,
    $fields
);

foreach ($iterator as $item) {
    // A validated item with values.
}

The Versions

27/04 2017

dev-master

9999999-dev

This package contains models to supply feed data.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Ashoka de Wit

27/04 2017

1.0.0

1.0.0.0

This package contains models to supply feed data.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Ashoka de Wit