Example #1
0
        /// <summary>
        /// Converts a W3C PHP object to a corresponding string.
        /// </summary>
        public static string /*!*/ PhpToString(Context ctx, PhpValue arg)
        {
            if (arg.IsObject)
            {
                // Node* (XPath)
                var node = arg.Object as DOMNode;
                if (node != null)
                {
                    return(node.XmlNode.Value);
                }

                // Node Set (XPath), Result Tree Fragment (XSLT)
                DOMNodeList list = arg.Object as DOMNodeList;
                if (list != null)
                {
                    if (list.length == 0)
                    {
                        return(String.Empty);
                    }
                    return(list.item(0).XmlNode.Value);
                }
            }

            // any other object
            return(arg.ToString(ctx));
        }
Example #2
0
        /// <summary>
        /// Converts a W3C PHP object to the corresponding W3C .NET object.
        /// </summary>
        public static object /*!*/ PhpToDotNet(Context ctx, PhpValue arg)
        {
            if (arg.IsNull)
            {
                return(String.Empty);
            }

            // Node* (XPath)
            if (arg.IsObject)
            {
                var node = arg.Object as DOMNode;
                if (node != null)
                {
                    return(node.XmlNode.CreateNavigator());
                }

                // Node Set (XPath), Result Tree Fragment (XSLT)
                DOMNodeList list = arg.Object as DOMNodeList;
                if (list != null)
                {
                    XPathNavigator[] navs = new XPathNavigator[list.length];

                    for (int i = 0; i < list.length; i++)
                    {
                        navs[i] = list.item(i).XmlNode.CreateNavigator();
                    }

                    return(navs);
                }

                // any other object
                return(arg.ToString(ctx));
            }

            // TODO: Handle PhpArray separately?
            // String (XPath), Boolean (XPath), Number (XPath)
            return(arg.ToClr());
        }