I want to extend symfony's default router. I have created routing folder in lib/ and created customRouter.class.php saved it under lib/routing. I have changed factories.yml as below:
all:
routing:
class: customRouter
My customRouter.class.php is:
class customRouter extends sfPatternRouting{
}
I only extend sfPatternRouting class. When I run the application it gives me an error as below:
Catchable fatal error: Argument 1 passed to sfRouting::__construct() must be an instance of sfEventDispatcher, string given in /opt/task/lib/vendor/symfony/lib/routing/sfRouting.class.php on line 32
I do not realize the problem. I only extend the class. What is the solution to extend symfony's router?
I believe you are extending the wrong class and as such are not inheriting necessary methods. The symfony 1.4 documentation suggests extending the 'sfDoctrineRoute' class to create custom routing (as linked by #Kenny)
Related
Upgrading a legacy system of grails. One of the controllers implements Serializable. This is throwing the following error in newer versions of grails:
Invalid duplicate class definition of class com.regional.ScheduleController :
The source contains at least two definitions of the class.
One of the classes is an explicit generated class using the class statement,
the other is a class generated from the script body based on the file name.
Solutions are to change the file name or to change the class name.
The solution mentioned would break (previous) grails convention. Anyone know how to handle this in grails 2.5+?
EDIT
Serializable is not the issue. I tried removing it and got the same error.
I found this explanation from another question:
IN groovy.. class B{} is a class structure and defines a class B.
Scripts are classes too.
Now you may create a B.groovy, with the content "class B{}; def b = new B()".
There would be one class named B, and a script with the very same name.
This is a conflict.
However this does not explain why it runs fine below grails 2.5 and not above it. And I can't find a def conflict like the one mentioned above in that controller.
ANSWER:
One of the imports was what was actually failing- in a way that caused groovy to generate a class definition based on the current file name. When it hit the class definition, there was already an auto generated class name to collide with.
I am using swagger-inflector to design an API. I am trying to use x-swagger-router-controller and x-swagger-router-model as specified in the docs, but it is not working as specified.
The way I read the docs, these vendor extensions are supposed to create the class if it does not exist and then create a method named with the "operationId". However, they do not work as specified. (I looked at the code that I think is supposed to process this vendor extension, and it looks like the extension should be processed, but the classes are not created as expected. Well, the x-swagger-router-model generates the desired class name, but not the desired package).
If I use the inflector.yaml file and specify modelPackage and controllerPackage, the classes get created in those packages, but I need more granular control over what package is used for the generated classes.
Am i doing something wrong, or is this broken?
Here is an example:
definitions:
SomeObject:
type: object
x-swagger-router-model: com.example.api.dto.SomeObjectDTO
...
paths:
/mypath:
x-swagger-router-controller: com.example.api.controller.subpkg1.MyController
get:
...
From the above example
I do not get a model class named SomeObjectDTO created in com/example/api/dto. If no modelPackage is specified in inflector.yaml, I get a model class named SomeObject created in the default package (io/swagger/...). The model class name that is generated in either case is SomeObject.java
I do not get a controller class named MyController created in com/example/api/controller/subpkg1. If no controllerPackage is specified in inflector.yaml, I get a controller class named "MyPathController" created in the default package (io/swagger/...). The controller class that is generated in either case is MyPathController.java.
It looks like this is a bug, or that I am missing something really obvious. Any pointers here?
the swagger-inflector code will not generate models for you--it will attempt to connect the routing information (via x-swagger-router-model) or via modelPackage + schema name. If that model cannot be loaded in the class loader, it will treat this model as a jackson JsonNode for all input (put/post) methods.
I am trying to use Spring in my rails project but I have my own class called Spring that inherits from another class of mine called Feature.
In my code I call .superclass on a variable that is set to Spring sometimes. It fails because the variable is set to the other Spring class. How can I set it to class I defined?
i would suggest use modules.
create your class inside a module and call it MyModule::Spring to avoid conflicts
I'm trying to get a list of the methods defined in our Rails codebase, without including anything defined in superclass or dynamically defined at runtime. I've tried instance_methods(false), but a ton of methods are returned:
> User.instance_methods(false).length
=> 310
I'm guessing this is because Rails defines a bunch of methods at runtime. Is there any way to get a list of the methods only defined in the files in our app? Hoping there's a Ruby way and not just running a grep across all of the files. Bonus points for class methods as well...
User.instance_methods will show all the inherited methods as well, so you should run something like that
User.instance_methods - User.superclass.instance_methods
Be ware thought that it will show heaps of other methods that are generated by AR when you inherited the ActiveRecord::Base class
Use MyClass.instance_methods(false), but make sure to pass false as an argument if you don't want it to return the methods defined in the superclasses.
Additionally, use MyClass.singleton_methods(false) for class methods.
More info:
https://apidock.com/ruby/Object/singleton_methods
https://apidock.com/ruby/Module/instance_methods
According to Grails API, we can retrieve all domain classes definition through GrailsApplication as such
import org.codehaus.groovy.grails.commons.ApplicationHolder as AH
AH.application.domainClasses
I have classes defined under src/groovy and would like to do the same. I tried using the follwing code but in vain
import org.codehaus.groovy.grails.commons.ApplicationHolder as AH
AH.application.allClasses
According to Grails API, call to getAllClasses should return all classes loaded by Grails class loader
Class[] getAllClasses()
Retrieves all java.lang.Class instances loaded by the Grails class loader
Am i missing something
Any Java or Groovy code can be placed in the src directory and does not have to integrate with Grails. The Grails class loader only loads Grails specific classes such as pluggins, controllers, and domain classes that your grails application knows about at run-time. In order to find out about classes located in your src directory you will need to know the package name your interested in and then iterate through everything contained in that package.
.
Well the classes under 'src' are not registered with grails classLoader. But you can use the "in context class loader" to get those classes easily using one single line of code (Java Style though)
Class fetchedClass = Class.forName(
"Class Full Name Here",
true,
Thread.currentThread().getContextClassLoader()
)
.
.
Thats It .. :) All Done!! Easily.
.
.
Example to get the class "com.myPackage.dto.AddressDTO"
We will Do:
EXAMPLE: get class "com.myPackage.dto.AddressDTO"
Class fetchedClass = Class.forName(
"com.myPackage.dto.AddressDTO",
true,
Thread.currentThread().getContextClassLoader()
)