Presentation is loading. Please wait.

Presentation is loading. Please wait.

Integration between PHP and.NET Applications Svetlin Nakov National Academy for Software Development academy.devbg.org.

Similar presentations


Presentation on theme: "Integration between PHP and.NET Applications Svetlin Nakov National Academy for Software Development academy.devbg.org."— Presentation transcript:

1 Integration between PHP and.NET Applications Svetlin Nakov National Academy for Software Development academy.devbg.org

2 ContentsContents 1.PHP Interoperability 2.PHP and COM 3.Writing WordPress Plug-in in C# 4.Phalanger: Running PHP in.NET CLR 1.PHP Interoperability 2.PHP and COM 3.Writing WordPress Plug-in in C# 4.Phalanger: Running PHP in.NET CLR

3 PHP Interoperability

4 What is Interoperability?What is Interoperability? Ability to work together with other products, frameworks, languages and platformsAbility to work together with other products, frameworks, languages and platforms PHP InteroperabilityPHP Interoperability Call external process – shell_exec() functionCall external process – shell_exec() function Invoke native C/C++ code (.so /.dll libraries)Invoke native C/C++ code (.so /.dll libraries) dl() function in PHP (load extension library)dl() function in PHP (load extension library) SWIG – http://www.swig.org/SWIG – http://www.swig.org/http://www.swig.org/ COM operability (in Windows)COM operability (in Windows) Web services (REST / SOAP)Web services (REST / SOAP) What is Interoperability?What is Interoperability? Ability to work together with other products, frameworks, languages and platformsAbility to work together with other products, frameworks, languages and platforms PHP InteroperabilityPHP Interoperability Call external process – shell_exec() functionCall external process – shell_exec() function Invoke native C/C++ code (.so /.dll libraries)Invoke native C/C++ code (.so /.dll libraries) dl() function in PHP (load extension library)dl() function in PHP (load extension library) SWIG – http://www.swig.org/SWIG – http://www.swig.org/http://www.swig.org/ COM operability (in Windows)COM operability (in Windows) Web services (REST / SOAP)Web services (REST / SOAP)

5 PHP and COM

6 What is COM? Component Object Model (COM)Component Object Model (COM) Microsoft Windows built-in technologyMicrosoft Windows built-in technology Inter-process communication between components and applicationsInter-process communication between components and applications Example: Display Adobe Acrobat PDF in Internet ExplorerExample: Display Adobe Acrobat PDF in Internet Explorer Object-oriented approachObject-oriented approach Allows dynamic object creation and method invocation and properties / events accessAllows dynamic object creation and method invocation and properties / events access Language-neutral technologyLanguage-neutral technology Component Object Model (COM)Component Object Model (COM) Microsoft Windows built-in technologyMicrosoft Windows built-in technology Inter-process communication between components and applicationsInter-process communication between components and applications Example: Display Adobe Acrobat PDF in Internet ExplorerExample: Display Adobe Acrobat PDF in Internet Explorer Object-oriented approachObject-oriented approach Allows dynamic object creation and method invocation and properties / events accessAllows dynamic object creation and method invocation and properties / events access Language-neutral technologyLanguage-neutral technology

7 Creating COM Component in.NET Framework and C# Define the COM dispatch interface:Define the COM dispatch interface: Define the COM implementation class:Define the COM implementation class: Define the COM dispatch interface:Define the COM dispatch interface: Define the COM implementation class:Define the COM implementation class: [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface ICalculator { int Sum(int a, int b) int Sum(int a, int b)} namespace PlayingWithCOM { [ComVisible(true)] [ComVisible(true)] [Guid("38AADE7B-79B8-31A1-B365-22C6AAE5232C")] [Guid("38AADE7B-79B8-31A1-B365-22C6AAE5232C")] public class Calculator : ICalculator { public class Calculator : ICalculator { public int Sum(int a, int b) { return a + b; } public int Sum(int a, int b) { return a + b; } }}

8 Register COM Component Assembly in the Registry Sign the assembly with strong name:Sign the assembly with strong name: Install the assembly in the Global Assembly Cache (GAC):Install the assembly in the Global Assembly Cache (GAC): Register the assembly as COM component in Windows registry:Register the assembly as COM component in Windows registry: Sign the assembly with strong name:Sign the assembly with strong name: Install the assembly in the Global Assembly Cache (GAC):Install the assembly in the Global Assembly Cache (GAC): Register the assembly as COM component in Windows registry:Register the assembly as COM component in Windows registry: [assembly:AssemblyKeyFile(@"secret-key.snk")] gacutil -i PlayingWithCOM.dll regasm PlayingWithCOM.dll

9 Using COM Objects from PHP Script Creating COM object and invoking method from PHP:Creating COM object and invoking method from PHP: $calc = new COM("PlayingWithCOM.Calculator"); $result = $calc->Sum(5, 6); echo $result;

10 Writing WordPress Plug-ins in C#

11 WordPress on IIS Running WordPress in IISRunning WordPress in IIS Run PHP on IIS:Run PHP on IIS: Install FastCGI ISAPI extension for IISInstall FastCGI ISAPI extension for IIS Install and configure PHP for WindowsInstall and configure PHP for Windows Alternatively use Web Platform InstallerAlternatively use Web Platform Installer Install and configure MySQL for WindowsInstall and configure MySQL for Windows Configure WordPress and URL rewriting:Configure WordPress and URL rewriting: ISAPI_Rewrite in IIS 5.1/6ISAPI_Rewrite in IIS 5.1/6 Microsoft URL Rewrite for IIS 7Microsoft URL Rewrite for IIS 7 Running WordPress in IISRunning WordPress in IIS Run PHP on IIS:Run PHP on IIS: Install FastCGI ISAPI extension for IISInstall FastCGI ISAPI extension for IIS Install and configure PHP for WindowsInstall and configure PHP for Windows Alternatively use Web Platform InstallerAlternatively use Web Platform Installer Install and configure MySQL for WindowsInstall and configure MySQL for Windows Configure WordPress and URL rewriting:Configure WordPress and URL rewriting: ISAPI_Rewrite in IIS 5.1/6ISAPI_Rewrite in IIS 5.1/6 Microsoft URL Rewrite for IIS 7Microsoft URL Rewrite for IIS 7

12 Creating WordPress Plug-in We want to create WordPress plug-in for downloading a blog post as PDF documentWe want to create WordPress plug-in for downloading a blog post as PDF document Converting HTML page to PDF is not straightforward problem!Converting HTML page to PDF is not straightforward problem! We prefer to implement this in C#We prefer to implement this in C# Use Internet Explorer through COMUse Internet Explorer through COM Open the web page URL in Internet ExplorerOpen the web page URL in Internet Explorer Take the entire page as graphics imageTake the entire page as graphics image Cut the image into pages and write them to PDF document with PdfSharpCut the image into pages and write them to PDF document with PdfSharp Invoke the C# class from PHP through COMInvoke the C# class from PHP through COM We want to create WordPress plug-in for downloading a blog post as PDF documentWe want to create WordPress plug-in for downloading a blog post as PDF document Converting HTML page to PDF is not straightforward problem!Converting HTML page to PDF is not straightforward problem! We prefer to implement this in C#We prefer to implement this in C# Use Internet Explorer through COMUse Internet Explorer through COM Open the web page URL in Internet ExplorerOpen the web page URL in Internet Explorer Take the entire page as graphics imageTake the entire page as graphics image Cut the image into pages and write them to PDF document with PdfSharpCut the image into pages and write them to PDF document with PdfSharp Invoke the C# class from PHP through COMInvoke the C# class from PHP through COM

13 Creating WordPress Plug-in (2) We want to add a parameter " ?pdf " to all WordPress URLs to produce PDF outputWe want to add a parameter " ?pdf " to all WordPress URLs to produce PDF output We hook the WordPress action " init "We hook the WordPress action " init " In the action handler invoke the C# based Web2Pdf converterIn the action handler invoke the C# based Web2Pdf converter We want to add a parameter " ?pdf " to all WordPress URLs to produce PDF outputWe want to add a parameter " ?pdf " to all WordPress URLs to produce PDF output We hook the WordPress action " init "We hook the WordPress action " init " In the action handler invoke the C# based Web2Pdf converterIn the action handler invoke the C# based Web2Pdf converter add_action('init', 'init_action_handler'); $web2pdf = new COM("Web2Pdf.WebPageToPDFGenerator"); new COM("Web2Pdf.WebPageToPDFGenerator"); $pdf_base64 = $web2pdf- >GeneratePdfFromWebPageAsBase64($url);

14 Creating WordPress Plug-In in C# - Web2Pdf Converter Live Demo

15 PhalangerPhalanger The PHP Language Compiler for.NET

16 Phalanger Project: Running PHP in.NET Framework Phalanger ProjectPhalanger Project Open source PHP compiler for.NET CLROpen source PHP compiler for.NET CLR Web site: http://www.php-compiler.netWeb site: http://www.php-compiler.nethttp://www.php-compiler.net Compiles PHP code to MSIL just like C#Compiles PHP code to MSIL just like C# Implements all standard PHP functionsImplements all standard PHP functions Two modes of execution:Two modes of execution: Classical PHP execution model – run existing applications like phpBB, Drupal, etc.Classical PHP execution model – run existing applications like phpBB, Drupal, etc. ASP.NET mode – use ASP.NET with PHP language – mix.NET and PHP functionsASP.NET mode – use ASP.NET with PHP language – mix.NET and PHP functions Phalanger ProjectPhalanger Project Open source PHP compiler for.NET CLROpen source PHP compiler for.NET CLR Web site: http://www.php-compiler.netWeb site: http://www.php-compiler.nethttp://www.php-compiler.net Compiles PHP code to MSIL just like C#Compiles PHP code to MSIL just like C# Implements all standard PHP functionsImplements all standard PHP functions Two modes of execution:Two modes of execution: Classical PHP execution model – run existing applications like phpBB, Drupal, etc.Classical PHP execution model – run existing applications like phpBB, Drupal, etc. ASP.NET mode – use ASP.NET with PHP language – mix.NET and PHP functionsASP.NET mode – use ASP.NET with PHP language – mix.NET and PHP functions

17 Integration between PHP and.NET Applications Questions?Questions?


Download ppt "Integration between PHP and.NET Applications Svetlin Nakov National Academy for Software Development academy.devbg.org."

Similar presentations


Ads by Google