PHP code example of globalprofessionalsearch / popov
1. Go to this page and download the library: Download globalprofessionalsearch/popov 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/ */
globalprofessionalsearch / popov example snippets
use GPS\Popov\Facade as Factory;
use League\FactoryMuffin\Faker\Facade as Faker;
// Returns an instance of `GPS\Popov\Factory`
$factory = Factory::instance();
// Define a pool of 100 users; `Factory::definePool` returns an instance
// of `GPS\Popov\Definition`. Defining a pool creates and stores an instance
// of `GPS\Popov\Pool` in the factory.
$factory->definePool('App\User', 100)->setAttrs([
//use the Faker facade to easily wrap calls to faker in closures...
'firstName' => Faker::firstName(),
'lastName' => Faker::lastName(),
// ... or set explicit values, which will be the same for all objects
'enabled' => true,
// ... or reference any callable
'address' => 'Some\Class::generateAddress',
// ... or define custom closures to be called. Closures will receive the
// instance of the object that is being created
'fullName' => function($user) {
return $user->getFirstName().' '.$user->getLastName();
}
]);
// Define a pool of 20 groups
$factory->definePool('App\Group', 20)->setAttrs([
'number' => Faker::randomNumber()
]);
// You can retrieve generated objects by accessing the created pools
// directly...
$user1 = $factory->getPool('App\User')->fetchRandom();
$group1 = $factory->getPool('App\Group')->fetchRandom();
// ... or you can use the wrapper methods on the factory to interact with the
// underlying pool instances
$user2 = $factory->fetchRandom('App\User');
$group2 = $factory->fetchRandom('App\Group');
$obj = $factory->getPool('App\User')->fetchRandom();
$objs = $factory->getPool('App\User')->fetchMultipleRandom();
$obj = $factory->getPool('App\User')->fetchBy('firstName', 'Foobert');
$objs = $factory->getPool('App\User')->fetchMultipleBy('isEnabled', true);
$objs = $factory->getPool('App\User')->fetchMatching(function ($obj) {
// if the callable returns true, this object will be added
// to the returned set
return in_array('Foobert', ['Alice','Bob', 'Foobert']);
});
$objs = $factory->getPool('App\User')->fetchAll();
// ...
$factory->definePool('App\User', 100)->setAttrs([
'firstName' => Faker::firstName(),
'lastName' => Faker::lastName(),
'preferences' => Factory::create('App\AccountPrefs')
]);
// Note that we don't define a starting number for the pool. In this case
// there is no need since an instance will just be created any time a user is
// created
$factory->definePool('App\AccountPrefs')->setAttrs([
'allowEmails' => true,
]);
// the fetched user should contain the nested object
$allow = $factory
->fetchRandom('App\User')
->getPreferences()
->getAllowEmails()
;
//...
$factory
->definePool('App\User')
->setAttrs([
// ...
])
->setRefs([
// ...
])
->after(function($user) {
// this will be called for each user after it's been created
$user->doSomething();
})
;
$factory
->getPool('App\User')
->after(function($pool) {
// this will be called after the pool is
// initialized
foreach($pool->fetchAll() as $obj) {
// ... do something
}
})
;
//... define some pools
// create a hard coded user... any attributes you provide
// will be merged with the existing attributes from the pool
$user = $factory->create('App\User', [
'firstName' => 'Foobert',
'lastName' => 'Bartleby',
'preferences' => Factory::create('App\AccountPrefs', [
'allowEmail' => false
])
]);
// ...
$factory->definePool('App\User', 100)->setAttrs([/* ... */]);
$factory->definePool('App\Group', 20)->setAttrs([/* ... */]);
$factory->definePool('App\Transaction', 50)->setAttrs([/* ... */]);
// ... maybe hard-code some example fixtures
// assuming we know that certain objects should be persisted in a certain order...
$persistOrder = [
'App\User',
'App\Group',
'App\Transaction'
];
// use doctrine to persist each object in each pool
// in the needed order
foreach ($persistOrder as $poolName) {
$pool = $factory->getPool($poolName);
foreach ($pool->fetchAll() as $obj) {
$doctrineManager->persist($obj);
}
$doctrineManager->flush();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.