Doctrine ORM integration in framework - php

I'm trying to integrate the Doctrine ORM in my Framework. This is the basic structure of my framework.
├───app
│ ├───cache
│ ├───config
│ ├───controllers
│ ├───database
│ │ ├───mapping
│ │ ├───entities
│ │ └───repositories
│ ├───models
│ └───views
├───bin
├───framework
│ ├───cache
│ └───library
├───vendor
So i need to set the default path in Doctrine so that mapping, entity and repository files were generated on those directories:
├───database
│ ├───mapping
│ ├───entities
│ └───repositories
I've been reading the official documentation of Doctrine ORM, but I have not accomplished anything. I would appreciate if someone can help me a little. Sorry if i have orthographic failures.
Regards.

Try this.May it help u.
Let your framework be XYZ:
Make following changes in your index file.
require_once 'XYZ/Loader/Autoloader.php';
$loader = XYZ_Loader_Autoloader::getInstance()
->registerNamespace('Doctrine')
->pushAutoloader(array('Doctrine', 'autoload'));
use Doctrine\ORM\EntityManager, Doctrine\ORM\Configuration;
$manager = Doctrine_Manager::getInstance();

Related

Eclipse with composer problem with "run on server", ok with "PHP CLI Application"

Hi I have a project that uses composer to handle mongo libraries, if I debug with a "test cli application" as console application it works fine, as soon as I try to run it as "run on server" it "looses" autoload.php. The server is a native eclipse's php server
my project directory tree is:
D:\EclipseWorkspace-GIT\mongowithcomposer
├───src
│ ├───MongoHandler
│ ├───WebContent
│ │ ├───js
│ │ ├───resources
│ │ │ └───images
│ │ ├───DEFINITIONS.PHP
│ │ ├───HOME.PHP
│ │ └───style
│ └───XML-Handler
├ COMPOSER.JSON
├ COMPOSER.LOCK
└───vendor
├───composer
├─── AUTOLOAD.PHP
└───mongodb
└───mongodb
├───.github
│ └───ISSUE_TEMPLATE
├───.phpcs
├───.travis
├───docs
│ ├───.static
│ ├───includes
│ ├───reference
.......
this is the error I got:
Warning: require_once(D:\Eclipse-Workspace-GIT\.metadata\.plugins\org.eclipse.wst.server.core\tmp6\htdocs\mongowithcomposer\autoload.php): failed to open stream: No such file or directory in D:\Eclipse-Workspace-GIT\.metadata\.plugins\org.eclipse.wst.server.core\tmp6\htdocs\mongowithcomposer\definitions.php on line 10
NOTE: In the tree output the files are higlighted by being UPPERCASE
EDIT:
this is the server automatic path mapping:
<Server>
<Port name="HTTP/1.1" protocol="HTTP">8181</Port>
<PathMapping local="/mongowithcomposer/vendor/composer" module="mongowithcomposer" remote="D:\Eclipse-Workspace-GIT\.metadata\.plugins\org.eclipse.wst.server.core\tmp6\htdocs\mongowithcomposer"/>
<PathMapping local="/mongowithcomposer/src" module="mongowithcomposer" remote="D:\Eclipse-Workspace-GIT\.metadata\.plugins\org.eclipse.wst.server.core\tmp6\htdocs\mongowithcomposer"/>
<PathMapping local="/mongowithcomposer/vendor/mongodb/mongodb/src" module="mongowithcomposer" remote="D:\Eclipse-Workspace-GIT\.metadata\.plugins\org.eclipse.wst.server.core\tmp6\htdocs\mongowithcomposer"/>
</Server>
This is PDT bug. In current implementation rather than just run php -S it copy .buildpath dirs into separate dir, and then run server.
I have a plan to fix this for in Eclipse 2020-09 and already prepared issue for this: https://github.com/eclipse/pdt/issues/68

Symfony 4 - creating a new project (it does not work)

