-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'remotes/origin/master' into 1.9
- Loading branch information
Showing
164 changed files
with
5,167 additions
and
604 deletions.
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
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
4 changes: 4 additions & 0 deletions
4
src/Oro/Bundle/ActivityListBundle/Resources/config/oro/api.yml
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,4 @@ | ||
oro_api: | ||
entities: | ||
Oro\Bundle\ActivityListBundle\Entity\ActivityList: ~ | ||
Oro\Bundle\ActivityListBundle\Entity\ActivityOwner: ~ |
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
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
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
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
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
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
122 changes: 122 additions & 0 deletions
122
src/Oro/Bundle/ApiBundle/Command/DumpPublicResourcesCommand.php
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 | ||
|
||
namespace Oro\Bundle\ApiBundle\Command; | ||
|
||
use Oro\Bundle\ApiBundle\Request\PublicResource; | ||
use Oro\Bundle\EntityBundle\ORM\EntityAliasResolver; | ||
use Oro\Bundle\EntityBundle\Provider\EntityClassNameProviderInterface; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Helper\Table; | ||
use Symfony\Component\Console\Helper\TableSeparator; | ||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
|
||
use Oro\Bundle\ApiBundle\Provider\PublicResourcesLoader; | ||
use Oro\Bundle\ApiBundle\Request\RequestType; | ||
use Oro\Bundle\ApiBundle\Request\Version; | ||
|
||
class DumpPublicResourcesCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('oro:api:resources:dump') | ||
->setDescription('Dumps all public API resources.') | ||
// @todo: API version is not supported for now | ||
//->addArgument( | ||
// 'version', | ||
// InputArgument::OPTIONAL, | ||
// 'API version', | ||
// Version::LATEST | ||
//) | ||
->addOption( | ||
'request-type', | ||
null, | ||
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, | ||
'API request type', | ||
[RequestType::REST, RequestType::JSON_API] | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$requestType = $input->getOption('request-type'); | ||
// @todo: API version is not supported for now | ||
//$version = $input->getArgument('version'); | ||
$version = Version::LATEST; | ||
|
||
/** @var PublicResourcesLoader $resourcesLoader */ | ||
$resourcesLoader = $this->getContainer()->get('oro_api.public_resources_loader'); | ||
$resources = $resourcesLoader->getResources($version, $requestType); | ||
|
||
$table = new Table($output); | ||
$table->setHeaders(['Entity', 'Attributes']); | ||
|
||
$i = 0; | ||
foreach ($resources as $resource) { | ||
if ($i > 0) { | ||
$table->addRow(new TableSeparator()); | ||
} | ||
$table->addRow( | ||
[ | ||
$resource->getEntityClass(), | ||
$this->convertResourceAttributesToString($this->getResourceAttributes($resource)) | ||
] | ||
); | ||
$i++; | ||
} | ||
|
||
$table->render(); | ||
} | ||
|
||
/** | ||
* @param PublicResource $resource | ||
* | ||
* @return array | ||
*/ | ||
protected function getResourceAttributes(PublicResource $resource) | ||
{ | ||
$result = []; | ||
|
||
$entityClass = $resource->getEntityClass(); | ||
|
||
/** @var EntityAliasResolver $entityAliasResolver */ | ||
$entityAliasResolver = $this->getContainer()->get('oro_entity.entity_alias_resolver'); | ||
$result['Alias'] = $entityAliasResolver->getPluralAlias($entityClass); | ||
|
||
/** @var EntityClassNameProviderInterface $entityClassNameProvider */ | ||
$entityClassNameProvider = $this->getContainer()->get('oro_entity.entity_class_name_provider'); | ||
$result['Name'] = $entityClassNameProvider->getEntityClassName($entityClass); | ||
$result['Plural Name'] = $entityClassNameProvider->getEntityClassPluralName($entityClass); | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param array $attributes | ||
* | ||
* @return string | ||
*/ | ||
protected function convertResourceAttributesToString(array $attributes) | ||
{ | ||
$result = ''; | ||
|
||
$i = 0; | ||
foreach ($attributes as $name => $value) { | ||
if ($i > 0) { | ||
$result .= PHP_EOL; | ||
} | ||
$result .= sprintf('%s: %s', $name, $value); | ||
$i++; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Oro/Bundle/ApiBundle/Command/RequestTypeApplicableChecker.php
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,44 @@ | ||
<?php | ||
|
||
namespace Oro\Bundle\ApiBundle\Command; | ||
|
||
use Oro\Component\ChainProcessor\ApplicableCheckerInterface; | ||
use Oro\Component\ChainProcessor\ContextInterface; | ||
|
||
class RequestTypeApplicableChecker implements ApplicableCheckerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isApplicable(ContextInterface $context, array $processorAttributes) | ||
{ | ||
$result = self::ABSTAIN; | ||
$attrName = 'requestType'; | ||
if (!empty($processorAttributes[$attrName]) && $context->has($attrName)) { | ||
if (!$this->isMatch($processorAttributes[$attrName], $context->get($attrName))) { | ||
$result = self::NOT_APPLICABLE; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Checks if a value of a processor attribute matches a corresponding value from the context | ||
* | ||
* @param mixed $value | ||
* @param mixed $contextValue | ||
* | ||
* @return bool | ||
*/ | ||
protected function isMatch($value, $contextValue) | ||
{ | ||
if (is_array($contextValue)) { | ||
return is_array($value) | ||
? count(array_intersect($value, $contextValue)) === count($value) | ||
: in_array($value, $contextValue, true); | ||
} | ||
|
||
return $contextValue === $value; | ||
} | ||
} |
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
Oops, something went wrong.