/** * Get a database connection by name. * * @param string name get default connection if null. * @return ZenMagick\Base\Database\Connection */ public static function getDatabase($conf = 'default') { if (null !== Runtime::getContainer()) { return Runtime::getContainer()->get('doctrine.dbal.' . $conf . '_connection'); } if (is_array(self::$databaseMap[$conf])) { self::$databaseMap[$conf] = Doctrine\DBAL\DriverManager::getConnection(self::$databaseMap[$conf]); } return self::$databaseMap[$conf]; }
$loader = new Twig_Loader_Filesystem([$twigBridgeViews, './app/Resources/view']); $twig = new Twig_Environment($loader, $c->get('parameters')['twig']['loader_options']); $twig->addGlobal('show_exception_backtrace', $c->get('parameters')['twig']['show_exception_backtrace']); $twig->addGlobal('session', $c->get('session')); $formEngine = new \Symfony\Bridge\Twig\Form\TwigRendererEngine(['bootstrap_3_layout.html.twig']); $formEngine->setEnvironment($twig); $formExt = new \Symfony\Bridge\Twig\Extension\FormExtension(new \Symfony\Bridge\Twig\Form\TwigRenderer($formEngine)); $twig->addExtension($formExt); $transExt = new \Symfony\Bridge\Twig\Extension\TranslationExtension($c->get('translator')); $twig->addExtension($transExt); return $twig; }), 'router' => function () { return \FastRoute\simpleDispatcher(function (\FastRoute\RouteCollector $r) { $r->addRoute('GET', '/', ['ClassicApp\\Controller\\IndexController', 'index']); $r->addRoute('GET', '/book', ['ClassicApp\\Controller\\BookController', 'index']); $r->addRoute('GET', '/book/new', ['ClassicApp\\Controller\\BookController', 'create']); $r->addRoute('POST', '/book/new', ['ClassicApp\\Controller\\BookController', 'create']); }); }, 'redis' => \DI\factory(function (\DI\Container $c) { $redis = new Redis(); $redis->connect($c->get('parameters')['redis']['host'], $c->get('parameters')['redis']['port']); return $redis; }), 'doctrine.dbal' => \DI\factory(function (\DI\Container $c) { return Doctrine\DBAL\DriverManager::getConnection($c->get('parameters')['doctrine']['conn']); }), 'doctrine.em' => \DI\factory(function (\DI\Container $c) { $cacheDriver = new \Doctrine\Common\Cache\RedisCache(); $cacheDriver->setRedis($c->get('redis')); $config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration($c->get('parameters')['doctrine']['orm']['entityPaths'], $c->get('parameters')['doctrine']['orm']['devMode'], $c->get('parameters')['doctrine']['orm']['proxyDir'], $cacheDriver, false); $dbal = $c->get('doctrine.dbal'); return \Doctrine\ORM\EntityManager::create($dbal, $config); })];
/** * Reverse engineering of the model from the database structure. * Write result to the entity folder * * WARNING THIS WILL OVERWRITE EXISTING MODEL. * * @return boolean */ public function generate_model() { if (!$this->is_dev()) { return false; } $root = $this->get_entity_path(); $connection_parameters = $this->get_connection_parameters(); $connection = Doctrine\DBAL\DriverManager::getConnection($connection_parameters); $platform = $connection->getDatabasePlatform(); $platform->registerDoctrineTypeMapping('enum', 'string'); $platform->registerDoctrineTypeMapping('set', 'string'); $config = Setup::createConfiguration($this->is_dev()); $config->setMetadataDriverImpl(new Doctrine\ORM\Mapping\Driver\DatabaseDriver(new Doctrine\DBAL\Schema\MySqlSchemaManager($connection))); $em = EntityManager::create($connection, $config); $cmf = new Doctrine\ORM\Tools\DisconnectedClassMetadataFactory(); $cmf->setEntityManager($em); $metadatas = $cmf->getAllMetadata(); $repo_factory = new EntityRepositoryGenerator(); $course = null; foreach ($metadatas as $metadata) { $n = strtolower($metadata->name); if ($n == 'course') { $course = $metadata; break; } } foreach ($metadatas as $metadata) { echo sprintf('Processing entity "<info>%s</info>"', $metadata->name) . '<br/>'; foreach ($metadata->identifier as $key => $value) { //$mapping = $metadata->fieldMappings[$value]; $metadata->identifier[$key] = Inflector::tableize($value); } $fields = array(); foreach ($metadata->fieldMappings as $fieldMapping) { $name = Inflector::tableize($fieldMapping['fieldName']); $fieldMapping['fieldName'] = $name; $fields[$name] = $fieldMapping; } $metadata->fieldMappings = $fields; $n = $metadata->name; if ($n == 'CDocument') { $i = 1; } $name = $metadata->name; $name = Inflector::tableize($name); $is_course_table = strpos($name, 'c_') === 0; if ($is_course_table) { $name = substr($name, 2, strlen($name) - 2); } //$metadata->namespace = 'Entity'; $metadata->customRepositoryClassName = 'Entity\\Repository\\' . Inflector::classify($name) . 'Repository'; //if(is_course_table){ $metadata->name = 'Entity\\' . Inflector::classify($name); $metadata->lifecycleCallbacks['prePersist'] = array('before_save'); //} //$metadata->rootEntityName = Inflector::classify($name); if ($is_course_table) { foreach ($metadata->fieldMappings as $mapping) { $name = $mapping['columnName']; $is_id = isset($mapping['id']) ? $mapping['id'] : false; if ($name != 'c_id' && $is_id) { } } } if ($is_course_table) { $metadata->is_course_table = true; // $mapping = array(); // $mapping['cascade'] = array(); // $mapping['joinColumns'][0] = array('name' => 'c_id', 'referencedColumnName' => 'id'); // $mapping['sourceToTargetKeyColumns']['c_id'] = 'id'; // $mapping['joinColumnFieldNames']['c_id'] = 'c_id'; // $mapping['targetToSourceKeyColumns']['id'] = 'c_id'; // $mapping['id'] = 1; // $mapping['isOwningSide'] = 0; // $mapping['isCascadeRemove'] = 0; // $mapping['isCascadePersist'] = 0; // $mapping['isCascadeRefresh'] = 0; // $mapping['isCascadeMerge'] = 0; // $mapping['isCascadeDetach'] = 0; // $mapping['orphanRemoval'] = 0; // $mapping['type'] = ClassMetadataInfo::MANY_TO_ONE; // $mapping['fetch'] = ClassMetadataInfo::FETCH_LAZY; // $mapping['fieldName'] = 'course'; // $mapping['targetEntity'] = 'Entity\\Course'; // $mapping['sourceEntity'] = $metadata->name; // // $metadata->associationMappings['course'] = $mapping; // $metadata->identifier['course']; // unset($metadata->identifier['c_id']); // unset($metadata->fieldMappings['c_id']); // $mapping = array(); // $mapping['cascade'] = array(); // $mapping['joinColumns'][0] = array('name' => 'id', 'referencedColumnName' => 'c_id'); // $mapping['sourceToTargetKeyColumns']['id'] = 'c_id'; // $mapping['joinColumnFieldNames']['id'] = 'id'; // $mapping['targetToSourceKeyColumns']['c_id'] = 'id'; // $mapping['id'] = 1; // $mapping['isOwningSide'] = 1; // $mapping['isCascadeRemove'] = 0; // $mapping['isCascadePersist'] = 0; // $mapping['isCascadeRefresh'] = 0; // $mapping['isCascadeMerge'] = 0; // $mapping['isCascadeDetach'] = 0; // $mapping['orphanRemoval'] = 0; // $mapping['type'] = ClassMetadataInfo::ONE_TO_MANY; // $mapping['fetch'] = ClassMetadataInfo::FETCH_LAZY; // $name = explode('\\' ,$metadata->name); // $name = end($name); // $name = Inflector::tableize($name); // $mapping['fieldName'] = $name; // $mapping['targetEntity'] = $metadata->name; // $mapping['sourceEntity'] = 'Entity\\Course'; // $course->associationMappings[$name] = $mapping; } $metadata->class_to_extend = $is_course_table ? 'CourseEntity' : 'Entity'; $repo_factory->writeEntityRepositoryClass($metadata->name, $root . '\\repository\\'); } $generator = new EntityGenerator(); $generator->setClassToExtend('Entity'); $generator->setGenerateAnnotations(false); $generator->setGenerateStubMethods(true); $generator->setRegenerateEntityIfExists(false); $generator->setUpdateEntityIfExists(false); $generator->setBackupExisting(false); $generator->setExtension('.class.php'); $generator->setNumSpaces(4); // Generating Entities $generator->generate($metadatas, $root); $exporter = new \Doctrine\ORM\Tools\Export\Driver\YamlExporter(); $exporter->setOutputDir($root . '/mapping'); foreach ($metadatas as $metadata) { echo $metadata->name . '<br/>'; try { $exporter->setMetadata(array($metadata)); $exporter->export(); } catch (Exception $e) { echo $e->getMessage(); } } }
<?php // DIC configuration $container = $app->getContainer(); // view renderer $container['renderer'] = function ($c) { $settings = $c->get('settings')['renderer']; return new Slim\Views\PhpRenderer($settings['template_path']); }; // doctrine connection $container['db'] = function ($c) { $settings = $c->get('settings')['db']; return Doctrine\DBAL\DriverManager::getConnection($settings); }; // redis client $container['redis'] = function ($c) { $settings = $c->get('settings')['redis']; return new Predis\Client($settings); }; // ElasticSearch client $container['search'] = function ($c) { $settings = $c->get('settings')['search']; return new Elastica\Client($settings); }; // monolog $container['logger'] = function ($c) { $settings = $c->get('settings')['logger']; $logger = new Monolog\Logger($settings['name']); $logger->pushProcessor(new Monolog\Processor\UidProcessor()); $logger->pushHandler(new Monolog\Handler\StreamHandler($settings['path'], Monolog\Logger::DEBUG)); return $logger;
if ($adresa == "") { $adresa = strval($vbas->AD->UC) . " " . strval($vbas->AD->PB); } //$mesto = strval($vbas->RRZ->FU->NFU); echo " Parsing done ARES" . PHP_EOL; } else { echo 'Nonexisting ICO ' . PHP_EOL; return; } } else { echo "DB ARES not available" . PHP_EOL; return; } $configuration = new Doctrine\DBAL\Configuration(); $settings = ['dbname' => 'ifarmnew', 'user' => 'root', 'password' => '', 'host' => 'localhost', 'driver' => 'pdo_mysql', 'charset' => 'utf8']; $connection = Doctrine\DBAL\DriverManager::getConnection($settings, $configuration); echo "Donwloaded adress " . $adresa . PHP_EOL; echo "Donwloaded dic " . $dic . PHP_EOL; $ps = $connection->prepare('UPDATE user SET dic=:dic, adress1=:adresa WHERE id=:id '); $ps->execute(['dic' => $dic, 'id' => $userId, 'adresa' => $adresa]); echo "Updated: " . $ps->rowCount(); print_r($ps->getWrappedStatement()); print_r($ps->errorInfo()); echo 'DIC and Adress saved' . PHP_EOL; $urladresa = urlencode($adresa); $geocode = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=' . $urladresa . '&key=AIzaSyDmPjww9bGInAdOuHn7PzD5WtVT2fx-eP8'); echo 'DIC and Adress saved\\n'; $geocodeJSON = json_decode($geocode, true); $lat = $geocodeJSON["results"][0]["geometry"]["location"]["lat"]; $lng = $geocodeJSON["results"][0]["geometry"]["location"]["lng"]; $ps = $connection->prepare('UPDATE user SET lat=:lat, lng=:lng WHERE id=:id ');
$loader = (require __DIR__ . '/../vendor/autoload.php'); $container = (require_once __DIR__ . '/../container.php'); PSX\Bootstrap::setupEnvironment($container->get('config')); // setup connection $params = null; switch (getenv('DB')) { case 'mysql': $params = array('dbname' => 'fusio_ui', 'user' => 'root', 'password' => '', 'host' => 'localhost', 'driver' => 'pdo_mysql'); break; default: case 'sqlite': $params = array('path' => PSX_PATH_CACHE . '/fusio_ui.db', 'driver' => 'pdo_sqlite'); break; } $config = new Doctrine\DBAL\Configuration(); $connection = Doctrine\DBAL\DriverManager::getConnection($params, $config); $container->set('connection', $connection); if (isset($_SERVER['argv']) && in_array('--warmup', $_SERVER['argv'])) { // warmup $loader->addClassMap(['Fusio\\Impl\\Fixture' => __DIR__ . '/../tests/Fixture.php', 'Fusio\\Impl\\TestSchema' => __DIR__ . '/../tests/TestSchema.php']); // create schema $fromSchema = $connection->getSchemaManager()->createSchema(); $version = new Fusio\Impl\Database\Version\Version010(); $toSchema = $version->getSchema(); Fusio\Impl\TestSchema::appendSchema($toSchema); $queries = $fromSchema->getMigrateToSql($toSchema, $connection->getDatabasePlatform()); foreach ($queries as $query) { $connection->query($query); } // insert fixtures $connection = new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($container->get('connection')->getWrappedConnection());