namespaces

PHP namespace and dynamic classname

ⅰ亾dé卋堺 提交于 2020-01-14 13:49:28
问题 I've encountered a "weird" thing while experimenting with spl_autoload, namespaces and dynamic class names. I use PHP 5.3.2, call the autoload like this set_include_path(get_include_path().PATH_SEPARATOR."classes".PATH_SEPARATOR."utils"); spl_autoload_extensions(".class.php"); spl_autoload_register(); Now to the core. Suggest following code: new \User\Student; $name="\User\Student"; new $name(); This works fine, file classes/user/student.class.php gets loaded successfully, both constructions

Groovy XmlSlurper: get value of attribute that has an associated namespace

送分小仙女□ 提交于 2020-01-14 09:04:31
问题 I have an XML document that contains attributes with qualified names. I want to get the attribute value using XmlSlurper, but trying to access the attribute without specifying the namespace does not work (below is a minimal example). def rootNode = new XmlSlurper().parseText( '''<root xmlns:ex="http://example.com"> <one ex:a1="uno!"/> <ex:two>Some text!</ex:two> </root>''' ) assert rootNode.one[0].@a1.text() == 'uno!' rootNode.one[0].@a1.text() will yield an empty string. If using rootNode

PHP namespacing and spl_autoload_register

谁都会走 提交于 2020-01-14 07:57:10
问题 I had spl_autoload_register working fine but then I decided to add some namespacing to bring in PSR2 compliance and can't seem to get it working. Directory strcuture: -index.php -classes/ -Class1.class.php -Class2.class.php -Class3.class.php Each class starts with: namespace Foo; Class ClassX { Index.php: <?php spl_autoload_register(function($class) { include 'classes/' . $class . '.class.php'; }); $myObj = new Class1(); echo $myObj->doSomething(); This products an error Fatal error: Class

How to use JSDoc3 to document nested namespaces

梦想的初衷 提交于 2020-01-14 07:35:07
问题 I'm having trouble using JSDoc3 to document code that's structured along these lines /** * @namespace MyNamespace.MySubNamespace */ (function (MyNamespace) { MyNamespace.MySubNamespace.Foo = { doSomething: function (someParam) { // doing it } } })(window.MyNamespace) How would I use JSDoc3 to document that MyNamespace contains MySubNamespace which contains Foo ? Further how would I associate doSomething with Foo and document its parameter someParam ? A limitation I have is that I can't add

xml.etree.ElementTree - Trouble setting xmlns = '…'

让人想犯罪 __ 提交于 2020-01-14 05:18:07
问题 I must be missing something. I'm attempting to set up a google product feed, but am having a hard time registering the namespace. Example: Directions here: https://support.google.com/merchants/answer/160589 Trying to insert: <rss version="2.0" xmlns:g="http://base.google.com/ns/1.0"> This is the code: from xml.etree import ElementTree from xml.etree.ElementTree import Element, SubElement, Comment, tostring tree = ElementTree tree.register_namespace('xmlns:g', 'http://base.google.com/ns/1.0')

web link in svg

匆匆过客 提交于 2020-01-14 03:27:11
问题 I need to have a linked text inside a svg graph. Here is what I did <?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg width="138pt" height="188pt" viewBox="0.00 0.00 138.00 188.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:html="http://www.w3.org/1999/xhtml"> <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 184)"> <g id="node5" class="node"><title>EQ2</title> <ellipse style="fill:none;stroke:black;" cx="65" cy="-18"

Python functions can be given new attributes from outside the scope?

↘锁芯ラ 提交于 2020-01-14 02:23:56
问题 I didn't know you could do this: def tom(): print "tom's locals: ", locals() def dick(z): print "z.__name__ = ", z.__name__ z.guest = "Harry" print "z.guest = ", z.guest print "dick's locals: ", locals() tom() #>>> tom's locals: {} #print tom.guest #AttributeError: 'function' object has no attribute 'guest' print "tom's dir:", dir(tom) # no 'guest' entry dick( tom) #>>> z.__name__ = tom #>>> z.guest = Harry #>>> dick's locals: {'z': <function tom at 0x02819F30>} tom() #>>> tom's locals: {}

Unknown type 'AppBarButton' in XML namespace - Windows 8 Store App XAML, issues adding app bars

放肆的年华 提交于 2020-01-13 10:56:08
问题 I'm new to developing Windows 8 apps, and am having trouble getting my XAML file to recognise generated code for adding AppBars and CommandBars. I am getting the error "Unknown type [something] in XML namespace" for a number of elements I am trying to add, here is my example below: If I re-open my solution this is temporarily displayed as a warning rather than an error. Also navigating to http://schemas.microsoft.com/winfx/2006/xaml/presentation just produces "The resource you are looking for

how do you organize your namespaces?

…衆ロ難τιáo~ 提交于 2020-01-13 10:12:09
问题 So I have logical entities (person, country, etc.), GUI elements / controls, data and navigation controllers / managers, then things like quad-trees and timers, and I always struggle with cleanly separating these things into logical namespaces. I usually have something like this: Leviathan.GUI.Controls Leviathan.GUI.Views Leviathan.Entities Leviathan.Controllers (data and other stuff) Leviathan.Helpers (trees and other stuff) Are there any good guides on this? I need to stop this mess. 回答1:

PHP trying to use autoload function to find PDO class

烂漫一生 提交于 2020-01-13 09:49:06
问题 This has been bugging me for some time now and I can't seem to make sense of it. My phpinfo reports that PDO is installed and I can connect to my database on my index.php file. But when I try to open a PDO connection on a namespaced class, php is trying to use my autoload function to find PDO.php which won't work. My class is as follows: abstract class { protected $DB; public function __construct() { try { $this->DB = new PDO("mysql:host=$host;port=$port;dbname=$dbname", $user, $pass); }