1 /** 2 * Copyright (C) 2005-2009 Alfresco Software Limited. 3 * 4 * This file is part of the Spring Surf Extension project. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.springframework.extensions.webscripts.processor; 20 21 import org.springframework.extensions.surf.core.processor.ProcessorExtension; 22 23 import com.caucho.quercus.module.AbstractQuercusModule; 24 import com.caucho.quercus.module.QuercusModule; 25 26 /** 27 * Base class representing an extension to the PHP processor that adds new methods. 28 * 29 * @author Roy Wetherall 30 */ 31 public class PHPMethodExtension extends AbstractQuercusModule implements ProcessorExtension 32 { 33 /** The name of the extension */ 34 protected String extensionName; 35 36 /** The PHP processor */ 37 protected PHPTemplateProcessor phpProcessor; 38 39 /** 40 * Sets the extension name 41 * 42 * @param extensionName the extension name 43 */ 44 public void setExtensionName(String extensionName) 45 { 46 this.extensionName = extensionName; 47 } 48 49 /** 50 * @see org.alfresco.service.cmr.repository.ProcessorExtension#getExtensionName() 51 */ 52 public String getExtensionName() 53 { 54 return this.extensionName; 55 } 56 57 /** 58 * Sets the PHP Processor 59 * 60 * @param phpProcessor the PHP processor 61 */ 62 public void setPhpProcessor(PHPTemplateProcessor phpProcessor) 63 { 64 this.phpProcessor = phpProcessor; 65 } 66 67 /** 68 * Register the method extension with the PHP processor. 69 */ 70 public void register() 71 { 72 this.phpProcessor.registerProcessorExtension(this); 73 } 74 75 /** 76 * Callback used to copy across state to the Quercus module. This is needed because the Quercus 77 * library creates a new instance of the module once it has been added. 78 * 79 * @param module the Quercus module 80 */ 81 public void initialiseModule(QuercusModule module) 82 { 83 PHPMethodExtension baseModule = (PHPMethodExtension)module; 84 baseModule.extensionName = this.extensionName; 85 baseModule.phpProcessor = this.phpProcessor; 86 } 87 }