today I wanted to learn something about symfony and start with basic project setup but it seems like it doesnt work. Here's my steps:
I have created new project by writing:
composer create-project symfony/skeleton my_project '4.4.*'
it went well.
I started local server with:
symfony start:server
server started without any problems.
My routing looks like this:
index:
path: /
controller: App\Controller\DefaultController::index
myController:
public function index() {
return new Response('IT WORKS!');
}
But instead of my response im getting
unable to fetch the response from the backend: malformed MIME header
line: [info] Matched route "index".
Why is this happening? I couldn't find anything.
It seems like this issue is not happening if you create project based on symfony 4.3.. as I did. I have no idea why it didn't work on 4.4. thou.
I got the same problem. I think it is a recent bug of Symfony https://github.com/symfony/cli/issues/274.
My temporary solution is to remove PHP CGI, so Symfony CLI is force to use PHP CLI.
When you run symfony local:php:list, if you saw PHP CGI in the table:
┌─────────┬────────────┬─────────┬─────────┬─────────────┬─────────┬─────────┐
│ Version │ Directory │ PHP CLI │ PHP FPM │ PHP CGI │ Server │ System? │
├─────────┼────────────┼─────────┼─────────┼─────────────┼─────────┼─────────┤
│ 7.4.6 │ /usr/local │ bin/php │ │ bin/php-cgi │ PHP CGI │ * │
└─────────┴────────────┴─────────┴─────────┴─────────────┴─────────┴─────────┘
Try to remove it by running apt remove php-cgi, or if you are in a Docker image, add this line instead RUN rm /usr/local/bin/php-cgi:
┌─────────┬────────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
│ Version │ Directory │ PHP CLI │ PHP FPM │ PHP CGI │ Server │ System? │
├─────────┼────────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ 7.4.6 │ /usr/local │ bin/php │ │ │ PHP CLI │ * │
└─────────┴────────────┴─────────┴─────────┴─────────┴─────────┴─────────┘

Provide localization from custom Laravel packages [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I struggle on how to use localizations correctly with custom packages for laravel?
$this->loadTranslationsFrom(__DIR__ . '/../../resources/lang', 'package_lang'); does not provide me access to my nested translation-files in my views (Blade Templating).
My Folder-Structure
foo-package/
├── resources/
│ ├── lang/
│ │ ├── de/
│ │ │ └── subs/
│ │ │ ├── fields.php
│ │ │ └── general.php
│ │ └── en/
│ │ └── subs/
│ │ ├── fields.php
│ │ └── general.php
│ └── views/
│ └── subs/
│ ├── create.php
│ └── edit.php
└── src/
└── Providers/
└── PackageProvider.php
In my views I try to access it like this:
<label>{{ __('package_lang::subs/fields.name_of_subs') }}</label>
or
<button type="submit">{{ __('package_lang::subs/fields.create_sub') }}</button>
Resulting in returning the translation string key.
The ServiceProvider is loaded in my app.phpconfig, in which I have set the correct locale as well (Debug-Bar proves that). Tried composer dump-autoload, but no success.
I'm only getting this to work if I use the standard project folders of laravel project/resources/lang, which prevents me from using my prefered namespace package_lang:: and making my package ready for localization.
My Service Provider
namespace FooPackage\Providers;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
class PackageServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* #return void
*/
public function boot()
{
$this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');
$this->loadViewsFrom(__DIR__.'/../../resources/views', 'package_views');
$this->loadTranslationsFrom(__DIR__.'/../../resources/lang', 'package_lang');
}
}
Any idea how to solve it?
EDIT:
I have multiple packages following this folder structure.
Okay nevermind, the Post was missing out one major point.
Multiple custom packages are involved, which uses the same namespace package_lang, which causes the problem.
For whatever reason, the second namespace-parameter of $this->loadTranslationsFrom(__DIR__ . '/../../resources/lang', 'package_lang'); has to be uniquely defined!
Changing this solves the problem.
Just a side note:
The above rule does however not apply to $this->loadViewsFrom(__DIR__.'/../../resources/views', 'package_views'); where multiple packages can have the same namespace.

composer PSR4 autoloading issue

