// $Id$ #include @class NSFileManager; @interface PHP : WODynamicElement { WOAssociation *script; NSFileManager *fileManager; } @end #include "PHPInterpreter.h" #include "PHPRequest.h" #include #include #include "common.h" @implementation PHP + (void)initialize { /* this is called when the class is used the first time */ [PHPInterpreter phpInterpreter]; } - (id)initWithName:(NSString *)_name associations:(NSDictionary *)_config template:(WOElement *)_t { if ((self = [super initWithName:_name associations:_config template:_t])) { self->script = OWGetProperty(_config, @"script"); self->fileManager = [[NSFileManager defaultManager] retain]; } return self; } - (void)dealloc { [self->fileManager release]; [self->script release]; [super dealloc]; } /* response generation */ - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { PHPRequest *php; WORequest *rq; NSString *path; rq = [_ctx request]; path = [self->script stringValueInComponent:[_ctx component]]; if ([fileManager isReadableFileAtPath:path] == NO) { [self logWithFormat:@"PHP: Unable to access file: %@", path]; return; } [[PHPInterpreter phpInterpreter] pushContext:_ctx]; php = [[PHPRequest alloc] initWithMethod:[rq method] uri:[rq uri] translatedPath:path remoteUser:[(OGoSession *)[_ctx session] activeLogin]]; if ([php startup]) { [php executeFileAtPath:path]; [php shutdown]; } else [self logWithFormat:@"could not setup PHP context!"]; [php release]; [[PHPInterpreter phpInterpreter] popContext]; } @end /* PHP */