PHP code example of gbprod / elastica-provider-bundle
1. Go to this page and download the library: Download gbprod/elastica-provider-bundle 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/ */
gbprod / elastica-provider-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
new GBProd\ElasticaProviderBundle\ElasticaProviderBundle(),
);
}
namespace GBProd\AcmeBundle\Provider;
use GBProd\ElasticaProviderBundle\Provider\BulkProvider;
class SuperHeroProvider extends BulkProvider
{
protected function populate()
{
$this->index(
'Spider-Man', // id of the document
[
"name" => "Spider-Man",
"description" => "Bitten by a radioactive spider, high school student Peter Parker gained the speed, strength and powers of a spider. Adopting the name Spider-Man, Peter hoped to start a career using his new abilities. Taught that with great power comes great responsibility, Spidey has vowed to use his powers to help people.",
]
);
$this->update(
'Hulk',
[
"name" => "Hulk",
"description" => "Caught in a gamma bomb explosion while trying to save the life of a teenager, Dr. Bruce Banner was transformed into the incredibly powerful creature called the Hulk. An all too often misunderstood hero, the angrier the Hulk gets, the stronger the Hulk gets.",
]
);
$this->create(
'Thor',
[
"name" => "Thor",
"description" => "As the Norse God of thunder and lightning, Thor wields one of the greatest weapons ever made, the enchanted hammer Mjolnir. While others have described Thor as an over-muscled, oafish imbecile, he's quite smart and compassionate. He's self-assured, and he would never, ever stop fighting for a worthwhile cause.",
]
);
$this->delete('Captain America');
}
public function count()
{
return 4;
}
}
namespace GBProd\AcmeBundle\Provider;
use GBProd\ElasticaProviderBundle\Provider\BulkProvider;
use Doctrine\ORM\EntityManager;
class SuperHeroprovider extends BulkProvider
{
private $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
protected function populate()
{
$query = $this->em->createQuery('SELECT s FROM AcmeBundle\Model\SuperHero s');
$results = $query->iterate();
foreach ($results as $row) {
$this->index(
$row[0],
[
"name" => $row[0],
"description" => $row[1],
]
);
$this->em->detach($row[0]);
}
}
public function count()
{
$query = $this->em
->createQuery('SELECT COUNT(s.id) FROM AcmeBundle\Model\SuperHero s')
;
return $query->getSingleScalarResult();
}
}
namespace GBProd\AcmeBundle\Provider;
use GBProd\ElasticaProviderBundle\Provider\BulkProvider;
class SuperHeroprovider extends BulkProvider
{
public function __construct()
{
$this->changeBulkSize(42);
}
protected function populate()
{
// ...
}
}
namespace GBProd\AcmeBundle\Provider;
use GBProd\ElasticaProviderBundle\Provider\BulkProvider;
class SuperHeroprovider extends BulkProvider
{
protected function populate()
{
// ...
}
public function count()
{
return 2;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.