I am currently using the Form Annotation builder with Zend Framework 2 (Latest 2.3.2).
I have a single form validator which does not want to play nice and I cannot find any example documentation on how to make the Hostname validator work properly when allowing local hostnames.
Here is a code snippet of the validator in question:
/**
* #Form\Type("text")
* #Form\Required(false)
* #Form\Options({"label":"name"})
* #Form\Attributes({"id":"name"})
* #Form\Filter({"name":"stringtrim"})
* #Form\Filter({"name":"stringtolower"})
* #Form\Validator({"name":"stringlength", "options":{"min":"1", "max":"254"}, "break_chain_on_failure":"true"})
* #Form\Validator({"name":"hostname", "options":{"allow":"\Zend\Validator\Hostname::ALLOW_LOCAL"}, "break_chain_on_failure":"true"})
* #Form\Validator({"name":"CompanyDns\Validator\DnsName", "break_chain_on_failure":"true"})
*/
public $name;
When the form attempts to validate using a local name I am getting the validators response of:
The input appears to be a local network name but local network names are not allowed
I am following the manual http://framework.zend.com/manual/2.3/en/modules/zend.form.quick-start.html#using-annotations
Any ideas what I am missing or can do to resolve this?
It appears that when using the Annotation Builder additional Hostname::* features do not get passed as one would expect.
So this line:
#Form\Validator({"name":"hostname", "options":{"allow":"\Zend\Validator\Hostname::ALLOW_LOCAL"}, "break_chain_on_failure":"true"})
Should actually read:
#Form\Validator({"name":"hostname", "options":{"allow":"4"}, "break_chain_on_failure":"true"})
If you look at the Hostname Validator class the 4 represents the ALLOW_LOCAL of the validator.
This should resolve the problem for you.
Related
I am using instructions from here on how to get started with open layers and I got the error: Namespace "ol" already declared - source ol-debug.js and the error
this.Va is not a function - source ol.js
I am pretty sure I have included the ol.js, ol-debug.js and ol.css files properly in my index.html.
Link to open layers js and css files.
This is the relevant part from ol-debug.js file -
/**
* Defines a namespace in Closure.
*
* A namespace may only be defined once in a codebase. It may be defined using
* goog.provide() or goog.module().
*
* The presence of one or more goog.provide() calls in a file indicates
* that the file defines the given objects/namespaces.
* Provided symbols must not be null or undefined.
*
* In addition, goog.provide() creates the object stubs for a namespace
* (for example, goog.provide("goog.foo.bar") will create the object
* goog.foo.bar if it does not already exist).
*
* Build tools also scan for provide/require/module statements
* to discern dependencies, build dependency files (see deps.js), etc.
*
* #see goog.require
* #see goog.module
* #param {string} name Namespace provided by this file in the form
* "goog.package.part".
*/
goog.provide = function(name) {
if (goog.isInModuleLoader_()) {
throw Error('goog.provide can not be used within a goog.module.');
}
if (!COMPILED) {
// Ensure that the same namespace isn't provided twice.
// A goog.module/goog.provide maps a goog.require to a specific file
if (goog.isProvided_(name)) {
throw Error('Namespace "' + name + '" already declared.');
}
}
goog.constructNamespace_(name);
};
You need to declare either ol.js or ol-debug.js, not both of them. The error is coming from the fact that you're declaring both of them and it is creating a namespace conflict.
I'm trying to post linked entries in atom-format to Odata service. Only thing missing from my payload is that rel-attribute should be: "http://schemas.microsoft.com/ado/2007/08/dataservices/related/SOItems". Currently it's automatically generated to "http://schemas.microsoft.com/ado/2007/08/dataservices/related/links"
Heres my current linked entries:
<a:link href="SOItems" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/links" type="application/atom+xml;type=entry"><m:inline><a:feed><a:entry><a:author><a:name></a:name></a:author><a:content type="application/xml"><m:properties><d:OrderId>0</d:OrderId><d:Item>000020</d:Item><d:Material>M-06</d:Material><d:Plant>1200</d:Plant><d:Quantity>200.000</d:Quantity><d:Description m:null="true"></d:Description><d:UoM m:null="true"></d:UoM><d:Value m:null="true"></d:Value></m:properties></a:content></a:entry><a:entry><a:author><a:name></a:name></a:author><a:content type="application/xml"><m:properties><d:OrderId>0</d:OrderId><d:Item>000020</d:Item><d:Material>M-06</d:Material><d:Plant>1200</d:Plant><d:Quantity>200.000</d:Quantity><d:Description m:null="true"></d:Description><d:UoM m:null="true"></d:UoM><d:Value m:null="true"></d:Value></m:properties></a:content></a:entry></a:feed></m:inline></a:link>
How can I set rel-attribute for linked entry with datajs.
Thanks,
Br,
RP
the namespace of links "http://schemas.microsoft.com/ado/2007/08/dataservices/related/links" is hard code on datajs code. Currently there is no public API that the application could use to change it. However, since the datajs is open source, there are still some methods to work around this issue by modifying the datajs code:
a) Change the value of local property “odataRelatedLinksPrefix” in data.js
b) Expose the local variable “odataRelatedLinksPrefix” to be public by adding odata.odataRelatedLinksPrefix = odataRelatedLinksPrefix in data.js code. After doing this, the application could change the namespace value by calling OData.odataRelatedLinksPrefix whenever and wherever.
I encountered a problem with Javadoc generation. I would like to create a truncated Javadoc consisting only of specific comments, specifically - test cases (which are described by every #Test annotation), packages and classes, all other information is not needed. Is it possible to limit other elements in Javadoc while generating it without parsing it ?
For example:
/**
* <b>Test case A:</b>
*
* <ol>
* <li>Navigate to main application</li>
* <li>In actions drop-down select value = 'Run'</li>
* <li>Assert that application is running</li>
* </ol>
*
**/
#Test
public void testMainApp() throws IOException {
navigateToMainApp();
selectAndExecute();
Assert.assertEquals("Applications is not running: ", true, status.equals(RUNNING));
}
Thanks in advance!
You can use maven to generate javadocs(http://maven.apache.org/plugins/maven-javadoc-plugin/javadoc-mojo.html). You will be able to exclude packages and source files for which you do not want to create docs.
Hope this helps.
Has the interface <none> in the gdbus-monitor output a special meaning?
What API call is required to create such a message using GDbus (g_dbus_connection_register_object does not allow to pass NULL as GDBusInterfaceInfo * and that seems to be the only to register a object to a path)
related: dbus - register object to remote on interface NULL
Looking into dbus-monitor's source code shows that it occures as soon as DBUS_EXPORT const char * dbus_message_get_interface ( DBusMessage * message ) returns NULL (which is valid!, but not according to the spec which requires minimum one . and two name chunks!! EDIT: A noteable exception are method calls which do not require the interface field of a message to be set http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-types).
g_dbus_message_new_method_call (...) allows interface_ to be null. But that still only solves half the problems (sender). The receiver method seems to not exist for interface_s being NULL.
Turns out it is a bug, I did a source code investigation and filed a bug (including fix) https://bugzilla.gnome.org/show_bug.cgi?id=706675
client needs to know the interface name while subscribing g_dbus_connection_signal_subscribe to any signal else it will listen to all interfaces hence inefficient.
Interface is required to bind methods and signals in single entity mentioned in server introspection xml file.
I'm using BjyAuthorize with Zend Framework2 to implement authorization and was able to successfully integrate roles from database. Now I want to get my Rules and Guards also from data base tables. How can I do this?
The easiest method and "the trick" here is really to:
Get your rules and guards into the same array format as it is shown in example configuration. So after reading records from the database, in whatever format your raw database data is, process it to match the same guard format as in the configuration. (My answer goes into detail on how to do that with Doctrine ORM, but also should give you an idea with other DB engines. Just substitute "DB read" operation with your fave database engine)
Inject the rules that are already in the proper format BjyAuthorize expects (because you made them so), into BjyAuthorize\Guard\Controller, from within YOUR_MODULE_NAME\Factory\DoctrineControllerGuardAdapterFactory, which you will write. Bjy's Controller will treat the rules as if those rules came from configuration*, and not suspect any difference.
Step back and enjoy!
This is the construct that you need to write in your own module:
namespace YOUR_MODULE_NAME\Factory;
/**
* See "How and where exactly to register the factory" in ZF2 config
* below in my answer.
*/
class [Custom]ControllerGuardAdapterFactory
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
/**
* Retrieve your rules from favorive DB engine (or anything)
*
* (You may use $serviceLocator to get config for you DB engine)
* (You may use $serviceLocator to get your DB engine)
* (You may use $serviceLocator to get ORM Entity for your DB engine)
* (Or you may hack your DB connection and retrieval in some other way)
*
* Hell, you may read them from a text file using PHP's file() method
* and not use $serviceLocator at all
*
* You may hardcode the rules yourself right here for all that matters
*/
$rules = ... //array(...);
/**
* Inject them into Bjy's Controller
*
* Rules must be in the same format as in Bjy config, or it will puke.
* See how ['guards'][\BjyAuthorize\Guard\Controller::class] is constructed
* in Bjy configuration for an example
*/
return new \BjyAuthorize\Guard\Controller($rules, $serviceLocator);
}
}
Now watch and observe how mind-numbingly complicated this can be made! (modeled after Bjy's own mechanisms)
This is mostly just ZF2, OO & Bjy "Configuration Hell", folks, nothing special otherwise. Welcome to ZF2 and Bjy and ORM Configuration Hell. You are welcome.
Detailed Answer - How to Implement?
Write an adapter factory, which reads rules from database, and then injects them into BjyAuthorize's Controller Guard. The effect will be the same as if the rules were being read from ['guards'][\BjyAuthorize\Guard\Controller::class]
What?
The way BjyAuthorize's Controller Guard works is it takes rules in a certain format (format specified for ['guards']['BjyAuthorize\Guard\Controller']), and then it uses the rules to populate the ACL. It also computes Resources from rules for you and loads those into ACL as well. If it didn't, you would have to write your own Resource Provider to do so.
So the task becomes:
Load rules from database and Transform the rules to format BjyAuthorize expects. This can be done in your own Rule Provider, much like this one.
You can use a factory to load your particular DB and storage class configuration arrays from module.config.php file. I put mine under ['guards']['YOUR_MODULE_NAME_controller_guard_adapter'].
'guards' => array(
'YOUR_MODULE_NAME_controller_guard_adapter' => array(
'object_manager' => 'doctrine.entity_manager.orm_default',
'rule_entity_class' => 'YOUR_MODULE_NAME\Entity\ObjectRepositoryProvider'
)
)
(cont) I put it under guards as opposed to rule_providers, because what we are dealing with here is not a pure rule provider. It is a guard provider, or "an adapter that gets rules out of your ObjectRepositoryProvider, and injects them into controller guard". This factory should look similar to this, except that you will be loading rules, not roles. You will then be injecting the rules into Controller, as in the next step.
Inject the rules into Controller, very much like it is done here
Example Implementation Details (from Q/A in comments)
More on the last point of "Injecting rules into Controller". Basically two steps: 1) make sure you already have (or will) generate your rules somehow (that's the hard step ). 2) inject those rules into controller (that's the easier step). The actual injection is done like this
$rules = __MAGIC__; //get rules out of somewhere, somehow.
return new Controller($rules, $serviceLocator); //$rules injection point
See code block below for my own implementation, where the last line in the block is the line I gave just above here.
namespace YOUR_MODULE_NAME\Factory;
use BjyAuthorize\Exception\InvalidArgumentException;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use YOUR_MODULE_NAME\Provider\Rule\DoctrineRuleProvider; //this one's your own
use BjyAuthorize\Guard\Controller;
class DoctrineControllerGuardAdapterFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
//just setting up our config, move along move along...
$config = $serviceLocator->get('Config');
$config = $config['bjyauthorize'];
//making sure we have proper entries in our config...
//move along "nothing to see" here....
if (! isset($config['guards']['YOUR_MODULE_NAME_controller_guard_adapter'])) {
throw new InvalidArgumentException(
'Config for "YOUR_MODULE_NAME_controller_guard_adapter" not set'
);
}
//yep all is well we load our own module config here
$providerConfig = $config['guards']['YOUR_MODULE_NAME_controller_guard_adapter'];
//more specific checks on config
if (! isset($providerConfig['rule_entity_class'])) {
throw new InvalidArgumentException('rule_entity_class not set in the YOUR_MODULE_NAME guards config.');
}
if (! isset($providerConfig['object_manager'])) {
throw new InvalidArgumentException('object_manager not set in the YOUR_MODULE_NAME guards config.');
}
/* #var $objectManager \Doctrine\Common\Persistence\ObjectManager */
$objectManager = $serviceLocator->get($providerConfig['object_manager']);
//orp -- object repository provider
//here we get our class that preps the object repository for us
$orp=new DoctrineRuleProvider($objectManager->getRepository($providerConfig['rule_entity_class']));
//here we pull the rules out of that object we've created above
//rules are in the same format BjyAuthorize expects
$rules=$orp->getRules();
//here pass our rules to BjyAuthorize's own Guard Controller.
//It will not know the difference if we got the rules from Config or from Doctrine or elsewhere,
//as long as $rules are in the form it expects.
return new Controller($rules, $serviceLocator);
}
}
DoctrineRuleProvider
namespace YOUR_MODULE_NAME\Provider\Rule;
use Doctrine\Common\Persistence\ObjectRepository;
use BjyAuthorize\Provider\Rule\ProviderInterface;
/**
* Guard provider based on a {#see \Doctrine\Common\Persistence\ObjectRepository}
*/
class DoctrineRuleProvider implements ProviderInterface
{
/**
* #var \Doctrine\Common\Persistence\ObjectRepository
*/
protected $objectRepository;
/**
* #param \Doctrine\Common\Persistence\ObjectRepository $objectRepository
*/
public function __construct(ObjectRepository $objectRepository)
{
$this->objectRepository = $objectRepository;
}
/**
* Here we read rules from DB and put them into an a form that BjyAuthorize's Controller.php understands
*/
public function getRules()
{
//read from object store a set of (role, controller, action)
$result = $this->objectRepository->findAll();
//transform to object BjyAuthorize will understand
$rules = array();
foreach ($result as $key => $rule)
{
$role=$rule->getRole();
$controller=$rule->getController();
$action=$rule->getAction();
if ($action==='all') //action is ommitted
{
$rules[$controller]['roles'][] = $role;
$rules[$controller]['controller'] = array($controller);
}
else
{
$rules[$controller.':'.$action]['roles'][]=$role;
$rules[$controller.':'.$action]['controller']=array($controller);
$rules[$controller.':'.$action]['action']=array($action);
}
}
return array_values($rules);
}
}
Q: How and where exactly to register the factory DoctrineControllerGuardAdapterFactory
A: Try this path: module\YOUR_MODULE_NAME\config\module.config.php and have
'service_manager' => array(
'factories' => array(
'YOUR_MODULE_NAME_controller_guard_adapter' => \YOUR_MODULE_NAME\Factory\DoctrineControllerGuardAdapterFactory::class
)
)
Note: YOUR_MODULE_NAME. The thing on the left of => sign is "the key", and can be anything you want it to be. Convention in Bjy is that it is similar to the actual class names and paths. And the thing on the right of the => is the actual fully qualified namespace to the class that you want to call with with this key.
Basically you have to write your own Provider.
Check out the different RoleProvider. Every RoleProvider implements the Provider\Role\ProviderInterface. The same thing has to be done when you want to implement Guards and Rules. You go into the specific directories Provider\Rule and Provider\Resource and check for the specific ProviderInterface.
That way you can write your own class implementing the Interface and then via configuration you tell BjyAuthorize to use your provider-classes.
As far as Guards are concerned, i do believe it is not yet possible to create those from Database. You would have to modify / PR the Module itself to make that happen.