Fatal error: Uncaught Error: Class 'maimana\App' not found -- slim3 - php

i was following alex's how to build a shopping cart lesson and everything's working fine. but then i dont know what im doing wrong so i get this error :
Fatal error: Uncaught Error: Class 'maimana\App' not found in /Applications/MAMP/htdocs/maimana/bootstrap/app.php:13 Stack trace: #0 /Applications/MAMP/htdocs/maimana/public/index.php(3): require() #1 {main} thrown in /Applications/MAMP/htdocs/maimana/bootstrap/app.php on line 13
bootsrap/app.php :
<?php
use Respect\Validation\Validator as v;
use maimana\App as MyApp;
use Slim\Views\Twig;
use Illuminate\Database\Capsule\Manager as Capsule;
session_start();
require __DIR__ . '/../vendor/autoload.php';
$app = new MyApp;
$container = $app->getContainer();
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'maimana',
'username' => 'rdp46',
'password' => 'littlelion4696',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
require __DIR__ . '/../app/routes.php';
Myapp/App.php :
namespace maimana;
use DI\ContainerBuilder;
use DI\Bridge\Slim\App as DiBridge;
class App extends DiBridge{
protected function configureContainer(ContainerBuilder $builder)
{
$builder->addDefinitions([
'settings.displayErrorDetails' => true,
]);
$builder->addDefinitions(__DIR__ . '/container.php');
}
}
anyone know what's going on?

Rename the Myapp directory to maimana (note case) and then update your composer.json to autoload the maimana namespace.
i.e. ensure that your composer.json has:
"autoload": {
"psr-4": {
"maimana\\": "maimana/"
}
}
This assumes that the maimana directoryis in the root of your project where the composer.json file is. Once you have changed composer.json, you need to run composer dumpautoload for the changes to take effect.
This is required because there is a one to one mapping between directory name that the PHP file is in and the namespace for the class in that PHP file. As the namespace in your App.php is maimana, the directory needs to be maimana.

Related

Laravel: Jasper reports in laravel lumen5.6

I already implemented jasper reports with laravel and it works fine for me. Now i shifted to laravel lumen for api building so i try to integrate jasper as same as i integrate in my laravel projects but in laravel lumen it throws some error as below:-
Call to undefined method Laravel\Lumen\Application::booting()
below is my connection code
class_alias(JasperPHP\JasperPHPServiceProvider::class,'JasperPHP');
$app->withFacades(); $app->withEloquent();
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(App\Providers\EventServiceProvider::class);
$app->register(JasperPHP\JasperPHPServiceProvider::class);
Please share your thoughts, Thanks in advance
I finally come up with a solution and it works fine with laravel lumen 5.6 below are the steps:-
1)Install JasperReports 6 library by below command
composer require cossou/jasperphp
In bootstrap/app.php uncomment this line $app->withFacades(); and add below code
$app->singleton('jasperphp', function ($app) {
return new JasperPHP;
});
$app->alias('JasperPHP\JasperPHPServiceProvider\JasperPHP', 'JasperPHP');
Controller part Changes
namespace App\Http\Controllers;
use JasperPHP\JasperPHP as JasperPHP;
use Illuminate\Http\Request;
//dd(__DIR__ . '/../../vendor/cossou/jasperphp/examples/hello_world.jasper');
class ReportController extends Controller {
public function generateReport() {
//JasperPHP::compile(base_path('/vendor/cossou/jasperphp/examples/hello_world.jrxml'))->execute();
$jasper = new JasperPHP;
$filename = 'gau';
$output = base_path('//public/reports/' . $filename);
$jasper->process(
base_path('/vendor/cossou/jasperphp/examples/LaravelIreporTest.jasper'),
$output,
array("pdf"),
array("test" => "Tax Invoice"),
array(
'driver' => 'mysql',
'username' => 'username',
'password' => 'password',
'host' => 'localhost',
'database' => 'database name',
'port' => '3306',
)
)->execute();
}
}

Doctrine cannot redeclare class Annotation

