Propel ORM and PHP - php

I am making a php application using propel ORM. It gives me the following message when I try to run it:
Fatal error: Uncaught Error: Class 'Propel\Runtime\Propel' not found in C:\MAMP\htdocs\Conference\vendor\bin\generated-conf\config.php:2 Stack trace: #0 C:\MAMP\htdocs\Conference\vendor\bin\list.php(6): require_once() #1 {main} thrown in C:\MAMP\htdocs\Conference\vendor\bin\generated-conf\config.php on line 2.
In my config.php generated file I have this written:
'classname' => '\\Propel\\Runtime\\Connection\\ConnectionWrapper'
What does it all mean? Am I missing some file or what?

I think you are missing a step in the building.
I assume you have your schema.xml file complete and you also have a propel.yaml (or with allowed extension file) properly configured. Also I assume you got Propel with Composer.
If you have all that the next steps are:
1) Open a terminal and go to your project directory, where the schema.xml and propel.yaml files are.
2) Execute the following command to get yout generated-sql (I have to do it this way on Windows):
c:\MAMP\htdocs\Conference\vendor\bin\propel sql:build
3) Get your model classes with the following command:
c:\MAMP\htdocs\Conference\vendor\bin\propel model:build
4) After generating the classes, you have to autoload them. Open your composer.json file with your text editor and add the following:
"autoload": {
"classmap": ["generated-classes/"]
}
It should look like this, for example:
{
"require": {
"twig/twig": "~1.0",
"propel/propel": "~2.0#dev"
},
"autoload": {
"classmap": ["generated-classes/"]
}
}
5) To finish the classes autoloading, you need to execute on your console:
composer dump-autoload
6) And for the runtime connection settings run this for comunicate classes at runtime:
c:\MAMP\htdocs\Conference\vendor\bin\propel config:convert
7) Assuming you have created your database, the last thing you need to do is create the tables, this is with the following command:
c:\MAMP\htdocs\Conference\vendor\bin\propel sql:insert
And there you go! That works for me every time I build a project.

Related

PHP Fatal error: Uncaught Error: Class "Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver" not found

Zend Framework Version: 1.21.2
I'm updating my app and in particular a package doctrine/mongodb-odm. I run into the above error.
my .yml files are defined like thus:
/configs/doctrinemappings/
- myFile.dcm.yml
- myFile1.dcm.yml
Bootstrap.php
<?
$driver = new \Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver(array(APPLICATION_PATH.'/configs/doctrinemappings/'));
$config->setMetadataDriverImpl($driver);
?>
I have
composer.json
"require": {
"php": "^8.1",
"doctrine/mongodb-odm": "^2.4.2", <-- updated from 1.2.5
"doctrine/mongodb-odm-bundle": "^4.4"
},
at my disposal. As the error says, YamlDriver not found. I have
AnnotationDriver, SimplifiedXMLDriver, XMLDriver & AttributeDriver at my disposal with my updated package. Can you give me some advice
or a pointer on how best to switch from yaml to one of the above?
It's my understanding, I'd have to use annotations on all my zf1 models to use docblocks for example instead of my current .yml files/setup.
(Assuming i chose AnnotationDriver option above). I've picked this as an example only and would be open to any of the other options.

Composer not generating autoload files package made by me

I hate to add more to the noise of "autoload isn't working!!!!!", but I can't seem to get this problem figured out, and I figured getting some fresh eyes on it would get the problem in a lot less time. Here is my index.php file:
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
require_once 'model/PageNav.php';
use ShinePHP\{Crud, CrudException, EasyHttp, EasyHttpException, HandleData, HandleDataException};
// ALWAYS serve over encrypted channels
try {
EasyHttp::checkHttps();
} catch (EasyHttpException $ex) {
echo $ex;
}
try {
// check if it's a GET request, if it is, serve page, if not, do nothing
if (EasyHttp::isRequestMethod('GET')) {
$Page = new PageNav('Home', 'view/home.php');
$Page->buildPage();
exit;
}
}
catch (EasyHttpException $ex) {
echo $ex;
}
So obviously I am using a package from composer called ShinePHP (it's one I've made, and I'm still working on the documentation, so I'm just using it for my own projects at the moment, composer just makes package management so easy!)
ANYWAYS...because I'm writing this question, I'm obviously getting the following error:
Fatal error: Uncaught Error: Class 'ShinePHP\EasyHttp' not found in /Applications/XAMPP/xamppfiles/htdocs/KRTY/src/index.php:11 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/KRTY/src/index.php on line 11
Now, I haven't manually touched the composer.json file, so here it is:
{
"require": {
"adammcgurk/shine-php": "~0.0.1"
},
"autoload": {
"psr-4": {
"ShinePHP\\": "src/"
}
}
}
I'm not getting any errors on requiring the vendor/autoload.php file (and I've tried changing the path to something that doesn't exist like vendor/alkdjfladksf/autoload.php and it throws an error how it should), I'm running PHP version 7.2.7 on XAMPP on Mac OS Mojave. Here is the directory structure, the highlighted index.php file is the one with the code above:
And here is the output of composer dump-autoload -o:
Generating optimized autoload files
And so...to add more to the fire of this question on Stack...How can I get composer to autoload my ShinePHP namespace with the classes as shown in the code?
This dependency does not have any autoloading rules, so Composer does not know where to find ShinePHP\EasyHttp class. You need to add autoloading configuration in composer.json of shine-php package:
"autoload": {
"psr-4": {
"ShinePHP\\": "src/"
}
},

How to auto generate a bundle in Symfony3? [duplicate]

