PHP code example of widefocus / feed-source

1. Go to this page and download the library: Download widefocus/feed-source 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/ */

    

widefocus / feed-source example snippets



use WideFocus\Feed\Source\IdentitySourceInterface;

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


use WideFocus\Feed\Source\ValueSourceInterface;

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


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 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 WideFocus\Feed\Source\Iterator\IdentitySourceIterator;

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


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.
}


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.
}


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.
}