Making custom plugin with “QuizzesInit” name I have problems, I suppose because of double names plugin.
My plugin is located in /projects_path/quizzes/packages/vendorname/QuizzesInit/src/Providers/QuizzesInitProvider.php file and has content:
<?php
// My phpstorm shows error here : Namespace name doesn't match the PSR-0/PSR-4 project structure
namespace vendorname\QuizzesInit\Providers;
use Illuminate\Support\ServiceProvider;
class QuizzesInitProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* #return void
*/
public function boot()
{
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
$this->loadViewsFrom(__DIR__ . '/views', 'QuizzesInit' );
}
public function register()
{
}
}
Adding route in /projects_path/quizzes/packages/vendorname/QuizzesInit/src/routes/web.php :
Route::get('/quizzes', function () {
//packages/vendorname/QuizzesInit/src/views/index.blade.php
return view('QuizzesInit::index');
}); // ->middleware(['auth', 'verified'])->name('dashboard');
I got error on url "http://local-site.com/quizzes"
View [index] not found.
I do not know is this error is related with “QuizzesInit” name and Namespace name breaking PSR-0/PSR-4 project structure I show in my provider ?
In all docs (like https://laravel.com/docs/9.x/packages#service-providers) in 1 word plugin names are used...
How can it be fixed ?
UPDATED INFO # 1:
At docs https://laravel.com/docs/9.x/packages#service-providers that is not clear actually which composer commands I need to run
I run
composer init
in clear vendorname/QuizzesInit directory
and created new composer project
I run in project root :
composer dump-autoload
with success, but it did not show my package
when I run composer require with my package in project root :
$ composer require vendorname\QuizzesInit
In PackageDiscoveryTrait.php line 364:
Could not find a matching version of package vendornameQuizzesInit. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (dev).
in composer.json I have :
"autoload": {
"psr-4": {
"App\": "app/",
"Database\Factories\": "database/factories/",
"vendorname\QuizzesInit\": "packages/vendorname/QuizzesInit/src/",
"Database\Seeders\": "database/seeders/"
}
},
5)Inside of my /packages/vendorname/QuizzesInit/src I have files :
-rwxrwxrwx 1 root root 585 Feb 14 08:47 composer.json
-rwxrwxrwx 1 root root 95971 Feb 14 07:34 composer.lock
drwxrwxrwx 1 root root 0 Feb 14 07:35 Providers
drwxrwxrwx 1 root root 0 Feb 14 08:53 routes
drwxrwxrwx 1 root root 0 Feb 14 07:34 src
drwxrwxrwx 1 root root 4096 Feb 14 07:34 vendor
drwxrwxrwx 1 root root 0 Feb 15 06:39 views
But am not sure now which command did I run, I run differend commands in root dir and /packages/vendorname/QuizzesInit...
I found in net some step by step manuals(like https://adevait.com/laravel/how-to-create-a-custom-package-for-laravel),
but it is somewhat confusing for me, which commands have I to run at first and during development of the package ?
UPDATED INFO # 2 :
In packages/vendorname/QuizzesInit/src/routes/web.php I added :
Route::get('/quizzes_count', function () {
return 'quizzes_count';
});
So running http://local-com.com/quizzes_count
I got valid 'quizzes_count' string in my browse, so I think my plugin is installed correctly and in
provider file packages/vendorname/QuizzesInit/src/Providers/QuizzesInitProvider.php having 2 options :
public function boot()
{
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
// routes with line above works ok
// view with line below does not work at all
$this->loadViewsFrom(__DIR__ . '/views', 'QuizzesInit' );
}
?
UPDATED INFO # 3 :
# Project/packages/vendorname/QuizzesInit/src/views$ ls -la
total 8
drwxrwxrwx 1 root root 0 Feb 15 06:39 .
drwxrwxrwx 1 root root 4096 Feb 15 06:39 ..
-rwxrwxrwx 1 root root 643 Feb 15 06:40 index.blade.php
UPDATED INFO # 4:
I write
__DIR__ . '/views'
value into log on and have :
Project/packages/vendorname/QuizzesInit/src/Providers/views
But it is different from real path :
Project/packages/vendorname/QuizzesInit/src/views/index.blade.php
Where from "Providers/"? Or have I to add this "Providers/" subdirectory in my options? Where ?
Thanks!
This makes a lot of sense after all the info you've supplied.
$this->loadViewsFrom(__DIR__ . '/views', 'QuizzesInit' ); is located in packages/vendorname/QuizzesInit/src/Providers/QuizzesInitProvider.php
If you look up what the documentation says about __DIR__, Returns the directory of the file., it will all make sense.
Your QuizzesInitProvider.php is located in packages/vendorname/QuizzesInit/src/Providers, so that's what __DIR__ will return to you.
However, you are looking for the Views directory, which is not under /Providers, but one step up,
So in order to get to the Views directory, you have to do exactly the same thing you did with the routes (can't believe neither of us spotted this sooner), so $this->loadViewsFrom(__DIR__ . '/views', 'QuizzesInit' ); will now become $this->loadViewsFrom(__DIR__.'/../views', 'QuizzesInit' ); with the dots signifying that you want to move one directory up from the current directory (/Providers) and then move into the /views directory.
TL;DR:
Change: $this->loadViewsFrom(__DIR__ . '/views', 'QuizzesInit' );
to: $this->loadViewsFrom(__DIR__.'/../views', 'QuizzesInit' );
Related
I am trying to upload a file and move it to public/ folder. The file uploads without problem to writable folder, however, it is the moving to the public folder that has a problem.
Here is my code;
$update_post->move(ROOTPATH.'public/', $update_post.'.'.$fileType);
Path is correct. When I echo out echo ROOTPATH.'public/'; and then manually copy/paste, I do get to the destination directory.
Permissions correct. There are my permission on the public/ directory:
drwxr-xr-x 9 www-data www-data 4096 Jan 30 01:08 public
Any hints appreciated.
Reason:
It's because the move(string $targetPath, ?string $name = null, bool $overwrite = false) method's $name argument is invalid.
$update_post->move( ... , $update_post.'.'.$fileType);
Explanation:
Concatenating an class CodeIgniter\Files\File extends SplFileInfo instance calls the inherited SplFileInfo class's __toString() method which returns the path to the file as a string.
Note that it doesn't return the filename, which is what you're interested in.
Solution:
You should instead pass in the basename instead.
$update_post->move(
ROOTPATH . 'public/',
$update_post->getBasename()
);
Alternatively, since you're not changing the destination filename, it's cleaner to just not pass in the second parameter of the move(...) method. I.e:
$update_post->move(
ROOTPATH . 'public'
);
Addendum:
If you wish to change the destination filename to a new name, try this instead:
guessExtension()
Attempts to determine the file extension based on the trusted
getMimeType() method. If the mime type is unknown, will return null.
This is often a more trusted source than simply using the extension
provided by the filename. Uses the values in app/Config/Mimes.php to
determine extension:
$newFileName = "site_logo"; // New filename without suffixing it with a file extension.
$fileExtension = $update_post->guessExtension();
$update_post->move(
ROOTPATH . 'public',
$newFileName . (empty($fileExtension) ? '' : '.' . $fileExtension)
);
Notes:
The move(...) method returns a new File instance for the relocated file, so you must capture the result if the resulting location is needed: $newRelocatedFileInstance = $update_post->move(...);
I got this DatabaseSeeder.php in laravel where I create a Directory:
public function run()
{
Storage::deleteDirectory('posts');
Storage::makeDirectory('posts');
// Etcetera ...
}
And then I run
$ php artisan migrate:fresh --seed
This works flawlessly in my development environment (Laravel Homestead).
However, if I run that same command inside a Docker container using Laradock, I get the following error:
Seeding: Database\Seeders\PostsSeeder
InvalidArgumentException
Cannot write to directory "public/storage/posts"
at vendor/fakerphp/faker/src/Faker/Provider/Image.php:90
86▕ ) {
87▕ $dir = is_null($dir) ? sys_get_temp_dir() : $dir; // GNU/Linux / OS X / Windows compatible
88▕ // Validate directory path
89▕ if (!is_dir($dir) || !is_writable($dir)) { ➜ 90▕ throw new \InvalidArgumentException(sprintf('Cannot write to directory
"%s"', $dir));
91▕ }
92▕
93▕ // Generate a random filename. Use the server address so that a file
94▕ // generated at the same time on a different server won't have a collision.
+3 vendor frames
database/factories/ImageFactory.php:25
Faker\Generator::__call()
Why is this happening?
How do I fix it?
Workaround
To easily solve it simply create those directories:
$ ls -lah public/
$ cd public/ && mkdir storage && cd storage && mkdir posts && cd ../..
Try again
$ artisan migrate:refresh --seed
This error is because one of your "Factory" files, in the "faker" method in this case, the "posts" folder does not exist.
Faker does not have the ability to create a new folder and since the folder does not exist, I get that error.
So in this case you have to create the posts folder first. To do this, inside your "DatabaseSeeder.php" file, place the following line of code inside the run () method at the beginning:
use Illuminate\Support\Facades\Storage;
public function run()
{
Storage::deleteDirectory('public/posts');
Storage::makeDirectory('public/posts');
...
}
I had the same problem, I create the folder using the workaround, and it works, but running artisan migrate: refresh --seed doesn't remove the directories but creates more.
public function run()
{
Storage::deleteDirectory('posts');
Storage::makeDirectory('posts');
// Etcetera ...
}
ErrorException in CryptKey.php line 57:
Key file "file://C:\wamp\www\project\public_html\storage\oauth-private.key" permissions are not correct, should be 600 or 660 instead of 666
My Configuration as follows:
Windows 10 64bit
WampServer 3.1.0
Apache 2.4.27
PHP 7.0.23
Laravel Framework version 5.3.31
composer require laravel/passport=~1.0
Any idea how to solve it?
You can turn off file checking permissions on line 57
your CryptKey Path is vendor/league/oauth2-server/src/CryptKey.php
on line number 48 turn it to false or comment the following block in your CryptKey.php
if ($keyPermissionsCheck === true) {
// Verify the permissions of the key
$keyPathPerms = decoct(fileperms($keyPath) & 0777);
if (in_array($keyPathPerms, ['600', '660'], true) === false) {
trigger_error(sprintf(
'Key file "%s" permissions are not correct, should be 600 or 660 instead of %s',
$keyPath,
$keyPathPerms
), E_USER_NOTICE);
}
}
keyPermissionsCheck set it to false.
Hope this helps.
Simply CHMOD the oauth-private.key file to 600 or 660. I see that you use Windows so you can surely follow the directions in this post to do that.
I'm having a hard time installing Laravel 4 on Windows 8 + Xampp.
Here's the setup:
- Xampp 1.8.1
- Composer is installed globally
I install Laravel with the usual "composer create-project laravel/laravel projectname". It installs fine.
But when I navigate to the public folder of the framework, I get dozens of Warning: Illegal offset type in isset or empty in \bootstrap\compiled.php errors.
On lines : 439, 221, 137, 154. The 4 errors are repeated indefinitely until the request times out.
Troubleshooting done so far:
- Tried on 2 seperate machines with the same setup.
- Re-ran Composer update.
- Instead of using create-project, I downloaded the framework and ran Composer install.
- Tried to setup up virtual hosts instead of accessing localhost/projectname/public.
- Searched online for 2 hours. Read every Laravel 4 install tutorial.
Any clues on what I might be doing wrong?
Thanks
-- EDIT --
Here are the lines causing the problem inside of compiled.php
Line 137 section :
$abstract = $this->getAlias($abstract);
if (isset($this->instances[$abstract])) {
return $this->instances[$abstract];
}
Line 154 section :
protected function getConcrete($abstract)
{
if (!isset($this->bindings[$abstract])) {
return $abstract;
} else {
return $this->bindings[$abstract]['concrete'];
}
}
Line 221 section :
protected function getAlias($abstract)
{
return isset($this->aliases[$abstract]) ? $this->aliases[$abstract] : $abstract;
}
Line 439 section :
public function make($abstract, $parameters = array())
{
if (isset($this->deferredServices[$abstract])) {
$this->loadDeferredProvider($abstract);
}
return parent::make($abstract, $parameters);
}
-- NEW FIND --
Using Wampserver works, instead of using Xampp.
Encountered the same error when using Xampp. I fixed it by disabling the eAccelerator extension in php.ini. Try commenting out the following line: zend_extension = "path\to\xampp\php\ext\php_eaccelerator_ts.dll" in your php.ini file.
I am trying to set a sequential order on some of my modules for certain nodes.
node basenode{
include ps
include netfx
include hg
include reportviewer2012
include wdeploy30
include sqlexpress2008
include windowsrolesfeatures
include tcbase
}
node 'myserver' inherits basenode {
include tcuiagent
Class['tcuiagent'] -> Class['tcbase'] -> Class['windowsrolesfeatures'] -> Class['ps']
}
Certainly I DON'T want to set dependencies within the module resources because that will make them interdependent which I don't want to do. In this case, I want to accomplish this order.
ps (first one)
windowsrolesfeatures
anyotherpackage {hg,netfx...}(dont care the order of provisioning)
n. tcbase
tcuigant(last one)
If you really don't want to express relationships between modules, you can use stages to enforce an order.
You must first declare the stages in your top manifest :
## Very important : we define stages.
## Can only be done here.
stage { 'first': } # the first of first
stage { 'apt': } # to install apt sources and run apt-get update if necessary
# stage main # default stage, always available
stage { 'last': } # a stage after all the others
# Now we define the order :
Stage[first] -> Stage[apt] -> Stage[main] -> Stage[last]
Then use them :
# basics needing a run state
# We use the "class" syntax here because we need to specify a run stage.
class
{
'puppeted': # debug
stage => first, # note the explicit stage !
;
'apt_powered': # Very important for managing apt sources
stage => apt, # note the explicit stage !
#offline => 'true', # uncomment this if you are offline or don't want updates
;
'apt_powered::upgraded': # will systematically upgrade paquets. dev machine -> we want to stay up to date
stage => apt, # note the explicit stage !
;
}
But this is ugly and this is not what stages are made for.
I would strongly suggest rewriting the modules so that the order they are installed is not important anymore or create the necessary relationships to the resources.
If you are installing/configuring related resources from different modules, you could consider merging those modules.
Ger.
I guess I solve it using a different approach with node inheritance.
node windowsmachine{
include ps #powershell
include windowsrolesfeatures #windows roles and features
include netfx #netframework 4.0 and 4.5
}
node teamcitybase inherits windowsmachine {
include hg #mercurial
include nuget #nuget configuration
include reportviewer2012
include wdeploy30 #web deployment 3.0
include tcbase #asp.net configuration
include sqlexpress2008 #sqlexpress
}
node 'myserver1','myserver2' inherits teamcitybase{
#pending installation of puppet clients
}
node 'myserver3' inherits teamcitybase {
include tcuiagent
}
Windows Machine configuration modules do not depend on each other but myserver1 with the sqlexpress2008 depends on that baseline.
No stages or Module dependency!!!!!
After releasing the same problem i came across the following post which work the best from all that i have found.
1 #####################
2 # 1) Define the stages
3 #####################
4
5 stage { 'prereqs':
6 before => Stage['main'],
7 }
8
9 stage { 'final':
10 require => Stage['main'],
11 }
12
13 #####################
14 # 2) Define the classes
15 #####################
16
17 # We don't care when this class is executed, it will
18 # be included at random in the main stage
19 class doThisWhenever1 {
20
21 }
22
23 # We don't care when this class is executed either, it will
24 # be included at random in the main stage
25 class doThisWhenever2 {
26
27 }
28
29 # We want this class to be executed before the
30 # main stage
31 class doThisFirst {
32
33 exec {'firstThingsFirst':
34 command => '/bin/echo firstThingsFirst',
35 }
36 }
37
38 # We want this class to be executed after the
39 # main stage
40 class doThisLast {
41
42 exec {'lastly':
43 command => '/bin/echo lastly',
44 }
45
46 }
47
48 #####################
49 # 3) Assign the classes
50 # to a stage
51 #####################
52
53 class { 'doThisFirst':
54 stage => prereqs,
55 }
56
57 class { 'doThisLast':
58 stage => final,
59 }
60
61
62 include doThisFirst
63 include doThisLast
http://pipe-devnull.com/2013/09/20/puppet-ensure-class-execution-ordering.html
Regards