Download the PHP package sourcepot/asset without Composer
On this page you can find all versions of the php package sourcepot/asset. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sourcepot/asset
More information about sourcepot/asset
Files in sourcepot/asset
Package asset
Short Description PHP class providing an asset object
License MIT
Homepage https://datapool.info
Informations about the package asset
Installation
You can use Packagist to install the package on a web server or your lacal computer, e.g. Command Prompt, enter composer create-project sourcepot/asset {add your target directory here}.
The following code examples require the namespace to be set to namespace SourcePot\Asset;.
Features
- Creation and manipulation of an Asset object representing a value, wealth, etc.
- Creation of a Rates object providing currency names and exchange rates
- Creation of a DateTimeParser object providing representing a date and time at a specified timezone, parsing timestamps or strings to DateTimeParser object
- Calculations make use of Money PHP (
moneyphp/money) and BC Math
The Asset class
The asset class of this package can be used to create objects representing an asset. The main properties of such an asset are "value", "unit" and "dateTime", e.g. 1 (value) Euro (unit) on 12/03/2023. These three properties need to be provided to the contructor of a new asset object. If a different unit is set, the exchange rate is applied to the asset object and the dateTime will be updated to the excchange rate dateTime.
[!NOTE] European Central Bank exhchage rates are used. If an exchage rate is not yet present as csv-file in the data directory, it will be downloaded via the ECB API and saved to data directory. If an exchange rate is requested for a weekend (such as in the code sample below) or bank holiday, the latest valid exchange rate before that date will be used and a warning will be added as asset property.
The Asset class
Method \SourcePot\Asset\Asset::getArray() returns an array with derived asset properties including any warnings or errors.
An asset can be added to the asset object using the method \SourcePot\Asset\Asset::addAsset(float $value=0,string $unit=self::DEFAULT_UNIT,\DateTime $dateTime=NULL) and providing the respective asset properties. In the following example the asset is 100 EUR (2024-01-01T00:00:00+01:00) and an amount of 100 GBP is added on December 01, 2024:
Method \SourcePot\Asset\Asset::setFromString(string $string,string $unit=self::DEFAULT_UNIT,\DateTime $dateTime=NULL) provides a string parser. The method loads the asset derived from the string to the asset object. If the currency can't be derived, the default is used and if dateTime is not provided, DateTime('now') will be used.
The Rates class
The Rates class supports the Asset class with unit conversion. Currencies are subset of units. The following code example creates a Rates object and retunrs available currencies.
The DateTimeParser class
The DateTimeParser class provides methods for creating/updating a DateTime object from timestamps or strings. The following example creates a DateTimeParser object, sets a new state by parsing a string and outputs the DateTimeParser object. Since the setFromString() method is called without the timezone argument, the default timezone is used. The time zone is therefore changed from Asia/Tokyo to Europe/Berlin. The setFromString() method supports very different date/time formats. A timezone is only recognized in the string if the spelling corresponds exactly to a php time zone.
// the default timezone is Europe/Berlin, the parsed sting will return 2014-08-02T05:34:56+02:00 echo $asset;
Evaluation web page
An evaluation web page is provided with this package.
The webpage allows:
- flexible creation of an asset object,
- asset conversion to US-Dollars and
- adding yearly interest.
Here is a screenshot of the evaluation web page: