I want to add my custom function in Magento\Framework\Message\Manager file in core file its working perfectly but when i m try to override its not working
So , I want to know how to override class that implements interface in magento2
below file I need to override:
vendor/magento/framework/Message/Manager.php
Related
If the Application has a Custom Application object. It is needed to annotate this with #HiltAndroidApp
ex:
#HiltAndroidApp
class AppCore: Application
Appcore has some initialization logic which is needed for the app to run
Now in the Instrumentation tests We also need to Extend the custom Application object.
#CustomTestApplication(AppCore::class)
interface HiltTestApplication
This gives an error #CustomTestApplication value cannot be annotated with #HiltAndroidApp
Is there any other way of using HILT in instrumentation tests with custom Application objects
public abstract interface HiltTestApplication {
^
#CustomTestApplication value cannot be annotated with #HiltAndroidApp. Found: AppCore
As suggested in the issue tracker. Can you abstract your initialization logic into a base class, say BaseAppCore : Application then in your prod application extend it #HiltAndroidApp AppCore : BaseAppCore and then for tests make Hilt generate a test app based on your abstract one, #CustomTestApplication(BaseAppCore::class) interface AppCoreTestApplication. It might be best to file this issue in https://github.com/google/dagger/issues
You will need to create a new class with the #HiltAndroidApp annotation, which would be different from the one you will use in your tests.
open class AppCore: Application
{
// Existing code.
}
#HiltAndroidApp
class ProdAppCore : AppCore
{}
#CustomTestApplication(AppCore::class)
interface HiltTestApplication
If you are using Robolectric, you can set:
application = $packageName.HiltTestApplication_Application
And in your AndroidManifest.xml, set:
<application
android:name="$packageName.ProdAppCore"
where $packageName is the package where ProdAppCore and HiltTestApplication class have been defined.
This is also discussed here: https://github.com/google/dagger/issues/2033
I am using GetIt library in order to provide DI in my application.
I just reached point where I want to allow user to choose between LocalDataSource or NetworkDataSource, where these two classes are subclasses of an abstract class DataSource. Also, I created an enum called DataSourceType, which contains two values {local, network}. Along with that, there is a static field of DataSourceType in main class of the app, which should serve as flag for DataSource type.
So, I created screen with two radio buttons and user can select DataSource types, and that will set static value the field in main class.
The problem:
I don't know how to register and return subclasses of the DataSource class using GetIt and dynamically(in runtime) return one or another subclass, depending on DataSoruceType flag.
So, if user changes the source getit will return appropriate implementation in runtime.
Example code is here:
class DataSource {
static DataSourceType dataSource = DataSourceType.local;
...
}
class NetworkDataSource implements DataSource {
...
}
class LocalDataSource implements DataSource {
...
}
enum DataSourceType {local, network}
Can somebody help me to solve this problem?
I would appreciate any help.
How do I extend /include/SearchForm/SearchForm2.php in upgrade safe manner?
You could create /custom/include/SeachForm/CustomSearchForm2.php which extends SearchForm2 (the class name for SearchForm2) traditionally (e.g. CustomSearchForm2 extends SearchForm). The harder task is accessing your custom class at that point.
SearchForm is instantiated from include/MVC/View/views/view.list.php - in a couple of possible places: the protected method getSearchForm2() and [assumed] public method prepareSearchForm().
So how do you extend view.list.php? That one's easier. For any module you'd like a custom list view, create a file at /custom/modules/MyModule/views/view.list.php and define it as CustomMyModuleViewList extends ViewList. Some modules already have their own ViewList (e.g. Accounts, Calls) so for those you'd want to extend their original extended ViewList, e.g. CustomAccountsViewList extends AccountsViewList.
So create your custom ViewList extension, copy-paste the methods you need to alter (prepareSearchForm and getSearchForm2) and adjust as needed to load in your custom SearchForm class.
Assuming the question relates to SugarCRM 6.5.x (and potentially earlier 6.x versions - I haven't checked), Matthew Poer's answer is exactly right except for one thing: the class to extend is called SearchForm instead of SearchForm2. To do this:
Copy include/SearchForm/SearchForm2.php to custom/include/SearchForm/SearchForm2.php
Edit custom/include/SearchForm/SearchForm2.php and edit the class declaration, changing it to:
require_once('include/SearchForm/SearchForm2.php');
class CustomSearchForm extends SearchForm {
Copy include/MVC/View/views/view.list.php to custom/include/MVC/View/views/view.list.php
Edit custom/include/MVC/View/views/view.list.php and edit the class declaration, changing it to:
require_once('include/MVC/View/views/view.list.php');
class CustomViewList extends ViewList {
In the function prepareSearchForm in the CustomViewList class, change the line
require_once('include/SearchForm/SearchForm2.php');
to
require_once('custom/include/SearchForm/SearchForm2.php');
and the line
$searchMetaData = SearchForm::retrieveSearchDefs($this->module);
to
$searchMetaData = CustomSearchForm::retrieveSearchDefs($this->module);
In the function getSearchForm2 in the CustomViewList class, change the line
return new SearchForm($seed, $module, $action);
to
return new CustomSearchForm($seed, $module, $action);
The other functions of CustomSeachForm and CustomViewList can be subsequently overriden as needed. If you have module-specific view.list.php files, you will, of course, need to change them to extend CustomViewList instead of ViewList.
I'm using native session library to replace the built in session library in CI. I need to extend the class but when I drop in MY_Session.php, CI reverts back to the old /system/libraries/Session.php.
How to I extend a class that's replaced a core CI class like Session.php?
Simply by naming your class files identically to a native library will
cause CodeIgniter to use it instead of the native one. To use this
feature you must name the file and the class declaration exactly the
same as the native library. For example, to replace the native Email
library you'll create a file named application/libraries/Email.php
-user guide
then call it
class MY_Email extends CI_Email {
public function __construct()
{
parent::__construct();
}
}
Loading Your Sub-class:
$this->load->library('email');
EDIT
Try this:
Just load your new library (the one doing the extending):
Then, let's say we have Session.php and Mysession.php
<?php
load_class('session', false);
class Mysession extends Session {
//your code
}
You don't need the MY_ name tag still, I think you want to reserve that for it's original intended purpose to avoid confusion.
.. else just use an include() or require() :P
I'm creating a plugin for my symfony project, which includes a base action class, i.e.:
<?php
// myActions.class.php
class myActions extends sfActions {
/* ... */
}
Where in my plugin folder (e.g.: plugins/sfMyPlugin/???) should I place this file?
The goal is to have actions that are NOT a part of this plugin extend this class, hopefully having the class be autoloaded (similar to if it were placed under apps/my_app/lib). If it can't be autoloaded, how do I get symfony to include my php file?
You typically put it in your plugin's lib directory. The general conventions is also to to name with Base in the name so given your example that would be BasemyActions. Then you would also make an empty concrete class called myActions and you would extend that within your plugin thus allowing other user to complety replace myActions with their own implementation (so long as it extends the base class) or to simply extend myActions.
you can place it in the lib directory of your plugin. This is what the generate:plugin-module task of the sfTaskExtraPlugin does.