Hi I am wondering if it's possible to share modules throw apps.
In my project I have 3 applications and I am using the same module in each of them!
Making a plugin would be perfect, but my shared module is overwriting one of external plugin that I use. Do you have any idea of how I could do?
Maybe ordering module autoload... I don't have a clue!
Thanks!
You should put it in a plugin.
The order of plugins in your ProjectConfiguration determines the order they are loaded in. If you need to override another plugin, make sure yours is loaded after that.
Related
I am working on a NopCommerce website and have quite a bit of site-wide customization so I have created a plugin to handle it all but not sure on how to handle the localization. I see there are a couple of ways of updating the Localization strings, one way I have found is in the Plugin's Install() method:
this.AddOrUpdatePluginLocaleResource("Plugins.Payments.PayPalStandard.Fields.AdditionalFee", "Additional fee");
This looks like it only adds new resource strings for the plugin, is there a similar way to update the other resources via the Install() method like:
Admin.Catalog.Products.List.DownloadPDF
I found that there is a way to export the entire language to a language_pack.xml file, would it be better to just create an entire language pack instead? Is there a way to add a new language pack from the plugins Install() method?
I guess I could simply open the language_pack.xml file and add each resource found using the AddOrUpdatePluginLocaleResource, I was hoping that there was a built-in way of doing this using NopCommernce functionality.
Thanks!
As #Raphael suggested in a comment, provide a language pack along with plugin file to the end users, and give an option to upload required resource file within your plugin configuration page.
As per as I know, there is no inbuilt way to add language pack on plugin installation, but you can do some code on plugin install method to find language pack file(s) from plugin folder and install it, not quite sure, you can take reference of inbuilt methods.
I would like to write a Zend Framework 2 vendor module, hosted on github, installable via composer and given to the world at large!
Now while I have no problems writing modules, where I am struggling is the mechanics around this.
My initial instinct would be to do something like this:
Set up a zend framework 2 skeleton app
Add my module as a normal module
Navigate to the module folder and create a git repo
Work on the module and update the module to my gitto...
Now logic tells me this is not the right way to go. So I am thinking, maybe I write the module as a stand alone outside of the skeleton app, push to the gito, and then pull from the gito to a working applicaiton...
If you can direct me to a tutorial, please let me know or if you can confirm or deny my proposed thinking that would be great too.
You probably need some app around your module to check if it works, however that shouldn't affect the way you create that module.
When it comes to Zend Framework 2 integrating modules, all you really need is a class that is called SomeNameSpace\Module which must be autoloadable via Composer. Note that there is NO requirement to place this file at a certain location. ZF2 will detect that you are using it with Composer and simply check with class_exists() instead of trying to locate a file, include it and then check for the class.
This class should reveal some configuration info about your module in the way ZF2 expects modules to do this, i.e. add bootstrap event listeners, return configuration data via getConfig() etc. It need not return anything for getAutoloaderConfig(), because that's what Composer is for.
To add the module to the ZF2 application you add the SomeNameSpace name to the file config/application.config.php:
return array(
'modules' => array(
'OtherStuffForTheDemoApp',
'SomeNameSpace' # this enables your module in your demo app
# and anywhere else where it's being used
),
ZF2 will see the module mentioned, try to instantiate SomeNameSpace\Module, ask it about all the configuration you defined, possibly calling the hook functions like onBootstrap() you provided there - and that's about it. Your module is responsible for doing the rest, i.e. provide a service manager configuration, provide controllers etc. All classes are autoloaded by Composer.
I believe the question of how to expose resources like images of a module hasn't been answered by Zend itself - at least I saw these questions being raised, but unanswered in the most current version of the documentation: http://framework.zend.com/manual/current/en/modules/zend.module-manager.intro.html
The organisation of files inside your module is completely up to you, although it seems common practice to place the source in a folder named src, tests probably go into tests.
I am building a Dart application. It needs to load code from a third-party package, which is only known at runtime. My application needs to:
auto-discover the dependency
load a library from that dependency
interact with the dependency
Ideally, I do not want to require that my users specify the third-party dependency. The application should auto-discover the dependency.
For example, a workflow could be something like this:
User installs my app (pub global activate my_app)
User installs a "plugin" (pub global activate plugin_for_my_app)
User runs my app (my_app)
The app auto-discovers that plugin_for_my_app exists.
The app loads the plugin (via spawnUri perhaps?)
The app calls into the plugin
Requirements:
Must run from the command-line.
Must work on Windows, Mac, Linux.
Should (but doesn't have to) run when compiled to JavaScript.
pub run support is optional (pub run makes it tricky, because it rewrites your import URIs, so it's not a requirement)
What's the best way to do this?
This package https://pub.dartlang.org/packages/plugins seems to do exactly what you want (haven't used it myself yet though) by loading plugins into isolates.
This is not directly answering the question (CL tools as requested), but I use plugins in the browser and wanted to share my "pattern".
My web application imports includes.dart which is a dynamically generated file that imports all .dart files found in a specified directory. The file gets (re-)generated at app startup by the backend, just before serving the files to the browser. The found .dart files implement a public api (eg. init() and run()) so that the main application can call their code. The plugin code are not loaded into separate isolates but are executed in the same isolate as the main app which gives the benefit of plugins sharing the same heap and you're able to access the plugin code directly. This solution also assumes the plugins resolve their own dependencies.
This setup works fairly well for my use case. However, as there's no real dynamic code reloading in Dart (yet, I hope. see https://code.google.com/p/dart/issues/detail?id=10530), there's always a refresh step needed to load the new code.
In the plugins package, currently, there is no way to resolve dependencies through pub. When I originally designed the API it was assumed that the dependencies were already retrieved through pub get. With that said, plugin discovery on the file system is simple.
As you can see in the example in the README, loading plugins was as simple as new PluginManager().loadAll(String directory) which would automatically discover all plugins inside the directory and load them. This solution is ideal if all plugins are to be in one folder.
It is possible to do individual plugin directory loading as well, provided it follows the plugin directory structure. Using a PluginLoader you can load in a directory that contains the necessary files for a plugin to run properly. It is not necessary to call load() since the PluginManager will take care of calling in load for you.
A simplified way of loading a plugin
Instantiate the PluginManager.
PluginManager pm = new PluginManager();
Determine the plugin you want loaded. The plugins library will automatically
determine the pub cache directory. As per the documentation of pub, the PUB_CACHE environment variable is also supported.
Load in the plugin. A Future is returned with a Plugin object that provides basic information about the plugin. The plugin requires a pubspec.yaml with a name, a packages directory, and a bin/main.dart source file. However we are loading from the pub cache, so we do not need to worry about the setup of the plugin, the only requirement is the package from the pub cache supports the plugins package.
pm.loadFromCache("test-1.0.0").then((Plugin plugin) {
print("Plugin loaded!");
handle();
});
After all the plugins you desire to be loaded are initialized, the manager can now listen for requests properly. Simply use the listener to 'see' the incoming data.
The plugin side
The plugin simply uses a receiver as provided by the plugins API.
void main(List<String> args, SendPort port) {
Receiver rec = new Receiver(port);
rec.listen((Map<dynamic, dynamic> data) {
print("Received data: $data");
});
}
I wrapped the plugins package with a bit of sugar to provide some extra things like declarative RPC. It's very flexible, and samrg472 (the author of plugins.dart) is a good friend, so I have asked him to comment as well.
https://github.com/PolymorphicBot/PolymorphicBot/blob/master/lib/src/core/plugins/handler.dart
I'm developing a plugin for Redmine and encountered an issue of how to implement plugin specific settings in Redmine in the most neat way.
Is it possible to have a plugin specific settings in {redmine_home}/plugin/{my_plugin}/config/settings.yml while sharing with a core a model (in MVC terms) logic which reads YAML file, sets attributes of the model class, provides easy access to them, etc. ({redmine_home}/app/models/setting.rb)
I think copypasting or require'ing the core model in the plugin model is definitely a poor design so right now i'm tending to have a plugin specific settings in the core config {redmine_home}/config/settings.yml and when it comes to plugin controller to read a settings it relies on the core model to do that. ({redmine_home}/app/models/setting.rb)
Is this a proper design? Is there any better ways to do this?
Thanks.
I just checked 3 different plugins in our project all used something like:
options = YAML::load( File.open(File.join(Rails.root, 'plugins/fancy_plugin/config', 'settings.yml')))
So just copy pasting.
I have a symfony application with two different applications (frontend, backend) but there is one action in common. Now I have duplicated its code in both apps but I don't like that at all.
Is there a way to reuse an action in multiple symfony applications?
The easiest way would be to make an actions base class in lib with the shared methods/actions. Then the modules that need to use this functionality can just extend that base class instead of sfActions.
You could also probably just use an event listener on method_not_found of sfComponent. But that may not work as expected if the method is an actual action (and it would also be available in all modules and all components without some special detection logic).
The most complicated way would be to make a Plugin. Of course that would require making the logic that works with any models dynamic so it can be configured or isolating the relevant parts of the schema to the plugin's schema.
Two more options:
1) if your are on Linux, make a symlink to your actions.class.php or even whole module, if you share the same templates.
cd apps/backend/modules/name
ln -s ../../frontend/modules/name name
2) if you have not gone too far in development, re-factor your project to have only ONE application (my favourite).
If you want to share a module (and hence also it's actions), the proper way is to create a plugin.