本文整理汇总了PHP中Sonata\AdminBundle\Route\RouteCollection::addCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP RouteCollection::addCollection方法的具体用法?PHP RouteCollection::addCollection怎么用?PHP RouteCollection::addCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sonata\AdminBundle\Route\RouteCollection
的用法示例。
在下文中一共展示了RouteCollection::addCollection方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build
/**
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param \Sonata\AdminBundle\Route\RouteCollection $collection
*/
public function build(AdminInterface $admin, RouteCollection $collection)
{
$collection->add('list');
$collection->add('create');
$collection->add('batch');
$collection->add('edit');
$collection->add('delete');
$collection->add('show');
$collection->add('export');
if ($this->manager->hasReader($admin->getClass())) {
$collection->add('history', '/audit-history');
$collection->add('history_view_revision', '/audit-history-view');
}
if ($admin->isAclEnabled()) {
$collection->add('acl', $admin->getRouterIdParameter() . '/acl');
}
// an admin can have only one level of nested child
if ($admin->getParent()) {
return;
}
// add children urls
foreach ($admin->getChildren() as $children) {
$collection->addCollection($children->getRoutes());
}
}
示例2: build
/**
* RouteBuilder that allowes slashes in the ids.
*
* @param \Sonata\AdminBundle\Admin\AdminInterface $admin
* @param \Sonata\AdminBundle\Route\RouteCollection $collection
*/
function build(AdminInterface $admin, RouteCollection $collection)
{
$collection->add('list');
$collection->add('create');
$collection->add('batch');
$collection->add('edit', $admin->getRouterIdParameter() . '/edit', array(), array('id' => '.+'));
$collection->add('delete', $admin->getRouterIdParameter() . '/delete', array(), array('id' => '.+'));
$collection->add('show', $admin->getRouterIdParameter(), array(), array('id' => '.+', '_method' => 'GET'));
// add children urls
foreach ($admin->getChildren() as $children) {
$collection->addCollection($children->getRoutes());
}
}
示例3: testChildCollection
public function testChildCollection()
{
$childCollection = new RouteCollection('baseCodeRouteChild', 'baseRouteNameChild', 'baseRoutePatternChild', 'baseControllerNameChild');
$childCollection->add('view');
$childCollection->add('create');
$parentCollection = new RouteCollection('baseCodeRoute', 'baseRouteName', 'baseRoutePattern', 'baseControllerName');
$parentCollection->add('view');
$parentCollection->add('edit');
$parentCollection->addCollection($childCollection);
$this->assertTrue($parentCollection->has('view'));
$this->assertTrue($parentCollection->has('edit'));
$this->assertFalse($parentCollection->has('create'));
$this->assertFalse($parentCollection->has('baseCodeRouteChild.edit'));
}
示例4: build
/**
* RouteBuilder that allows slashes in the ids.
*
* {@inheritDoc}
*/
function build(AdminInterface $admin, RouteCollection $collection)
{
$collection->add('list');
$collection->add('create');
$collection->add('batch', null, array(), array('_method' => 'POST'));
$collection->add('edit', $admin->getRouterIdParameter() . '/edit', array(), array('id' => '.+'));
$collection->add('delete', $admin->getRouterIdParameter() . '/delete', array(), array('id' => '.+'));
$collection->add('export');
$collection->add('show', $admin->getRouterIdParameter() . '/show', array(), array('id' => '.+', '_method' => 'GET'));
if ($admin->isAclEnabled()) {
$collection->add('acl', $admin->getRouterIdParameter() . '/acl', array(), array('id' => '.+'));
}
// add children urls
foreach ($admin->getChildren() as $children) {
$collection->addCollection($children->getRoutes());
}
}
示例5: buildRoutes
/**
* Build all the related urls to the current admin
*
* @return void
*/
public function buildRoutes()
{
if ($this->loaded['routes']) {
return;
}
$this->loaded['routes'] = true;
$collection = new RouteCollection(
$this->getBaseCodeRoute(),
$this->getBaseRouteName(),
$this->getBaseRoutePattern(),
$this->getBaseControllerName()
);
$collection->add('list');
$collection->add('create');
$collection->add('batch');
$collection->add('edit', $this->getRouterIdParameter().'/edit');
$collection->add('delete', $this->getRouterIdParameter().'/delete');
$collection->add('show', $this->getRouterIdParameter().'/show');
// add children urls
foreach ($this->getChildren() as $children) {
$collection->addCollection($children->getRoutes());
}
$this->configureRoutes($collection);
$this->routes = $collection;
}
示例6: testGenerateUrlParentFieldDescription
/**
* @dataProvider getGenerateUrlParentFieldDescriptionTests
*/
public function testGenerateUrlParentFieldDescription($expected, $name, array $parameters)
{
$childCollection = new RouteCollection('base.Code.Parent|base.Code.Child', 'admin_acme_child', '/foo/', 'BundleName:ControllerName');
$childCollection->add('bar');
$collection = new RouteCollection('base.Code.Parent', 'admin_acme', '/', 'BundleName:ControllerName');
$collection->add('foo');
$collection->addCollection($childCollection);
$admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin->expects($this->any())->method('isChild')->will($this->returnValue(false));
$admin->expects($this->any())->method('getCode')->will($this->returnValue('base.Code.Parent'));
// embeded admin (not nested ...)
$admin->expects($this->once())->method('hasParentFieldDescription')->will($this->returnValue(true));
$admin->expects($this->once())->method('hasRequest')->will($this->returnValue(true));
$admin->expects($this->any())->method('getUniqid')->will($this->returnValue('foo_uniqueid'));
$admin->expects($this->any())->method('getCode')->will($this->returnValue('foo_code'));
$admin->expects($this->once())->method('getPersistentParameters')->will($this->returnValue(array('abc' => 'a123', 'efg' => 'e456')));
$admin->expects($this->any())->method('getExtensions')->will($this->returnValue(array()));
$admin->expects($this->any())->method('getRoutes')->will($this->returnValue($collection));
$router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
$router->expects($this->once())->method('generate')->will($this->returnCallback(function ($name, array $parameters = array()) {
$params = '';
if (!empty($parameters)) {
$params .= '?' . http_build_query($parameters);
}
switch ($name) {
case 'admin_acme_foo':
return '/foo' . $params;
case 'admin_acme_child_bar':
return '/foo/bar' . $params;
}
return null;
}));
$fieldDescription = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
$fieldDescription->expects($this->once())->method('getOption')->will($this->returnValue(array()));
$parentAdmin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$parentAdmin->expects($this->any())->method('getUniqid')->will($this->returnValue('parent_foo_uniqueid'));
$parentAdmin->expects($this->any())->method('getCode')->will($this->returnValue('parent_foo_code'));
$parentAdmin->expects($this->any())->method('getExtensions')->will($this->returnValue(array()));
$fieldDescription->expects($this->any())->method('getAdmin')->will($this->returnValue($parentAdmin));
$admin->expects($this->any())->method('getParentFieldDescription')->will($this->returnValue($fieldDescription));
$cache = new RoutesCache($this->cacheTempFolder, true);
$generator = new DefaultRouteGenerator($router, $cache);
$this->assertEquals($expected, $generator->generateUrl($admin, $name, $parameters));
}
示例7: testGenerateUrlLoadCache
/**
* @dataProvider getGenerateUrlLoadCacheTests
*/
public function testGenerateUrlLoadCache($expected, $name, array $parameters)
{
$childCollection = new RouteCollection('base.Code.Parent|base.Code.Child', 'admin_acme_child', '/foo', 'BundleName:ControllerName');
$childCollection->add('bar');
$collection = new RouteCollection('base.Code.Parent', 'admin_acme', '/', 'BundleName:ControllerName');
$collection->add('foo');
$collection->addCollection($childCollection);
$standaloneCollection = new RouteCollection('base.Code.Child', 'admin_acme_child_standalone', '/', 'BundleName:ControllerName');
$standaloneCollection->add('bar');
$admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin->expects($this->any())->method('isChild')->will($this->returnValue(true));
$admin->expects($this->any())->method('getCode')->will($this->returnValue('base.Code.Child'));
$admin->expects($this->any())->method('getBaseCodeRoute')->will($this->returnValue('base.Code.Parent|base.Code.Child'));
$admin->expects($this->any())->method('getIdParameter')->will($this->returnValue('id'));
$admin->expects($this->any())->method('hasParentFieldDescription')->will($this->returnValue(false));
$admin->expects($this->any())->method('hasRequest')->will($this->returnValue(true));
$admin->expects($this->any())->method('getUniqid')->will($this->returnValue('foo_uniqueid'));
$admin->expects($this->any())->method('getPersistentParameters')->will($this->returnValue(array('abc' => 'a123', 'efg' => 'e456')));
$admin->expects($this->any())->method('getRoutes')->will($this->returnValue($childCollection));
$admin->expects($this->any())->method('getExtensions')->will($this->returnValue(array()));
$parentAdmin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$parentAdmin->expects($this->any())->method('getIdParameter')->will($this->returnValue('childId'));
$parentAdmin->expects($this->any())->method('getRoutes')->will($this->returnValue($collection));
$parentAdmin->expects($this->any())->method('getCode')->will($this->returnValue('base.Code.Parent'));
$parentAdmin->expects($this->any())->method('getExtensions')->will($this->returnValue(array()));
// no request attached in this test, so this will not be used
$parentAdmin->expects($this->never())->method('getPersistentParameters')->will($this->returnValue(array('from' => 'parent')));
$request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
$request->attributes = $this->getMock('Symfony\\Component\\HttpFoundation\\ParameterBag');
$request->attributes->expects($this->any())->method('has')->will($this->returnValue(true));
$request->attributes->expects($this->any())->method('get')->will($this->returnCallback(function ($key) {
if ($key == 'childId') {
return '987654';
}
return;
}));
$admin->expects($this->any())->method('getRequest')->will($this->returnValue($request));
$admin->expects($this->any())->method('getParent')->will($this->returnValue($parentAdmin));
$standaloneAdmin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$standaloneAdmin->expects($this->any())->method('isChild')->will($this->returnValue(false));
$standaloneAdmin->expects($this->any())->method('getCode')->will($this->returnValue('base.Code.Child'));
$standaloneAdmin->expects($this->once())->method('hasParentFieldDescription')->will($this->returnValue(false));
$standaloneAdmin->expects($this->once())->method('hasRequest')->will($this->returnValue(true));
$standaloneAdmin->expects($this->any())->method('getUniqid')->will($this->returnValue('foo_uniqueid'));
$standaloneAdmin->expects($this->once())->method('getPersistentParameters')->will($this->returnValue(array('abc' => 'a123', 'efg' => 'e456')));
$standaloneAdmin->expects($this->any())->method('getRoutes')->will($this->returnValue($standaloneCollection));
$standaloneAdmin->expects($this->any())->method('getExtensions')->will($this->returnValue(array()));
$router = $this->getMock('\\Symfony\\Component\\Routing\\RouterInterface');
$router->expects($this->exactly(2))->method('generate')->will($this->returnCallback(function ($name, array $parameters = array()) {
$params = '';
if (!empty($parameters)) {
$params .= '?' . http_build_query($parameters);
}
switch ($name) {
case 'admin_acme_child_bar':
return '/foo/bar' . $params;
case 'admin_acme_child_standalone_bar':
return '/bar' . $params;
}
return;
}));
$cache = new RoutesCache($this->cacheTempFolder, true);
$generator = new DefaultRouteGenerator($router, $cache);
// Generate once to populate cache
$generator->generateUrl($admin, 'bar', $parameters);
$this->assertEquals($expected, $generator->generateUrl($standaloneAdmin, $name, $parameters));
}