PHP
  Home arrow PHP arrow Page 2 - Using the .NET Assembly in PHP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Using the .NET Assembly in PHP
By: Jayesh Jain
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 29
    2002-10-15

    Table of Contents:
  • Using the .NET Assembly in PHP
  • Creating an Assembly
  • Creating the PHP File
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using the .NET Assembly in PHP - Creating an Assembly


    (Page 2 of 4 )

    Open Visual Studio.Net and create a new class library project, which we will call "phpclass". Click on the OK button when you're done, as shown below:

    Creating our class library

    In the code window for class1 (class1.vb), type the following:

    Namespace HealthRecord
    Public Class patient
    Private m_lmp As Date
    Public Property lmp()
    Get
    Return Format(m_lmp, "D")
    End Get
    Set(ByVal Value)
    m_lmp = Value
    End Set
    End Property
    Public ReadOnly Property edd()
    Get
    'EDD is 280 days from LMP
    Return Format(DateAdd(DateInterval.Day, 280, m_lmp), "D")
    End Get
    End Property
    End Class
    End Namespace


    Let's assume that we're coding this app for a clinic. This VB.NET code will calculate the EDD (Estimated Delivery Date) from the specified LMP (Last Menstrual Period) date for any patient. To implement this, we have created a namespace called HealthRecord and a public class called patient, with two public properties: lmp and edd. Edd is a read-only property, which is calculated from lmp, which can be set and also read.

    We have used the format function to format the date variable to a human readable format. We have also used the dateadd function to calculate the edd, which is 280 days from the lmp.

    Creating a Strong Name Key File
    A strong name is the full class name including the namespace, version, public key and digital signature. All assemblies installed on the system have to be uniquely identified and versioned. To make sure the assembly is not tampered with, it needs to be signed with a common key (public key) to decrypt.

    The strong name command-line tool (sn.exe) can be used to generate a new public-private key pair and to write that pair to a file which can then be used to create an assembly.

    sn –k mykey.snk

    This utility can be found in the .NET Framework's Bin folder C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Bin (on my computer).

    Alternatively, you could run a .NET Command Window by selecting Start –> Programs -> Microsoft Visual Studio .NET -> Visual Studio .NET Tools >- Visual Studio .NET Command Prompt, which sets all of the required paths for you.

    Here is the sample output you should be expecting:

    Output from the strong name tool

    Copy this file (mykey.snk) to your project folder c:\tgol\phpclass (on my computer).

    Adding the Strong Key to Project
    We need to add the key we just created to our project. Open the solution explorer and double click AssemblyInfo.vb to open the code window and add the following line:

    <Assembly: AssemblyKeyFile("c:\tgol\phpclass\mykey.snk")>

    Make sure you enter the full path to where you saved the key file. Now build the application to create phpclass.dll (this file shall be created in the bin folder under the project folder) c:\tgol\phpclass\bin\phpclass.dll (on my computer).

    Registering the Assembly
    To register a .NET class with COM, you must run a command-line tool called the Assembly Registration Tool (regasm.exe). Regasm.exe creates a type library (TBL File) and adds information about the class to the system registry, so that COM clients can use the .NET class transparently.

    regasm c:\tgol\phpclass\bin\phpclass.dll /tlb:phpclass.tlb

    This utility can be found in C:\WINNT\Microsoft.NET\Framework\v1.0.3705 (on my computer).

    Running regasm.exe

    Adding the Assembly to Global Assembly Cache
    In order to share the assembly with all applications, it needs to be installed in the GAC (Global Assembly Cache) with the following command from the command line:

    gacutil /i c:\tgol\phpclass\bin\phpclass.dll

    This utility can be found in C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Bin (on my computer).

    Running gacutil.exe 

    To view all of the assemblies installed in the GAC on your computer, open your windows explorer and look in the assembly folder under your windows folder, C:\WINNT\assembly (on my computer)

    More PHP Articles
    More By Jayesh Jain


       · Really usefull .Net assembly use in PHP overall.Helped me start my own...
     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT