Inheritance: PHPIniBase, IRemoteObject
Exemplo n.º 1
0
        public string AddExtension(string extensionPath)
        {
            if (String.IsNullOrEmpty(extensionPath))
            {
                throw new ArgumentException("The extension path is not specified.");
            }

            EnsurePHPIsRegistered();

            var filename = Path.GetFileName(extensionPath);
            if (String.IsNullOrEmpty(filename))
            {
                throw new ArgumentException(String.Format("Cannot extract file name from the extention path {0}.", extensionPath));   
            }
            var targetPath = Path.Combine(PHPDirectory, "ext");
            targetPath = Path.Combine(targetPath, filename);

            File.Copy(extensionPath, targetPath, false);
            var extension = new PHPIniExtension(filename, true);

            var extensions = new RemoteObjectCollection<PHPIniExtension> { extension };
            UpdateExtensions(extensions);
            
            return extension.Name;
        }
Exemplo n.º 2
0
        internal void UpdateExtensions(IEnumerable <PHPIniExtension> extensions)
        {
            foreach (PHPIniExtension extension in extensions)
            {
                int foundIndex = -1;

                for (int i = 0; i < RawEntries.Count; i++)
                {
                    PHPIniBase b = RawEntries[i];

                    PHPIniExtension existing = b as PHPIniExtension;
                    if (existing != null)
                    {
                        if (String.Equals(existing.Name, extension.Name, StringComparison.OrdinalIgnoreCase))
                        {
                            foundIndex = i;
                            break;
                        }
                    }
                }

                // If extension is found...
                if (foundIndex >= 0)
                {
                    // ... and is disabled then...
                    if (!extension.Enabled)
                    {
                        PHPIniBase extensionLine = RawEntries[foundIndex];
                        // ... remove the extension section name if it exists
                        if (foundIndex > 0 &&
                            String.Equals(RawEntries[foundIndex - 1].GetText(), GetExtensionSection(extension.Name), StringComparison.OrdinalIgnoreCase))
                        {
                            RawEntries.Remove(RawEntries[foundIndex - 1]);
                        }

                        // remove the exension
                        RawEntries.Remove(extensionLine);
                    }
                }
                else
                {
                    // Extension is not found
                    if (extension.Enabled)
                    {
                        extension.UpdateText();

                        // Add it at the end of the file along with the extension section name
                        int lastIndex = RawEntries.Count - 1;
                        lastIndex++;
                        RawEntries.Insert(lastIndex, new PHPIniString(GetExtensionSection(extension.Name)));
                        lastIndex++;
                        RawEntries.Insert(lastIndex, extension);
                    }
                }
            }
        }
Exemplo n.º 3
0
        internal void Parse()
        {
            if (String.IsNullOrEmpty(FileName))
            {
                throw new InvalidOperationException();
            }

            string extensionDir = String.Empty;

            using (StreamReader reader = new StreamReader(FileName))
            {
                foreach (object o in PHPIniFile.ParseIniFile(reader))
                {
                    PHPIniSetting directive = o as PHPIniSetting;
                    if (directive != null)
                    {
                        Settings.Add(directive);
                        RawEntries.Add(directive);

                        // Get the path to the extension directory - this will be used later
                        if (String.Equals(directive.Name, "extension_dir", StringComparison.OrdinalIgnoreCase))
                        {
                            extensionDir = directive.GetTrimmedValue();
                        }
                    }
                    else
                    {
                        PHPIniExtension extension = o as PHPIniExtension;
                        if (extension != null)
                        {
                            Extensions.Add(extension);
                            RawEntries.Add(extension);
                        }
                        else
                        {
                            PHPIniBase entry = o as PHPIniBase;
                            if (entry != null)
                            {
                                RawEntries.Add(entry);
                            }
                        }
                    }
                }
            }

            if (String.IsNullOrEmpty(extensionDir) ||
                !Path.IsPathRooted(extensionDir))
            {
                extensionDir = Path.Combine(Path.GetDirectoryName(FileName), "ext");
            }

            if (Directory.Exists(extensionDir))
            {
                AddAllAvailableExtensions(extensionDir);
            }
        }
Exemplo n.º 4
0
        public string AddExtension(string extensionPath)
        {
            EnsurePHPIsRegistered();

            string filename = Path.GetFileName(extensionPath);
            string targetPath = Path.Combine(PHPDirectory, "ext");
            targetPath = Path.Combine(targetPath, filename);

            File.Copy(extensionPath, targetPath, false);
            PHPIniExtension extension = new PHPIniExtension(filename, true);

            RemoteObjectCollection<PHPIniExtension> extensions = new RemoteObjectCollection<PHPIniExtension>();
            extensions.Add(extension);
            UpdateExtensions(extensions);
            
            return extension.Name;
        }
Exemplo n.º 5
0
        public string AddExtension(string extensionPath)
        {
            Debug.Assert(IsPHPRegistered());

            string filename = Path.GetFileName(extensionPath);
            string targetPath = PHPDirectory + "ext\\" + filename;

            if (File.Exists(targetPath))
            {
                throw new InvalidOperationException("The extension file " + filename + " already exists at the PHP ext directory");
            }

            File.Copy(extensionPath, targetPath, false);
            PHPIniExtension extension = new PHPIniExtension(filename, true);

            RemoteObjectCollection<PHPIniExtension> extensions = new RemoteObjectCollection<PHPIniExtension>();
            extensions.Add(extension);
            UpdateExtensions(extensions);
            
            return extension.Name;
        }
Exemplo n.º 6
0
            public PHPExtensionItem(PHPIniExtension extension)
            {
                _extension = extension;
                Text = _extension.Name;
                SubItems.Add(State);

                if (!extension.Enabled) {
                    ForeColor = SystemColors.ControlDark;
                }
            }
        protected override void DoProcessing()
        {
            Debug.Assert(_phpIniFile != null);
            Debug.Assert(_extensions != null);

            foreach (string extensionName in Name)
            {
                PHPIniExtension extension = Helper.FindExtension(_phpIniFile.Extensions, extensionName);
                if (extension != null)
                {
                    if ((extension.Enabled && Status == PHPExtensionStatus.Disabled) ||
                        (!extension.Enabled && Status == PHPExtensionStatus.Enabled))
                    {
                        if (ShouldProcess(extensionName))
                        {
                            extension = new PHPIniExtension(extensionName, (Status == PHPExtensionStatus.Enabled) ? true : false);
                            _extensions.Add(extension);
                        }
                    }
                }
                else
                {
                    ArgumentException ex = new ArgumentException(String.Format(Resources.ExtensionDoesNotExistError, extensionName));
                    ReportNonTerminatingError(ex, "InvalidArgument", ErrorCategory.ObjectNotFound);
                    return;
                }
            }
        }
Exemplo n.º 8
0
 public PHPExtensionItem(PHPIniExtension extension)
 {
     _extension = extension;
 }