laravel doesn't detect my service provider - php

I'm want create a packagist based in laravel,
I've created a laravel project,
I've created the next directory:
app/
...
packages/
- imfranq/
-- mypackage/
--- src/
---- Providers/
I want use the provider created in my Providers folder
My package composer.json
...
"autoload": {
"psr-4": {
"Imfranq\\MyPackage\\": "src/"
}
}
laravel app.php
'providers' => [
...
Imfranq\MyPackage\Providers\MyPackageServiceProvider::class,
]
I've run make:provider command and I've moved the file to my package folder
My MyPackageServiceProvider.php
public function boot()
{
dd('test');
}
Up to this point nothing works.
I try:
composer dump-autoload command
composer cache:clear command
php artisan clear-compiled command
nothing works
I try in laravel package.json
"autoload": {
"psr-4": {
"App\\": "app/",
"Imfranq\\MyPackage\\": "packages/imfranq/mypackage/src/"
},
"classmap": [
"packages/imfranq/mypackage/src",
"database/seeds",
"database/factories"
]
},
also
"extra": {
"laravel": {
"providers": [
"Imfranq\\MyPackage\\MyPackageServiceProvider"
]
}
},
Not work...

Related

overridding vendor file in lumen not working

I want to override vendor class EloquentUserProvider.
I have created one same file in app/Ovverides folder
this is my composer.json
"exclude-from-classmap": [
"vendor\\Illuminate\\Auth\\EloquentUserProvider.php"
],
"psr-4": {
"App\\": "app/",
"App\\Ovverides\\": "app/Ovverides/"
}
after running composer dump-autoload , the file is not overridden

Laravel modules in subfolder and composer

I'm using Laravel modules by nwidart and I want to create module in subfolder. According issue on its Github this is not possible but is possible to change paths in composer.json. So I've created new module Role2 and moved it to subfolder Administration. Then I've changed module's composer.json:
{
"name": "nwidart/role2",
"description": "",
"authors": [
{
"name": "Nicolas Widart",
"email": "n.widart#gmail.com"
}
],
"extra": {
"laravel": {
"providers": [
"Modules\\Administration\\Role2\\Providers\\Role2ServiceProvider"
],
"aliases": {
}
}
},
"autoload": {
"psr-4": {
"Modules\\Administration\\Role2\\": ""
}
}
}
But after command composer dumpautoload I see nothing in command php artisan module:list and also in vendor/composer/autoload_psr4.php there is no path to this module. What I'm doing wrong or what is missing to generate multiple composer (one in root and one in module)? Or is there some simple option to have module in subfolder?
There is what I have in root composer.json:
...
"autoload": {
"classmap": [
"database",
"vendor",
"app/Easyk"
],
"exclude-from-classmap": [
"vendor/swiftmailer"
],
"psr-4": {
"App\\": "app",
"Modules\\": "Modules",
"Easyk\\": "app/Easyk",
"Asipem\\OAuth2ClientManagement\\": "packages/asipem/oauth2-client-management/src",
"Asipem\\CAPRequestDispatcher\\": "packages/asipem/cap-request-dispatcher/src"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
],
"psr-4": {
"Tests\\Unit\\": "tests/unit"
}
},
...
autoload -> psr-4 key from composer.json is used to define psr-4 root namespaces for the application.
What happens is you define a namespace and the directory location for Autoloader to look for the files under that namespace.
As in your root composer.json
"psr-4": {
"App\\": "app",
"Modules\\": "Modules",
"Easyk\\": "app/Easyk",
"Asipem\\OAuth2ClientManagement\\": "packages/asipem/oauth2-client-management/src",
"Asipem\\CAPRequestDispatcher\\": "packages/asipem/cap-request-dispatcher/src"
}
App is the base namespace and app is its base directory. By defining it, you tell autoloader that all files with namespace App will be residing inside the directory 'app'. After that, Autoloader will traverse the app directory in the PSR-4 way for file path following the namespace trail after base namespace App.
For example: Controller App\Controller\ExampleController will tell Autoloader that the class defination will be found at app/Controller/ExampleController.
So you need to specify the base directory location of your module against the namespace Modules\\Administration\\Role2\\ which is the base source directory of your module folder.
Hope it helped.

TYPO3 7.6 - How can I autoload composer packages?