I am trying to implement PSR-4 autoloading in my project. It is an existing application I have inherited that doesn't currently use OOP (it's all scripted), but I am hoping to refactor over time to use OOP, and PSR-4 is crucial for me as it will end up being a large project.
At this present time we do not rely on any external libraries (old application entirely written in-house), so composer is ONLY being used for autoloading at this moment in time, but will use third-party packages eventually such as phpunit.
My app structure on my server looks like this:
/var/www/appurl/
│ composer.json
│
├───htdocs
│ ├───AppName
│ │ ├───admin
│ │ │ authenticated.php
│ │ │ init.php
│ │ │ login.php
│ │ │
│ │ └───php
│ │ └───search.php
│ └───Framework
│ ├───Helpers
│ │ └───OSHelpers.php
└───vendor
│ autoload.php
│
└───composer
autoload_classmap.php
autoload_namespaces.php
autoload_psr4.php
autoload_real.php
ClassLoader.php
composer.json:
{
"autoload": {
"psr-4": {
"Framework\\": "htdocs/Framework"
}
}
}
login.php calls authenticated.php when a user successfully logs in, and authenticated calls my init.php script which contains:
<?php
require_once('../../../vendor/autoload.php');
?>
it is search.php that has the error. The user is redirected to search.php when they are authenticated.
search.php has the lines:
use Framework\Helpers\OSHelpers;
$current_os = OSHelpers::GetConciseOSFromUserAgent($user_agent);
OSHelpers.php is namedspaced as: namespace Framework\Helpers;
the static call to OSHelpers works fine if require_once is used, but the 2nd line where I define $current_os is where it appears to be failing.
The error I receive is:
Fatal error: Class 'Framework\Helpers\OSHelpers' not found in /var/www/appurl/htdocs/AppName/php/search.php on line 829
I'm at a bit of a loss about why it does this? When I follow the example in this video (https://www.youtube.com/watch?v=VGSerlMoIrY) my example app works fine, but trying to replicate this in a slightly more complicated structure is giving me problems.
I have done composer dump-autoload -o, and looking within the vendor directory shows that my classes are defined correctly. From vendor/composer/autoload_classmap.php:
'Framework\\Helpers\\OSHelpers' => $baseDir . '/htdocs/Framework/Helpers/OSHelpers.php',

ZF2 + Doctrine multiple connections issue

I have the following situation:
A ZF2 driven application which uses Doctrine for the database related stuff.
My directory layout is that of a typical ZF2 application, except that my module directory (the one that contains src) has a sub-directory test with a seperate module for testing the module in the parent folder.
├───MyModule
│ ├───config
│ ├───src
│ │ └───MyModule
│ │ ├───Controller
│ │ ├───DoctrineExtensions
│ │ ├───Entity
│ │ ├───Factory
│ │ │ └───ViewHelper
│ │ ├───Fieldset
│ │ ├───Filter
│ │ ├───Form
│ │ │ └───Element
│ │ ├───Helper
│ │ ├───Hydrator
│ │ │ └───Strategy
│ │ ├───Mail
│ │ ├───Model
│ │ ├───Service
│ │ ├───Traits
│ │ ├───Validator
│ │ └───View
│ │ └───Helper
│ ├───test
│ │ ├───doc
│ │ └───MyModuleTest
│ │ ├───data
│ │ │ ├───DoctrineORMModule
│ │ │ │ └───Proxy
│ │ │ └───sql
│ │ │ └───data_single
│ │ ├───Fixture
│ │ └───Service
│ └───view
│ ├───flash-messenger
│ └───partial
I want to use a seperate Doctrine configuration and DB connection so I set it up according to DoctrineORMModule documentation.
In the Bootstrap.php file I use for setting up loading the modules under test (gets loaded by PHPUnit before every test run) I set up the ZF2`s ServiceManager and load the Doctrine configuration.
static::$config = $config; // contains merged config
$serviceManager = new ServiceManager(new ServiceManagerConfig());
$serviceManager->setService('ApplicationConfig', $config);
$serviceManager->setFactory('ServiceListener', 'Zend\Mvc\Service\ServiceListenerFactory');
But when I try to get the entity manager
$em = $serviceManager->get('doctrine.entitymanager.orm_testing_mysql');
I always get a
RuntimeException: Options with name "orm_testing_mysql" could not be found in "doctrine.entitymanager"
Running my debugger I found out that $serviceManage->instances['applicationconfig'] contains all the arrays I defined in my configuration file.
$serviceManage->instances['config']['doctrine'] however only contains the default doctrine configuration / connection data shipped with the module.
Can someone figure out what's going wrong?
Any help would be appreciated..
use Zend\ServiceManager\ServiceManager;
use Zend\Mvc\Service\ServiceManagerConfiguration;
class Bootstrap
{
protected static $application;
public static function init()
{
chdir(dirname(__DIR__ . '/../../../../../')); // <-Project path
include __DIR__ . '/../../../../init_autoloader.php'; //<- ur init_autoloader.php
self::$application = \Zend\Mvc\Application::init(include 'config/application.config.php');
}
public static function getServiceManager()
{
return self::$application->getServiceManager();
}
public static function getEntityManager()
{
return self::getServiceManager()->get('doctrine.entitymanager.orm_default');
}
}
Then When you use in to open connection with ORM
setUp()
{
$this->service = Bootstrap::getServiceManager()->get('ServiceRoute')
}

Categories