package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)'controllers' => \[\s*\K('factories' => )(\[((?>[^][]++|(?2))*)])`)
var str = `<?php
namespace Application;
use Laminas\Router\Http\Literal;
use Laminas\Router\Http\Segment;
use Laminas\ServiceManager\Factory\InvokableFactory;
return [
'view_manager' => [
'template_path_stack' => [
__DIR__ . '/../view',
__DIR__ . '/../view/Application/_shared'
],
],
'controllers' => [
'factories' => [
dsdsa
]
],
'service_manager' => [
'factories' => [
'UsersTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Laminas\Db\Adapter\Adapter');
$resultSetPrototype = new \Laminas\Db\ResultSet\ResultSet();
//get base url from config
$config = $sm->get('Config');
$baseUrl = $config['view_manager']['base_url'];
//pass base url via cnstructor to the User class
$resultSetPrototype->setArrayObjectPrototype(new Model\Rowset\User($baseUrl));
return new Utils\TableGateway('users', $dbAdapter, null, $resultSetPrototype);
},
'Application\Model\UsersTable' => function($sm) {
$tableGateway = $sm->get('UsersTableGateway');
$table = new Model\UsersTable($tableGateway);
return $table;
},
Utils\Authentication::class => function($sm) {
$auth = new Utils\Authentication(
$sm->get(\Laminas\Db\Adapter\Adapter::class),
$sm->get(Utils\Adapter::class)
);
return $auth;
},
Utils\Helper::class => InvokableFactory::class,
SessionManager::class => function ($container) {
$config = $container->get('config');
$session = $config['session'];
$sessionConfig = new $session['config']['class']();
$sessionConfig->setOptions($session['config']['options']);
$sessionManager = new Session\SessionManager(
$sessionConfig,
new $session['storage'](),
null
);
\Laminas\Session\Container::setDefaultManager($sessionManager);
return $sessionManager;
},
],
],
];`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/