AthenaeumAthenaeum
Packages
  • next
  • current
  • v9.x
  • v8.x
  • v7.x
  • v6.x
  • v5.x
  • v4.x
  • v3.x
  • v2.x
  • v1.x
Changelog
GitHub
Packages
  • next
  • current
  • v9.x
  • v8.x
  • v7.x
  • v6.x
  • v5.x
  • v4.x
  • v3.x
  • v2.x
  • v1.x
Changelog
GitHub
  • Version 4.x

    • Release Notes
    • Upgrade Guide
    • New to this...
    • Origin
  • Circuits

    • Circuits
    • How to install
    • Setup
    • Usage
    • Events
  • Config

    • Configuration Loader
    • How to install
    • Setup
    • Load Configuration Files
    • Custom File Parsers
  • Console

    • Command and Schedule Registration
    • How to install
    • Setup
    • Commands
    • Schedules
  • Container

    • IoC Service Container
    • How to install
    • registerAsApplication()
    • destroy()
  • Core

    • Athenaeum Core Application
    • Prerequisite
    • How to install
    • Integration
    • Usage

      • Configuration
      • Service Providers
      • Service Container
      • Events
      • Caching
      • Logging
      • Console
      • Task Scheduling
      • Exception Handling
      • Extending Core Application
      • Testing
  • Dto

    • Data Transfer Object (DTO)
    • How to install
    • Create Interface
    • Implement DTO
    • How to use
    • Populate
    • Export
    • Json
    • Serialization
    • Nested DTOs
    • Array DTO
  • Events

    • Register Listeners and Subscribers
    • How to install
    • Setup
    • Listeners
    • Subscribers
  • Http

    • Clients

      • Http Clients
      • How to install
      • Setup
      • Basic Usage
      • Available Methods

        • Fluent Api
        • Protocol Version
        • Base Uri
        • Http Method and Uri
        • Headers
        • Accept & Content-Type
        • Authentication
        • Http Query
        • Payload Format
        • Payload
        • Attachments
        • Cookies
        • Response Expectations
        • Conditions
        • Criteria
        • Redirects
        • Timeout
        • Driver Options
        • Driver
      • Http Query Builder

        • Introduction
        • Select
        • Where
        • Dates
        • Include
        • Pagination
        • Sorting
        • Raw Expressions
        • Custom Grammar
    • Cookies

      • Http Cookies
      • How to install
      • Usage
  • Properties

    • Properties Overload
    • How to install
    • Usage
    • Naming Convention
    • Properties Visibility
  • Service

    • Service Registrar
    • How to install
    • How to use
  • Support

    • Introduction
    • How to install
    • Laravel Aware-of Helpers

      • How to use
      • Enforce Via Interface
      • Custom Default
      • Pros and Cons
      • Available Helpers
    • Aware-of Properties

      • Generator
      • Available Aware-of Helpers
    • Live Templates
  • Testing

    • Introduction
    • How to install
    • Test Cases
    • Testing Aware-of Helpers
  • Utils

    • Introduction
    • How to install
    • Array
    • Json
    • Math
    • Method Helper
    • Populatable
    • Version
You are viewing documentation for an outdated version. It is no longer supported!

Usage

There are two DTOs that you can choose from; Cookie and SetCookie.

Cookie

The Cookie object only contains a name and value property.

<?php
use Aedart\Http\Cookies\Cookie;

$cookie = new Cookie([
    'name' => 'my_cookie',
    'value' => 'sweet'
]);

See mozilla.org for additional information about what the Cookie DTO is intended to represent.

Set-Cookie

The SetCookie is an extended version of the Cookie DTO. It offers the following properties

  • name: Cookie name
  • value: Cookie value
  • expires: Maximum lifetime of the cookie
  • maxAge: Number of seconds until the cookie expires.
  • domain: Hosts to where the cookie will be sent
  • path: Path that must exist on the requested url
  • secure: State of whether the cookie should be sent via https
  • httpOnly: Whether or not accessing the cookie is forbidden via JavaScript.
  • sameSite: whether cookie should be available for cross-site requests
<?php
use Aedart\Http\Cookies\SetCookie;

$cookie = new SetCookie([
    'name' => 'my_cookie',
    'value' => 'sweet',
    'expires' => null, // null, timestamp or RFC7231 Formatted string date 
    'maxAge' => 60 * 5,
    'domain' => null,
    'path' => '/',
    'secure' => true,
    'httpOnly' => false,
    'sameSite' => SetCookie::SAME_SITE_LAX
]);

See mozilla.org for additional information about what the SetCookie DTO is intended to represent.

Populate

The Cookie DTOs can be populated from an array, via the popualte() method.

$cookie->populate([
    'name' => 'my_other_cookie'
]);

echo $cookie->getName(); // "my_other_cookie"

Export to Array

Both DTOs are able to export their properties to an array, via the toArray() method.

$data = $cookie->toArray();

Onward

Please review the source code of these DTOs, for additional information. Feel free to extend these components and offer more functionality, should your application require such.

Edit page
Last Updated: 08/09/2020, 18:52
Contributors: Alin Eugen Deac
Prev
How to install