-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2bd7fd0
Showing
3,713 changed files
with
319,385 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PhpMob package. | ||
* | ||
* (c) Ishmael Doss <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMob\DataFixture; | ||
|
||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Jan Góralski <[email protected]> | ||
*/ | ||
abstract class AbstractExampleFactory implements ExampleFactoryInterface | ||
{ | ||
/** | ||
* @param OptionsResolver $resolver | ||
*/ | ||
abstract protected function configureOptions(OptionsResolver $resolver); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PhpMob package. | ||
* | ||
* (c) Ishmael Doss <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMob\DataFixture; | ||
|
||
use Doctrine\Common\Persistence\ObjectManager; | ||
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\OptionsResolver\Options; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @author Kamil Kokot <[email protected]> | ||
*/ | ||
abstract class AbstractResourceFixture implements FixtureInterface | ||
{ | ||
/** | ||
* @var ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var ExampleFactoryInterface | ||
*/ | ||
private $exampleFactory; | ||
|
||
/** | ||
* @var OptionsResolver | ||
*/ | ||
private $optionsResolver; | ||
|
||
/** | ||
* @param ObjectManager $objectManager | ||
* @param ExampleFactoryInterface $exampleFactory | ||
*/ | ||
public function __construct(ObjectManager $objectManager, ExampleFactoryInterface $exampleFactory) | ||
{ | ||
$this->objectManager = $objectManager; | ||
$this->exampleFactory = $exampleFactory; | ||
|
||
$this->optionsResolver = | ||
(new OptionsResolver()) | ||
->setDefault('random', 0) | ||
->setAllowedTypes('random', 'int') | ||
->setDefault('prototype', []) | ||
->setAllowedTypes('prototype', 'array') | ||
->setDefault('custom', []) | ||
->setAllowedTypes('custom', 'array') | ||
->setNormalizer('custom', function (Options $options, array $custom) { | ||
if ($options['random'] <= 0) { | ||
return $custom; | ||
} | ||
|
||
return array_merge($custom, array_fill(0, $options['random'], $options['prototype'])); | ||
}) | ||
; | ||
} | ||
|
||
/** | ||
* @param array $options | ||
*/ | ||
final public function load(array $options): void | ||
{ | ||
$options = $this->optionsResolver->resolve($options); | ||
|
||
$i = 0; | ||
foreach ($options['custom'] as $resourceOptions) { | ||
$resource = $this->exampleFactory->create($resourceOptions); | ||
|
||
$this->objectManager->persist($resource); | ||
|
||
++$i; | ||
|
||
if (0 === ($i % 10)) { | ||
$this->objectManager->flush(); | ||
$this->objectManager->clear(); | ||
} | ||
} | ||
|
||
$this->objectManager->flush(); | ||
$this->objectManager->clear(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$optionsNode = $treeBuilder->root($this->getName()); | ||
|
||
$optionsNode->children()->integerNode('random')->min(0)->defaultValue(0); | ||
|
||
/** @var ArrayNodeDefinition $resourcesNode */ | ||
$resourcesNode = $optionsNode->children()->arrayNode('custom'); | ||
|
||
/** @var ArrayNodeDefinition $resourceNode */ | ||
$resourceNode = $resourcesNode->requiresAtLeastOneElement()->prototype('array'); | ||
$this->configureResourceNode($resourceNode); | ||
|
||
return $treeBuilder; | ||
} | ||
|
||
/** | ||
* @param ArrayNodeDefinition $resourceNode | ||
*/ | ||
protected function configureResourceNode(ArrayNodeDefinition $resourceNode) | ||
{ | ||
// empty | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PhpMob package. | ||
* | ||
* (c) Ishmael Doss <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMob\DataFixture; | ||
|
||
/** | ||
* @author Kamil Kokot <[email protected]> | ||
*/ | ||
interface ExampleFactoryInterface | ||
{ | ||
/** | ||
* @param array $options | ||
* | ||
* @return object | ||
*/ | ||
public function create(array $options = []); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 liverbool | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PhpMob package. | ||
* | ||
* (c) Ishmael Doss <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMob\DataFixture; | ||
|
||
use Sylius\Component\Resource\Model\TranslatableInterface; | ||
use Sylius\Component\Resource\Translation\Provider\TranslationLocaleProviderInterface; | ||
use Symfony\Component\PropertyAccess\PropertyAccess; | ||
|
||
trait LocaleAwareFactoryTrait | ||
{ | ||
/** | ||
* @var TranslationLocaleProviderInterface | ||
*/ | ||
private $translationProvider; | ||
|
||
/** | ||
* @param TranslationLocaleProviderInterface $translationProvider | ||
*/ | ||
public function setTranslationProvider(TranslationLocaleProviderInterface $translationProvider) | ||
{ | ||
$this->translationProvider = $translationProvider; | ||
} | ||
|
||
/** | ||
* @param TranslatableInterface $object | ||
* @param array $properties | ||
* @param array $data | ||
* | ||
* @throws \TypeError | ||
*/ | ||
protected function setLocalizedData(TranslatableInterface $object, array $properties, array $data) | ||
{ | ||
$accessor = PropertyAccess::createPropertyAccessor(); | ||
|
||
foreach ($this->translationProvider->getDefinedLocalesCodes() as $localeCode) { | ||
$object->setCurrentLocale($localeCode); | ||
$object->setFallbackLocale($localeCode); | ||
|
||
foreach ($properties as $property) { | ||
$value = $data[$property]; | ||
$value = is_string($value) | ||
? $value | ||
: $value[$localeCode]; | ||
|
||
$accessor->setValue($object, $property, $value); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.