GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • 🐴 Roach
  • Docs
  • Github

This view

  • Original page
  • New address

GeezerVison is showing roach-php.dev — Items — Roach PHP

Introduction
  • Getting Started
    • Installation
    • Releases
    • Upgrade Guide
    • Scraping versus Crawling
  • Basic Concepts
    • Spiders
    • Processing Responses
    • Items
    • Item Pipeline
    • Interactive Shell
  • Advanced Usage
    • Spider Middleware
    • Downloader Middleware
    • Extensions
    • Configuring Middleware and Extensions
    • Dependency Injection
    • Testing
  • Framework Integration
    • Laravel
    • Symfony

Basic Concepts

Items

An abstraction about data extracted from web documents.

Items represent data that was extracted from documents. They are simple abstraction around PHP arrays that are more comfortable to work with than plain arrays.

Using Items

Since an Item is just a simple wrapper around a plain PHP array, it has a rather straight-forward API.

<?php
  
use RoachPHP\Support\DroppableInterface;
  
interface ItemInterface extends DroppableInterface, ArrayAccess
{
    /**
     * Returns the underlying data array.
     */
    public function all(): array;
  
    /**
     * Set a value on the item for the provided `$key`.
     */
    public function set(string $key, mixed $value): self;
  
    /**
     * Retrieve the value for `$key` or return `$default` instead.
     */
    public function get(string $key, mixed $default = null): mixed;
  
    /**
     * Checks if `$key` exists on the item. Note that this checks
     * if `$key` exists on the underlying data array, not if the
     * value is truthy.
     */
    public function has(string $key): bool;
}

Most of the time, you won’t directly create instances of an Item, but use the spider’s item() method instead. When writing ItemProcessors, however, this is the interface you will be dealing with.

On this page
  • Using Items
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.