This question already has answers here:
Symfony3 ClassNotFoundException after bundle creation
(4 answers)
Closed 5 years ago.
I've tried to automatically generate a bundle in Symfony3, using instructions on the official site: https://symfony.com/doc/current/bundles.html, but failed.
I created a directory \src\TestBundle in my project with a file TestBundle.php in it. I extended my class TestBundle from Bundle and added the use Symfony\Component\HttpKernel\Bundle\Bundle; line before the class declaration.
I added my new bundle name to the bundles list in AppKernel.php.
Finally, when I execute $ php bin/console generate:bundle --namespace=TestBundle, I get this error:
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "TestBundle" from namespace "TestBundle".
Any ideas why that happens?
If you launch this command:
php bin/console generate:bundle --namespace=TestBundle
Symfony create the Bundle for you, you don't need to create file and add It into the AppKernel file.
Try to remove all your files and reference about TestBundle and after launch only the command, Symfony will create and register the Bundle for you.
Instead i you want to create manually thos file you need to create the directory \src\TestBundle and inside It file TestBundle.php.
After you need to register It into your AppKernel.
After you need to tell to composer to load that bundle, if is not already done use this configuration for autoload inside composer.json
"autoload": {
"psr-4": {
"": "src/"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
And finally launch the command inside your console:
composer dump-autoload

Load git repo with composer - autoloading issue

I have a github repository https://github.com/KoulSlou/UPS and I would like to add it to my project.
In project root I created composer.json file and defined the following autoloading properties:
{
"autoload": {
"files": [
"libraries/Ups/Ups.php",
"libraries/Ups/Ups_Base.php",
"libraries/Ups/Ups_Base_Response.php",
"libraries/Ups/Ups_Live_Rates.php"
]
}
}
When I run
php composer.phar install
repository is being downloaded, but it looks like autoloader is not working. When I try to initialize one of the classes
$test = new Ups()
I got the following error:
Fatal error: Class 'Ups' not found in application/....
Did I define "autoload" property incorrectly?
I'd suggest not using the "files" autoloader, because that isn't very automatic - the files mentioned here are ALWAYS included. Replacing it with "classmap" would be better. And then you'd not be required to mention ALL files, but you can simply state the directory you want to have scanned for classes.
Now what I don't see anywhere: Did you initialize Composer's autoloader anywhere? This usually is something like
require "vendor/autoload.php";
Finaly, I have found out what was the problem. composer.json file in the project I was trying to load - UPS library -was invalid. I was able to download files when I ran:
composer.phar install
but it looks like composer.json file was ignored. I found it out when I ran
composer.phar update
and got
No valid composer.json was found
With option -v I got error that "name" is undefined index. So, I simply added "name" field to the composer.json. Final version is:
{
"name":"KoulSlou/UPS",
"autoload": {
"files": [
"libraries/Ups/Ups.php",
"libraries/Ups/Ups_Base.php",
"libraries/Ups/Ups_Base_Response.php",
"libraries/Ups/Ups_Live_Rates.php"
]
}
}

Unable to use Propel 2 (Class not found)

I'm tryng from several days to setup and use Propel now 2.0. PHP version is 5.4.4-14+deb7u5
What I have done:
0) Fresh LAMP with a folder "test" in /var/www
1) Composer.json with
{
"require": {
"propel/propel": "2.0.*#dev"
}
}
(also tried with the alpha indicated in home page, no success, download but i cannot use)
2) It download all necessary files.
3) I can launch "vendor/bin/propel" and it exit after some green text.
4) I create the schema.xml with foreign keys indicated in http://propelorm.org/documentation/02-buildtime.html
5) I set up buildtime.cconfiguration
6) I can create the sql:build and the model:build (I find the bookstore.sql in generated-sql and the classes in generated-classes)
7) I CANNOT insert the sql. I launch sql:insert, no error at screen but no insert in database (connection/password is okay, double checked).
8) I load myself SQL in database.
9) I create an index.php with this:
<?php
// setup the autoloading
require_once 'vendor/autoload.php';
use Propel\Runtime\Propel;
use Propel\Runtime\Connection\ConnectionManagerSingle;
$serviceContainer = Propel::getServiceContainer();
$serviceContainer->setAdapterClass('bookstore', 'mysql');
$manager = new ConnectionManagerSingle();
$manager->setConfiguration(array (
'dsn' => 'mysql:host=localhost;dbname=my_db_name',
'user' => 'my_db_user',
'password' => 's3cr3t',
));
$serviceContainer->setConnectionManager('bookstore', $manager);
echo 'All ok, for now...';
$author = new Author();
$author->setFirstName('Jane');
$author->setLastName('Austen');
$author->save();
/* /end of php file */
The echo is printed normally but next row script exit with error 500 and in Apache log I read "Class author not found".
Is there some other config to adjust other than indicate in the guide?
I resolved a similar situation by adding this to my composer.json and then running install again.
"autoload": {
"classmap": ["generated-classes/"]
}
I had this error too. Apparently the problem was with the autoload configuration and running a php composer.phar dump-autoload command fixed it.
php composer.phar dump-autoload
If you want to solve this problem you should combine jerrygarcuih's and Abaobi Orajiaku's awnsers.
Thank you guys.
Add the models folder to the composer.json
"autoload": {
"classmap": ["generated-classes/"]
}
Then run composer 'dump-autoload'.
All generated classes should be in the same namespace.
I had a similiar issue. And i solved it by including the exact path to the classmaps.
"autoload": {
"classmap": [
"path/to/generated-classes/",
"path/to/generated-classes/Base/",
"path/to/generated-classes/Map/"
]
}

Categories