Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mozart-created class non-functional #38

Open
leewillis77 opened this issue Jan 15, 2020 · 1 comment
Open

Mozart-created class non-functional #38

leewillis77 opened this issue Jan 15, 2020 · 1 comment

Comments

@leewillis77
Copy link
Contributor

Installing using mozart as recommended in the docs results in the following code which means that if there is a non-prefixed version somewhere in the software, the prefixed class doesn't get defined:

if ( ! class_exists( 'Gamajo_Template_Loader' ) ) {

	class MyPrefix_Gamajo_Template_Loader {

Attempting to add a class that extends MyPrefix_Gamajo_Template_Loader on a software stack that already includes a non-prefixed version of Gamajo_Template_Loader results in :

Fatal error: Class 'MyPrefix_Gamajo_Template_Loader' not found in /src/TemplateLoader.php

If all non-prefix instances are removed then this code works as expected.

@MikeiLL
Copy link

MikeiLL commented Jul 15, 2020

I'm confused about how to install this using Mozart.

This is my composer.json file:

#abbreviated

	"type": "wordpress-plugin",
	"require": {
		"php": ">=7.1",
		"composer/installers": "~1.0",
    	"gamajo/template-loader": "dev-master"
	},
	"autoload": {
		"psr-4": {
			"Cool_Plugin\\": "src"
		}
	},
	"extra": {
		"mozart": {
			"dep_namespace": "Cool_Plugin\\Dependencies\\",
			"dep_directory": "/src/Dependencies/",
			"classmap_directory": "/classes/dependencies/",
			"classmap_prefix": "Cool_Plugin",
			"delete_vendor_directories": true,
			"packages": [
			    "gamajo/template-loader"
			]
		}
	},
  "require-dev": {
    "coenjacobs/mozart": "dev-master"
  }
}

I have tried with and without the "packages" array. The only thing I see in /src/Dependencies is composer installers.

In the vendor directory there is:

vendor/gamajo/
└── template-loader
    ├── CHANGELOG.md
    ├── LICENSE
    ├── README.md
    ├── class-gamajo-template-loader.php
    └── composer.json

No namespaces in the class-gamajo-template-loader.php file.

Previously I have added this (fantastic) tool manually, but am hoping to do it the recommended way this time.

Any help appreciated.

Update

In the meantime, I'm using the files autoloading:


	"autoload": {
		"psr-4": {
			"MZ_Mobilize_America\\": "src"
		},
		"files": ["vendor/gamajo/template-loader/class-gamajo-template-loader.php"]

Then within my namespace I have to escape so php can find it in the global namespace:

namespace Cool_Plugin\Libraries;

use Cool_Plugin as NS;

class Template_Loader extends \Gamajo_Template_Loader {

    protected $filter_prefix = 'cool_plugin';

    protected $theme_template_directory = 'templates/cool_plugin';

    protected $plugin_directory = NS\PLUGIN_NAME_DIR; 
    // From main plugin file: define( NS . 'PLUGIN_NAME_DIR', plugin_dir_path( __FILE__ ) );

    protected $plugin_template_directory = 'src/Frontend/views';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants