I'm wondering if there is a proper way to check the dependencies.
For example I've got a NewsBundle. Now I'll have to check if there is a CommentBundle. If there is one, it should execute a few more Code.
Any suggestions?
In addition to markymark's answer, you can check if a specific service exists from your controller (or any other container-aware code) with the following snippet:
if ($this->container->has('foo_service.alias'))
{
// service is loaded and usable
}
If you're not sure of the exact alias of a given service, or just for kicks and giggles, you can run the console command php app/console container:debug to see all services registered with the container.
You could use class_exists on the main Bundle class that every bundle should have.
For example:
if (class_exists('Acme\CommentBundle\AcmeCommentBundle'))
{
// Bundle exists and is loaded by AppKernel...
}
The Kernel class contains a list of helper methods to check if a certain class is part of an active bundle or if a bundle is registered.
public BundleInterface[] getBundles()
Gets the registered bundle instances.
public bool isClassInActiveBundle(string $class)
Checks if a given class name belongs to an active bundle.
Related
Good day all, I tried connecting to the back4app back end service using the new parse4cn1 lib .....I supplied the keys required but my app could not connect to the backend for some strange reasons.kept reporting (unable to connect to back end.........codename one revisions some long numbers)
Some help or direction will be appreciated.Thanks all
What keys are you using? You need to pass your App Id and Client Key to parse4cn1. I just ran the regression tests against back4app and I didn't get any connection error. Can you provide more details (e.g. a dump) of the error you're getting?
Where are you putting your Parse.initialize? Just went for some digging on parse4cn1 and it seems that it needs to be inside a "initVars" function, usually created within a state machine as you can see in the example below:
public class StateMachine extends StateMachineBase {
/**
* this method should be used to initialize variables instead of
* the constructor/class scope to avoid race conditions
*/
protected void initVars(Resources res) {
Parse.initialize(API_ENDPOINT, APP_ID, CLIENT_KEY);
}
}
Maybe that can help you on this connection issue. Also check the link below (A very useful guide) for further info:
https://github.com/sidiabale/parse4cn1/wiki/Usage-Examples
I am new to Laravel 5.1 Events registration procedure and facing a problem when trying to register custom events at runtime which are not defined in the EventServiceProvider class.
I have the following slightly modified Laravel 5.1 folder structure which includes a root client folder where I store all the client specific classes, events and view files. Folder structure is as following:
--app
-- Events
-- RecordUpdatedEvent.php
-- more core events here...
-- Listeners
-- RecordUpdatedHandler.php
-- more core listeners here...
--bootstrap
--client
--Events
--RecordUpdatedEvent.php
--more client specific events...
--Listeners
--RecordUpdatedHandler.php
--more client specific listeners...
--resources
--config
--database
--resources
...etc
I have the following composer psr-4 setup for namespacing and autoloading:
"psr-4": {
"App\\": "app/",
"Client\\": "client/"
},
And of course performed composer dump-autoload -o. So far so good and it all works.
I am trying to find a way to register client specific event handlers without manually changing the EventServiceProvider class every time I want to add a new client specific event (since EventServiceProvider is a core class that is shared between all clients).
So for example, when an App\Events\RecordUpdatedEvent occur I will want to also fire a Client\Events\RecordUpdatedEvent (or more events) by dynamically resolving the events to be fired from the database.
The problem is that when I programmatically fire a client specific event (i.e Event::fire(Client\Events\RecordUpdatedEvent)) it gets fired correctly but never dispatches the Client\Listeners\RecordUpdatedHandler class since it is never registered anywhere.
My question will be how to register new event handlers during runtime or whether there is a way to specify within the event class itself (i.e RecordUpdatedEvent) which Handler class to dispatch. Ideally I would be able to set a class property such as $this->handler = "Client\Listeners\RecordUpdatedHandler".
Thanks.
Hope I get the question. One alternative is to create a Service Provider, then, in the boot() method you register a subscriber class:
\Event::subscribe(new CustomSubscriber());
Ok, lets say that you want to fire a custom event in a controller class. Just put it an name:
public function myControllerMethod(){
\Event::fire('test.event');
}
Finally, just join test.event with the subscriber's specific function. For example, onTestEvent() method will listen for test.event event:
class CustomSubscriber {
public function onTestEvent(){
Log::info('hello, this is a test event without editing kernel file');
}
// this is the trick
public function subscribe($events){
$events->listen('test.event', 'CustomSubscriber#onTestEvent');
}
}
This technique is cool if you work with custom package development.
I am trying to implement a custom membership provider in Sitefinity, and have followed through the documentation at: http://docs.sitefinity.com/tutorial-create-a-custom-membership-provider
When I come to register the provider in the Sitefinity backend, I get the message The following required properties are not set: type
I have checked, double checked and checked again the namespace and class names, and can even declare a variable as the provider type in the code-behind, yet it just won't have it.
My provider is defined thus:
namespace SitefinityWebApp
{
public class WebsiteMembersProvider : MembershipDataProvider
{
public WebsiteMembersProvider()
{
//... etc
I am registering the provider in the SF backend as:
SitefinityWebApp.WebsiteMembersProvider, SitefinityWebApp
And I can go into the code behind on one of my master pages and code:
SitefinityWebApp.WebsiteMembersProvider MyTestProvider;
and indeed, the class appears in the intellisense offerings just fine.
and the project all compiles/runs fine - but SF won't let me use the custom provider! I have also tried adding the provider manually in the securityconfig.config file - similar result.
Any idea anyone?
I went through the tutorial to try it myself and ran into the same problem as you.
Are you sure that you're putting this
SitefinityWebApp.WebsiteMembersProvider, SitefinityWebApp
in the ProviderType field (and not the 'Global resource class ID' field, which is what I initially did)? It seems like that error message shows up if I remove the text from that field and attempt to save (and also when it can't resolve that type).
Otherwise, I'm not sure what else it could be, aside from maybe recycling the app pool.
I am wondering if anyone else has had an issue with running the DB initializer from the global asax?
I have this in the ApplicationStart:
Database.SetInitializer(new MyInitializer());
That runs fine, after that once my application has started I try a login Method i created in my services. It fails when it tries to open the context.
My test application is setup almost the same way and doesn't have an issue.
Any thoughts?
Update:
I tried adding the MultipleActiveResultSets=True and now I am getting this error:
The underlying provider failed on Open.
Update 2:
Well, it turns out that my application loads while the initializer is still finishing. That is why I was getting those errors. So, what I figured out is that part of the app loads and then it must request something from the DB (at which point it created the DB and seeds it). At that point part of the application has loaded, but you don't know that the initializer is still running.
Like I sad in my updates, the DB wasn't getting created until after most of the application had run already. It was still running even though, as a user, you wouldn't know it. So I created an initialization project and added this class:
public static class InitializeAndSeed
{
public static void Initialize()
{
Database.SetInitializer(new MyContextInitializer());
using (var db = new MyContext())
{
db.Database.Initialize(false);
}
}
}
In my Applicaiton_Start() I call the InitializeAndSeed.Initialize(). Worked perfectly.
This article helped me figure that out.
I am having difficulty getting my Monodroid application retrieve a location when I run it in an emulator. My code looks something like this:
LocationManager locationsManager = (LocationManager)threadSurfaceView.Context.GetSystemService(Context.LocationService);
location = locationsManager.GetLastKnownLocation(Android.Content.Context.LocationService);
However, this always seems to return null. Do I have to configure the emulator in some way so that it has a locaion service and/or location?
I also tried adding a LocationListener:
locationListener = new MyLocationListener();
locationsManager.RequestLocationUpdates(LocationManager.GpsProvider, 120000, 0, locationListener);
But the problem I had here was to create the MyLocationListener class. I implemented the four public methods (OnLocationChanged(Location) and so on), but Visual Studio complained about a missing Android.Runtime.IJavaObject method - does anyone have a simple example of a class that implements ILocationListener?
Thanks for any help. Martin
I got a kindly link to a sample at
https://github.com/gshackles/Sample-Projects/blob/master/MonoDroid/MonoDroidSamples/MonoDroidSamples/DemoActivities/LocationDemo/LocationActivity.cs
Which works fine on my Nexus S but still will not work on the emulator - so (perhaps) the issue is not a code issue.
I liked the technique in this sample of getting the "Activity" to implement ILocationListener as well as Activity - a neat solution to getting data back out of the "listener" function which had been giving me headaches when it was wrapped into another class.
I downloaded the bundle of samples and if you do the same then you will need to grab an mp3 file - rename it volbeat.mp3 and add it to the "raw" folder within "Resources" as it is missing.
partial answer as I am working on the same problem.
Your listener class that implements ILocationListener needs to be declared like
public class myLocationListener : Java.Lang.Object, ILOcationListener
{
//plus the public functions you identified
}
My attempt looks like this:
Android.Locations.Location iAmHere;
LocationManager myLoc = (LocationManager)GetSystemservice(Context.LocationService);
iAmHere = myLoc.GetLastKnownLocation(Android.Content.Context.LocationService);
but iAmHere is null on the emulator even when I have used TelNet to push a geo fix location through