i've got my bootstrap
<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
// Log Filename
define ('LOG_FILENAME', 'clicktocall-'.date("Ymd").'log');
$loader = require "vendor/autoload.php";
// Doctrine parser
Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array("./src/acme"), $isDevMode);
// Database configuration parameters
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => 'localhost',
'user' => 'xxx',
'password' => 'yyy',
'dbname' => 'zzz',
);
// Obtaining the entity manager
$em = EntityManager::create($dbParams, $config);
// Setting Logger Monolog
$Logger = new \Monolog\Logger('CTLogger');
$Logger->pushHandler(new \Monolog\Handler\StreamHandler('./log/'.LOG_FILENAME, \Monolog\Logger::INFO));
When i'm trying to execute
vendor\bin\doctrine orm:schema-tool:update --force
I obtain this message
Fatal error: Cannot redeclare class Doctrine\ORM\Mapping\Annotation in E:\www\acme\vendor\doctri
ne\orm\lib\Doctrine\ORM\Mapping\Annotation.php on line 22
I'm just using Doctrine bundle.
Any idea?
Thanks a lot
[Edit]
I've found that the problem is caused by
Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
I use this row to parse the annotations for the symfony\validator bundle, without this the validation doesn't work...

Command line Doctrine ORM with Silex: You are missing a "cli-config.php" or "config/cli-config.php" file in your project

I am trying to use Doctrine ORM with Silex, and finding it an altogether frustrating experience, due to the lack of consistent documentation.
When I run vendor/bin/doctrine at the console, I get the following output:
output:
You are missing a "cli-config.php" or "config/cli-config.php" file in your
project, which is required to get the Doctrine Console working. You can use the
following sample as a template:
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
// replace with file to your own project bootstrap
require_once 'bootstrap.php';
// replace with mechanism to retrieve EntityManager in your app
$entityManager = GetEntityManager();
return ConsoleRunner::createHelperSet($entityManager);
This is my composer.json file:
{
"require": {
"silex/silex": "2.0.*#dev",
"symfony/yaml": "2.6.7",
"doctrine/dbal": "~2.2",
"dflydev/doctrine-orm-service-provider": "2.0.*#dev",
"khepin/yaml-fixtures-bundle": "~0.8.1"
},
"config": {
"bin-dir": "bin"
}
}
This is the php code that registers the Doctrine service etc.
<?php
use Doctrine\Common\Cache\ApcCache;
use Doctrine\Common\Cache\ArrayCache;
use Silex\Provider\DoctrineServiceProvider;
use Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider;
$app->register(new DoctrineServiceProvider(), array(
'db.options' => array(// http://silex.sensiolabs.org/doc/providers/doctrine.html
'driver' => 'pdo_mysql',
'dbname' => 'foobar',
'host' => 'localhost',
'user' => 'root',
'password' => 'root',
'charset' => 'utf8'
)
));
$app->register(new DoctrineORMServiceProvider(),
array(
'db.orm.proxies_dir' => __DIR__.'/../cache/doctrine/proxy',
'db.orm.proxies_namespace' => 'DoctrineProxy',
'db.orm.cache' => !$app['debug'] &&extension_loaded('apc') ? new ApcCache() : new ArrayCache(),
'db.orm.auto_generate_proxies' => true,
'db.orm.entities' => array(array(
'type' => 'simple_yaml',
'path' => __DIR__.'/src/Resources/config/doctrine',
'namespace' => 'Foobar\Entity',
)),
));
This is my configuration file (bin/cli-config.php)
<?php
// retrieve EntityManager
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
$app = require_once __DIR__.'/../app/src/app.php';
$isDevMode = $app['debug'];
$paths = $app['db.orm.entities']['path'];
$config = Setup::createYAMLMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($app['db.options'], $config);
return ConsoleRunner::createHelperSet($entityManager);
What am I doing wrong?
You need to move bin/cli-config.php in config/cli-config.php.
Unfortunately I have not found documentation about it. I opened doctrine/dbal/bin/doctrine-dbal.php and checked how it worked.
Both cli-config.php and bootstrap.php should be placed in same folder. They are working for me if either I place them at root of my zend project or in root->config folder.
Then orm:convert-mapping command in terminal on mac runs successfully.
./vendor/bin/doctrine orm:convert-mapping --namespace="Quiz\Model\Entity" --force --from-database annotation ./module/Quiz/src/Model/

Laravel 5 - Storage Adapter Extending Will Not Work