I've created a TYPO3 7.6 extension with the extension builder. Now I want to add and autoload composer installed packages. I read that ext_autoload.php won't be loaded since TYPO3 version 7 in general. For this you should use the ext_emconf.php OR the composer.json in the root path of your extension.
So I've setup the following composer.json and installed it with the composer.phar.
{
"require": {
"hybridauth/hybridauth": "v3.0.0-rc.1"
},
"config": {
"vendor-dir": "Vendor"
},
"autoload": {
"psr-4": {
"Vendor\\Package\\": "Classes"
},
"classmap": [
"Vendor/hybridauth/hybridauth/src"
]
}
}
Now there is the Vendor/hybridauth/hybridauth/src as expected but the autoloader of TYPO3 doesn't find for example the Vendor/hybridauth/hybridauth/src/Hybridauth.php defined class Hybridauth. I've checked it with:
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(get_declared_classes());
What did I miss? What do I have to add/change/rethink?
Your json file content like below.
{
"require": {
"hybridauth/hybridauth": "v3.0.0-rc.1"
},
"config": {
"vendor-dir": "Vendor"
},
"autoload": {
"psr-4": {
"vendor\\extensionName\\": "Classes"
},
"classmap": [
"Vendor/hybridauth/hybridauth/src/"
],
"files": [
"Vendor/hybridauth/hybridauth/src/Hybridauth.php"
]
}
}
It was my fault. TYPO3 already autoloads already the psr-4 called environments. But I had to have add the autoloader of Hybridauth itself as well like:
<?php
namespace Vendor\Package\Service;
require_once dirname(dirname(dirname(__FILE__))) . '/Vendor/autoload.php';
class SomeService extends \TYPO3\CMS\Sv\AbstractAuthenticationService{
// ...
}

composer exclude-from-classmap not working

so I have the following in my composer.json
"autoload": {
"classmap": [
"database", "app/path1"
],
"psr-4": {
"App\\": "app/"
},
"exclude-from-classmap": [
"/app/path1/Front/"
]
},
and yet when i run composer dump-autoload -o it would still complain about
[Symfony\Component\Finder\Exception\AccessDeniedException]
RecursiveDirectoryIterator::__construct(C:/app\path1\Front\
node_modules\babel-preset-react\node_modules\babel-plugin-transform-react-j
sx\node_modules\babel-helper-builder-react-jsx\node_modules\babel-types\nod
e_modules\babel-traverse\node_modules\babel-code-frame\node_modules\chalk,C
:/app\path1\Front\node_modules\babel-preset-react\node_modu
les\babel-plugin-transform-react-jsx\node_modules\babel-helper-builder-reac
t-jsx\node_modules\babel-types\node_modules\babel-traverse\node_modules\bab
el-code-frame\node_modules\chalk): The system cannot find the path specifie
d. (code: 3)
[UnexpectedValueException]
RecursiveDirectoryIterator::__construct(C:/app\path1\Front\
node_modules\babel-preset-react\node_modules\babel-plugin-transform-react-j
sx\node_modules\babel-helper-builder-react-jsx\node_modules\babel-types\nod
e_modules\babel-traverse\node_modules\babel-code-frame\node_modules\chalk,C
:/app\path1\Front\node_modules\babel-preset-react\node_modu
les\babel-plugin-transform-react-jsx\node_modules\babel-helper-builder-reac
t-jsx\node_modules\babel-types\node_modules\babel-traverse\node_modules\bab
el-code-frame\node_modules\chalk): The system cannot find the path specifie
d. (code: 3)
Which means that it is not really excluding /app/path1/Front/
What am I doing wrong and how can I exclude that directory so that it won't return those exceptions

Composer/Laravel Fatal Error

I added this to my composer.json file
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Claremontdesign\\Cdbase\\": "packages/Claremontdesign/cdbase/src",
"Claremontdesign\\Narbase\\": "packages/Claremontdesign/narbase/src",
"Claremontdesign\\Nhr\\": "packages/Claremontdesign/nhr/src"
},
"files": [
"packages/Claremontdesign/cdbase/src/Helpers/helpers.php",
"packages/Claremontdesign/narbase/src/Helpers/helpers.php",
"packages/Claremontdesign/nhr/src/Helpers/helpers.php"
]
},
then, I ran composer update from the command line, and it gave me this error:
symfony component debug exception fatalerrorexception class "Claremontdesign\Cdbase\ServiceProvider" not found
Has anyone else encountered this?
Also, I added a service provider in add.php
Claremontdesign\Cdbase\ServiceProvider::class
Did you try running just composer dump? composer update runs some scripts before it actually runs - for example php artisan clear-compiled. When artisan runs, it'll probably fail because it tries to register the serviceprovider which isn't autoloaded yet. composer dump only generates the autoload files, which is what you need in this case.
i think you are missing one more slash after every src folder
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Claremontdesign\\Cdbase\\": "packages/Claremontdesign/cdbase/src/",
"Claremontdesign\\Narbase\\": "packages/Claremontdesign/narbase/src/",
"Claremontdesign\\Nhr\\": "packages/Claremontdesign/nhr/src/"
},
"files": [
"packages/Claremontdesign/cdbase/src/Helpers/helpers.php",
"packages/Claremontdesign/narbase/src/Helpers/helpers.php",
"packages/Claremontdesign/nhr/src/Helpers/helpers.php"
]
},

Categories