本文整理汇总了PHP中Sonata\AdminBundle\Admin\Pool类的典型用法代码示例。如果您正苦于以下问题:PHP Pool类的具体用法?PHP Pool怎么用?PHP Pool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExecute
public function testExecute()
{
$application = new Application();
$command = new ListAdminCommand();
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$admin1 = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin1->expects($this->any())->method('getClass')->will($this->returnValue('Acme\\Entity\\Foo'));
$admin2 = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin2->expects($this->any())->method('getClass')->will($this->returnValue('Acme\\Entity\\Bar'));
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($container, $admin1, $admin2) {
switch ($id) {
case 'sonata.admin.pool':
$pool = new Pool($container, '', '');
$pool->setAdminServiceIds(array('acme.admin.foo', 'acme.admin.bar'));
return $pool;
break;
case 'acme.admin.foo':
return $admin1;
break;
case 'acme.admin.bar':
return $admin2;
break;
}
return null;
}));
$command->setContainer($container);
$application->add($command);
$command = $application->find('sonata:admin:list');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));
$this->assertRegExp('@Admin services:\\s+acme.admin.foo\\s+Acme\\\\Entity\\\\Foo\\s+acme.admin.bar\\s+Acme\\\\Entity\\\\Bar@', $commandTester->getDisplay());
}
示例2: testExecuteWithException2
public function testExecuteWithException2()
{
$application = new Application();
$command = new SetupAclCommand();
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($container, $admin) {
switch ($id) {
case 'sonata.admin.pool':
$pool = new Pool($container, '', '');
$pool->setAdminServiceIds(array('acme.admin.foo'));
return $pool;
case 'sonata.admin.manipulator.acl.admin':
return new \stdClass();
case 'acme.admin.foo':
return $admin;
}
return;
}));
$command->setContainer($container);
$application->add($command);
$command = $application->find('sonata:admin:setup-acl');
$commandTester = new CommandTester($command);
$commandTester->execute(array('command' => $command->getName()));
$this->assertRegExp('@Starting ACL AdminBundle configuration\\s+The interface "AdminAclManipulatorInterface" is not implemented for stdClass: ignoring@', $commandTester->getDisplay());
}
示例3: testdashboardActionAjaxLayout
public function testdashboardActionAjaxLayout()
{
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$pool = new Pool($container, 'title', 'logo.png');
$pool->setTemplates(array('ajax' => 'ajax.html'));
$templating = $this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface');
$request = new Request();
$request->headers->set('X-Requested-With', 'XMLHttpRequest');
$requestStack = null;
if (Kernel::MINOR_VERSION > 3) {
$requestStack = new \Symfony\Component\HttpFoundation\RequestStack();
$requestStack->push($request);
}
$values = array('sonata.admin.pool' => $pool, 'templating' => $templating, 'request' => $request, 'request_stack' => $requestStack);
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($values) {
return $values[$id];
}));
$container->expects($this->any())->method('getParameter')->will($this->returnCallback(function ($name) {
if ($name == 'sonata.admin.configuration.dashboard_blocks') {
return array();
}
}));
$controller = new CoreController();
$controller->setContainer($container);
$response = $controller->dashboardAction();
$this->isInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
}
示例4: setUp
public function setUp()
{
if (!interface_exists('JMS\\TranslationBundle\\Translation\\ExtractorInterface')) {
$this->markTestSkipped('JMS Translator Bundle does not exist');
}
$this->fooAdmin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$this->barAdmin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
// php 5.3 BC
$fooAdmin = $this->fooAdmin;
$barAdmin = $this->barAdmin;
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($fooAdmin, $barAdmin) {
switch ($id) {
case 'foo_admin':
return $fooAdmin;
case 'bar_admin':
return $barAdmin;
}
return null;
}));
$logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
$this->pool = new Pool($container, '', '');
$this->pool->setAdminServiceIds(array('foo_admin', 'bar_admin'));
$this->adminExtractor = new AdminExtractor($this->pool, $logger);
$this->adminExtractor->setLogger($logger);
}
示例5: onKernelRequest
/**
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* @throws \RuntimeException
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if (!$request) {
return;
}
if (!$request->hasSession()) {
return;
}
$adminCode = $request->get('_sonata_admin');
if (!is_null($adminCode)) {
$this->admin = $this->adminPool->getAdminByAdminCode($adminCode);
if (!$this->admin) {
throw new \RuntimeException(sprintf('Unable to find the admin class related to the current controller (%s)', get_class($this)));
}
if (method_exists($this->admin, 'getTrackedActions')) {
foreach ($this->admin->getTrackedActions() as $trackedAction) {
// if an action which is flagged as 'to be tracked' is matching the end of the route: add info to session
if (preg_match('#' . $trackedAction . '$#', $request->get('_route'), $matches)) {
$this->updateTrackedInfo($request->getSession(), '_networking_initcms_admin_tracker', array('url' => $request->getRequestUri(), 'controller' => $this->admin->getBaseControllerName(), 'action' => $trackedAction));
}
}
}
}
}
示例6: setUp
protected function setUp()
{
$this->application = new Application();
$command = new ExplainAdminCommand();
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$this->admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$this->admin->expects($this->any())->method('getCode')->will($this->returnValue('foo'));
$this->admin->expects($this->any())->method('getClass')->will($this->returnValue('Acme\\Entity\\Foo'));
$this->admin->expects($this->any())->method('getBaseControllerName')->will($this->returnValue('SonataAdminBundle:CRUD'));
$routeCollection = new RouteCollection('foo', 'fooBar', 'foo-bar', 'SonataAdminBundle:CRUD');
$routeCollection->add('list');
$routeCollection->add('edit');
$this->admin->expects($this->any())->method('getRoutes')->will($this->returnValue($routeCollection));
$fieldDescription1 = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
$fieldDescription1->expects($this->any())->method('getType')->will($this->returnValue('text'));
$fieldDescription1->expects($this->any())->method('getTemplate')->will($this->returnValue('SonataAdminBundle:CRUD:foo_text.html.twig'));
$fieldDescription2 = $this->getMock('Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface');
$fieldDescription2->expects($this->any())->method('getType')->will($this->returnValue('datetime'));
$fieldDescription2->expects($this->any())->method('getTemplate')->will($this->returnValue('SonataAdminBundle:CRUD:bar_datetime.html.twig'));
$this->admin->expects($this->any())->method('getListFieldDescriptions')->will($this->returnValue(array('fooTextField' => $fieldDescription1, 'barDateTimeField' => $fieldDescription2)));
$this->admin->expects($this->any())->method('getFilterFieldDescriptions')->will($this->returnValue(array('fooTextField' => $fieldDescription1, 'barDateTimeField' => $fieldDescription2)));
$this->admin->expects($this->any())->method('getFormTheme')->will($this->returnValue(array('FooBundle::bar.html.twig')));
$this->admin->expects($this->any())->method('getFormFieldDescriptions')->will($this->returnValue(array('fooTextField' => $fieldDescription1, 'barDateTimeField' => $fieldDescription2)));
$this->admin->expects($this->any())->method('isChild')->will($this->returnValue(true));
// php 5.3 BC
$adminParent = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$adminParent->expects($this->any())->method('getCode')->will($this->returnValue('foo_child'));
$this->admin->expects($this->any())->method('getParent')->will($this->returnCallback(function () use($adminParent) {
return $adminParent;
}));
// Prefer Symfony 2.x interfaces
if (interface_exists('Symfony\\Component\\Validator\\MetadataFactoryInterface')) {
$this->validatorFactory = $this->getMock('Symfony\\Component\\Validator\\MetadataFactoryInterface');
$validator = $this->getMock('Symfony\\Component\\Validator\\ValidatorInterface');
$validator->expects($this->any())->method('getMetadataFactory')->will($this->returnValue($this->validatorFactory));
} else {
$this->validatorFactory = $this->getMock('Symfony\\Component\\Validator\\Mapping\\Factory\\MetadataFactoryInterface');
$validator = $this->getMock('Symfony\\Component\\Validator\\Validator\\ValidatorInterface');
$validator->expects($this->any())->method('getMetadataFor')->will($this->returnValue($this->validatorFactory));
}
// php 5.3 BC
$admin = $this->admin;
$container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($container, $admin, $validator) {
switch ($id) {
case 'sonata.admin.pool':
$pool = new Pool($container, '', '');
$pool->setAdminServiceIds(array('acme.admin.foo', 'acme.admin.bar'));
return $pool;
case 'validator':
return $validator;
case 'acme.admin.foo':
return $admin;
}
return;
}));
$command->setContainer($container);
$this->application->add($command);
}
示例7: testGetDashboardGroups
public function testGetDashboardGroups()
{
$admin_group1 = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin_group1->expects($this->once())->method('showIn')->will($this->returnValue(true));
$admin_group2 = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
$admin_group2->expects($this->once())->method('showIn')->will($this->returnValue(false));
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$container->expects($this->any())->method('get')->will($this->onConsecutiveCalls($admin_group1, $admin_group2));
$pool = new Pool($container, 'Sonata Admin', '/path/to/pic.png');
$pool->setAdminGroups(array('adminGroup1' => array('items' => array('itemKey' => 'sonata.user.admin.group1')), 'adminGroup2' => array('itmes' => array('itemKey' => 'sonata.user.admin.group1')), 'adminGroup3' => array('items' => array('itemKey' => 'sonata.user.admin.group2'))));
$groups = $pool->getDashboardGroups();
$this->assertCount(1, $groups);
}
示例8: get
/**
* Retrieves the menu based on the group options.
*
* @param string $name
* @param array $options
*
* @return \Knp\Menu\ItemInterface
*
* @throws \InvalidArgumentException if the menu does not exists
*/
public function get($name, array $options = array())
{
$group = $options['group'];
$menuItem = $this->menuFactory->createItem($options['name'], array('label' => $group['label']));
foreach ($group['items'] as $item) {
if (isset($item['admin']) && !empty($item['admin'])) {
$admin = $this->pool->getInstance($item['admin']);
// skip menu item if no `list` url is available or user doesn't have the LIST access rights
if (!$admin->hasRoute('list') || !$admin->isGranted('LIST')) {
continue;
}
$label = $admin->getLabel();
$options = $admin->generateMenuUrl('list');
$options['extras'] = array('translation_domain' => $admin->getTranslationDomain(), 'admin' => $admin);
} else {
$label = $item['label'];
$options = array('route' => $item['route'], 'routeParameters' => $item['route_params'], 'extras' => array('translation_domain' => $group['label_catalogue']));
}
$menuItem->addChild($label, $options);
}
if (false === $menuItem->hasChildren()) {
$menuItem->setDisplay(false);
}
return $menuItem;
}
示例9: execute
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$user_current = $this->securityContext->getToken()->getUser();
$info = $this->em->getRepository("ApplicationSonataUserBundle:Matching")->lastMatchingFromUser($user_current);
// merge settings
$settings = array_merge($this->getDefaultSettings(), $blockContext->getSettings());
return $this->renderResponse($blockContext->getTemplate(), array('block' => $blockContext->getBlock(), 'base_template' => $this->pool->getTemplate('layout'), 'info' => $info, 'settings' => $blockContext->getSettings()), $response);
}
示例10: getAdmin
/**
* @param ComponentInterface $component
*
* @return AdminInterface
*/
protected function getAdmin(ComponentInterface $component, ActionInterface $action = null)
{
if ($action && ($adminComponent = $action->getComponent('admin_code'))) {
return $this->pool->getAdminByAdminCode($adminComponent);
}
try {
return $this->pool->getAdminByClass($component->getModel());
} catch (\RuntimeException $e) {
}
return false;
}
示例11: execute
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$user_current = $this->securityContext->getToken()->getUser();
$info['count_base'] = $this->em->getRepository("ApplicationSonataUserBundle:Base")->countConsumerBases($user_current);
$info['count_campaign'] = $this->em->getRepository("ApplicationSonataUserBundle:Campaign")->countActiveCampaign();
$info['count_md5'] = $this->em->getRepository("ApplicationSonataUserBundle:BaseDetail")->countBaseDetailByUser($user_current);
$info['count_match'] = $this->em->getRepository("ApplicationSonataUserBundle:MatchingDetail")->countMatchingDetailByUser($user_current);
// merge settings
$settings = array_merge($this->getDefaultSettings(), $blockContext->getSettings());
return $this->renderResponse($blockContext->getTemplate(), array('block' => $blockContext->getBlock(), 'base_template' => $this->pool->getTemplate('layout'), 'info' => $info, 'settings' => $blockContext->getSettings()), $response);
}
示例12: testGenerateLinkDisabledEditAndShow
public function testGenerateLinkDisabledEditAndShow()
{
$component = new Component();
$component->setModel('Acme\\DemoBundle\\Model\\Demo');
$component->setIdentifier('2');
$action = new Action();
$this->admin->expects($this->at(0))->method('hasRoute')->with($this->equalTo('edit'))->will($this->returnValue(false));
$this->admin->expects($this->at(1))->method('hasRoute')->with($this->equalTo('show'))->will($this->returnValue(false));
$this->admin->expects($this->once())->method('toString')->with($this->anything())->will($this->returnValue('Text'));
$this->assertEquals('Text', $this->twigExtension->generateLink($component, $action));
}
示例13: testMoveWithAdmin
function testMoveWithAdmin()
{
$movedPath = '/cms/to-move';
$targetPath = '/cms/target/moved';
$urlSafeId = 'urlSafeId';
$admin = $this->getMockBuilder('Sonata\\DoctrinePHPCRAdminBundle\\Admin\\Admin')->disableOriginalConstructor()->getMock();
$admin->expects($this->once())->method('getNormalizedIdentifier')->will($this->returnValue($targetPath));
$admin->expects($this->once())->method('getUrlsafeIdentifier')->will($this->returnValue($urlSafeId));
$this->pool->expects($this->once())->method('getAdminByClass')->will($this->returnValue($admin));
$tree = new PhpcrOdmTree($this->dm, $this->defaultModelManager, $this->pool, $this->translator, $this->assetHelper, array(), array('depth' => 1, 'precise_children' => true));
$this->assertEquals(array('id' => $targetPath, 'url_safe_id' => $urlSafeId), $tree->move($movedPath, $targetPath));
}
示例14: execute
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$admin = $this->pool->getAdminByAdminCode($blockContext->getSetting('code'));
$datagrid = $admin->getDatagrid();
$filters = $blockContext->getSetting('filters');
if (!isset($filters['_per_page'])) {
$filters['_per_page'] = array('value' => $blockContext->getSetting('limit'));
}
foreach ($filters as $name => $data) {
$datagrid->setValue($name, isset($data['type']) ? $data['type'] : null, $data['value']);
}
$datagrid->buildPager();
return $this->renderPrivateResponse($blockContext->getTemplate(), array('block' => $blockContext->getBlock(), 'settings' => $blockContext->getSettings(), 'admin_pool' => $this->pool, 'admin' => $admin, 'pager' => $datagrid->getPager(), 'datagrid' => $datagrid), $response);
}
示例15: createSidebarMenu
/**
* Builds sidebar menu.
*
* @return ItemInterface
*/
public function createSidebarMenu()
{
$menu = $this->factory->createItem('root');
foreach ($this->pool->getAdminGroups() as $name => $group) {
$extras = array('icon' => $group['icon'], 'label_catalogue' => $group['label_catalogue'], 'roles' => $group['roles']);
$menuProvider = isset($group['provider']) ? $group['provider'] : 'sonata_group_menu';
$subMenu = $this->provider->get($menuProvider, array('name' => $name, 'group' => $group));
$subMenu = $menu->addChild($subMenu);
$subMenu->setExtras(array_merge($subMenu->getExtras(), $extras));
}
$event = new ConfigureMenuEvent($this->factory, $menu);
$this->eventDispatcher->dispatch(ConfigureMenuEvent::SIDEBAR, $event);
return $event->getMenu();
}