For some reason I cannot extend the Storage Class like the example in the docs.
I have been trying to create an FTP adapter because it is required for the project I am working on.
Here is the Service Provider I have created
<?php namespace herbals\Providers;
use Storage;
use Illuminate\Filesystem\FilesystemServiceProvider as ServiceProvider;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Ftp as FTPAdapter;
class FTPFileSystemServiceProvider extends ServiceProvider {
public function boot()
{
Storage::extend('ftp', function($app, $config)
{
$client = new FTPAdapter(array(
'host' => env('FTP_HOST') || '',
'username' => env('FTP_USERNAME') || '',
'password' => env('FTP_PASSWORD') || '',
'port' => env('FTP_PORT') || '',
'root' => env('FTP_ROOT') || '/',
'passive' => true,
'ssl' => true,
'timeout' => 30,
));
$filesystem = new Filesystem($client);
return $filesystem;
});
}
public function register()
{
//
}
}
Here is the error I keep getting
ErrorException in FilesystemManager.php line 232:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Filesystem\FilesystemAdapter' does not have a method 'createDriver'
in FilesystemManager.php line 232
at HandleExceptions->handleError('2', 'call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Filesystem\FilesystemAdapter' does not have a method 'createDriver'', '/home/vagrant/Code/herbals/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php', '232', array('method' => 'createDriver', 'parameters' => array(null)))
at call_user_func_array(array(object(FilesystemAdapter), 'createDriver'), array(null)) in FilesystemManager.php line 232
at FilesystemManager->__call('createDriver', array(null)) in FilesystemManager.php line 97
at FilesystemManager->createDriver(null) in FilesystemManager.php line 97
at FilesystemManager->resolve('ftp') in FilesystemManager.php line 79
at FilesystemManager->get('ftp') in FilesystemManager.php line 68
at FilesystemManager->disk('ftp') in Facade.php line 210
at Facade::__callStatic('disk', array('ftp')) in routes.php line 26
at Storage::disk('ftp') in routes.php line 26
I think you are making a little mistake here, make sure you have the ftp drivers and its details (host, username,password ) in /config/filesystem.php and reference them in your provider using $config['host'] and so on...
After playing with the api for some time , I was able to figure it out , now follow these instructions : In you /config/filesystem.php , add the new driver settings like :
'ftp' => [
'driver' => 'ftp',
'host' =>'ftp-host',
'username' => 'ftp-username',
'password' => 'ftp-pass',
'port' => 21,
'ssl' => false,
],
Next we will create an Ftp Filemanager Driver Service Provider in /app/Providers ,save the file FtpFilesystemServiceProvider.php .. Below is how mine looks like
<?php
namespace App\Providers;
use Storage;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Ftp as FtpAdapter;
use Illuminate\Support\ServiceProvider as ServiceProvider;
class FtpFilesystemServiceProvider extends ServiceProvider {
//boot
public function boot()
{
Storage::extend('ftp',function($app, $config){
//init the client
$client = new FtpAdapter($config);
//lets now call the obj
$ftpFileSystem = new Filesystem($client);
//return
return $ftpFileSystem;
});
}//end boot
public function register()
{
//
}
}
After which we will edit /config/app.php and add the service provider to providers array so you will add the code below to the list of providers:
'App\Providers\FtpFilesystemServiceProvider',
We are done, you are off to go , yo can call the storage like this
Storage::disk("ftp");
or set ftp as your default driver , ....

Use Illuminate database

I want to use Illuminate database(https://github.com/illuminate/database). Not with Laravel, use only in my php file.
I do
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);
But it seems not working, and don't show any error message. Do I need to require any file? The illuminate directory is in the same directory with my php file.
EDIT:
I can use query now. Like this
$users = Capsule::table('users')->where('votes', '>', 100)->get();
I don't know how to use model.
User.php
class User extends Illuminate\Database\Eloquent\Model {
}
My php file
require 'vendor/autoload.php';
require 'User.php';
$users = User::where('status', '=', 1)->get();
Got error
Fatal error: Call to a member function connection() on a non-object in /Users/someone/repos/test/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php on line 2472
SOLVED:
Everything works fine. Use #majid8911 example https://github.com/mattstauffer/IlluminateNonLaravel
Thank you everyone.
take a look at here I successfully did the same with this tutorial:
https://github.com/mattstauffer/IlluminateNonLaravel

Categories