hs-php-session-0.0.9.3: PHP session and values serialization

Copyright(c) 2014 Edward Blake
LicenseBSD-style
MaintainerEdward L. Blake <edwardlblake@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell98

Data.PHPSession.Conv

Contents

Description

Non-coerced translation between PHPSessionValue and various Haskell types. convTo provide convenient translation from native types to PHPSessionValue, while translation from PHPSessionValue to native types is provided through convFrom and convFromSafe.

Synopsis

Convert to PHPSessionValue

convTo :: ConversionToPHPValue a => a -> PHPSessionValue #

convTo is a convenience function that converts natively typed values to PHPSessionValue, with the resulting PHP type determined by the type cast or inferred.

arrayOfPHPStrings :: PHPSessionValue
arrayOfPHPStrings =
  let str1 = "Hello" :: BS.ByteString
      str2 = "World"
   in convTo [(0 :: Int, str1), (1, str2)]

In the above example code, the OverloadedStrings language extension is assumed.

Convert from PHPSessionValue

convFrom :: ConversionFromPHPValueOrMismatch b => PHPSessionValue -> b #

convFrom and convFromSafe are convenience functions that translate PHP values stored as PHPSessionValue into appropriate Haskell types depending on the desired type cast or inferred. Functions provided in this module provide non-coerced type translations and so will either carry on the translation or signal the fact that the attempted conversion will alter the type of the value. For situations where altering value types is expected, alternative conversion functions with similar type signatures are provided in modules within Data.PHPSession.ImplicitConv.

The example arrayOfPHPStrings definition given in convTo can be reverted back to Haskell types, which evaluates to [(0,"Hello"),(1,"World")].

>>> convFrom arrayOfPHPStrings :: [(Int,LBS.ByteString)]
[(0,"Hello"),(1,"World")]

However, if the desired type signature is changed to a completely different type, then a runtime exception is thrown:

>>> convFrom arrayOfPHPStrings :: [(Int,Int)]
*** Exception: Type mismatch converting from (PHPSessionValueString "Hello") to Int

Where there is the possibility that the value being sought may be NULL, the type should be (Maybe a).

convFromSafe :: ConversionFromPHPValueOrMismatch b => PHPSessionValue -> Either String b #

A version of convFrom which returns a Left with an error message instead of throwing an exception.

Type classes

class ConversionToPHPValue a where #

Methods

convTo' :: a -> PHPSessionValue #

Instances
ConversionToPHPValue Bool # 
Instance details

Defined in Data.PHPSession.Conv

ConversionToPHPValue Double # 
Instance details

Defined in Data.PHPSession.Conv

ConversionToPHPValue Int # 
Instance details

Defined in Data.PHPSession.Conv

ConversionToPHPValue Int32 # 
Instance details

Defined in Data.PHPSession.Conv

ConversionToPHPValue Int64 # 
Instance details

Defined in Data.PHPSession.Conv

ConversionToPHPValue ByteString # 
Instance details

Defined in Data.PHPSession.Conv

ConversionToPHPValue ByteString # 
Instance details

Defined in Data.PHPSession.Conv

ConversionToPHPValue PHPSessionValue # 
Instance details

Defined in Data.PHPSession.Conv

(ConversionToPHPValue a, ConversionToPHPValue b) => ConversionToPHPValue [(a, b)] # 
Instance details

Defined in Data.PHPSession.Conv

Methods

convTo' :: [(a, b)] -> PHPSessionValue #

ConversionToPHPValue [(PHPSessionValue, PHPSessionValue)] # 
Instance details

Defined in Data.PHPSession.Conv

ConversionToPHPValue a => ConversionToPHPValue (Maybe a) # 
Instance details

Defined in Data.PHPSession.Conv

ConversionToPHPValue (PHPSessionClassName, [(PHPSessionValue, PHPSessionValue)]) # 
Instance details

Defined in Data.PHPSession.Conv

ConversionToPHPValue (PHPSessionClassName, ByteString) # 
Instance details

Defined in Data.PHPSession.Conv

class ConversionFromPHPValueOrMismatch b where #

Instances
ConversionFromPHPValueOrMismatch Bool # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch Double # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch Int # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch Int32 # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch Int64 # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch ByteString # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch ByteString # 
Instance details

Defined in Data.PHPSession.Conv

(ConversionFromPHPValueOrMismatch a, ConversionFromPHPValueOrMismatch b) => ConversionFromPHPValueOrMismatch [(a, b)] # 
Instance details

Defined in Data.PHPSession.Conv

Methods

convFromOM :: PHPSessionValue -> Either String [(a, b)] #

ConversionFromPHPValueOrMismatch a => ConversionFromPHPValueOrMismatch [(a, PHPSessionValue)] # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch b => ConversionFromPHPValueOrMismatch [(PHPSessionValue, b)] # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch [(PHPSessionValue, PHPSessionValue)] # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch a => ConversionFromPHPValueOrMismatch (Maybe a) # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch (Either Double ByteString) # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch (Either Double ByteString) # 
Instance details

Defined in Data.PHPSession.Conv

Integral n => ConversionFromPHPValueOrMismatch (Either n ByteString) # 
Instance details

Defined in Data.PHPSession.Conv

Integral n => ConversionFromPHPValueOrMismatch (Either n ByteString) # 
Instance details

Defined in Data.PHPSession.Conv

Integral n => ConversionFromPHPValueOrMismatch (Either n Double) # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch (PHPSessionClassName, [(PHPSessionValue, PHPSessionValue)]) # 
Instance details

Defined in Data.PHPSession.Conv

ConversionFromPHPValueOrMismatch (PHPSessionClassName, ByteString) # 
Instance details

Defined in Data.PHPSession.Conv