Download the PHP package tobento/service-view without Composer

On this page you can find all versions of the php package tobento/service-view. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package service-view

View Service

The View Service provides a simple yet flexible way to create and render views.
It brings together rendering, shared data, and asset management into a unified and extensible system, making it easy to build structured and maintainable templates.

Table of Contents

Getting started

Add the latest version of the view service project running this command.

Requirements

Highlights

Simple Example

Here is a simple example of how to use the View service.
We will assume the following directory structure:

Create and render a view

The view template

Documentation

Data

The Data class provides a flexible way to manage variables passed to your views.
You can set global data available to all views, or target specific views individually.
Data can be added, renamed, retrieved, or merged, giving you full control over what each view receives.

Assets

The Assets class provides a convenient way to register, organize, and render assets such as CSS, JavaScript, or any other file-based resources your application needs.
It acts as a lightweight collection where each asset can define its own file path, directory, URI, attributes, group, and render order.

You can also attach an AssetsHandlerInterface implementation to enable advanced features like minification, combining, or rewriting imports.
By default, assets are only collected and rendered as placeholders until you flush them.

Assets Handler

The AssetsHandler provides a flexible way to process and build assets without modifying any view files.
It supports:

This enables a streamlined build process and ensures that optimized, versioned assets are used consistently throughout your views.

Requirements

The AssetsHandler requires the Minify Service:

Why this is useful

Notes

Example

All methods return a new instance, allowing fluent configuration:

Note
Imported JS files are only re-processed when the root asset is defined in the view.
For example:

If the root file is not referenced in the view, changes inside imported files will not trigger an update in the build output unless those imported files are also defined as separate assets.

JavaScript import handling

The asset handler supports rewriting relative JavaScript imports for cache-busting.
Only .js files are processed. CSS and other asset types are not rewritten.

Supported JavaScript import patterns

The following ES module import schemes are recognized and rewritten with versioning:

Pattern type Example Supported
Same-directory relative import import a from './foo.js' yes
Parent-directory import import b from '../bar.js' yes
Complex relative paths import c from './../baz.js' yes
Deep relative paths import d from '../../utils/qux.js' yes
Normalized paths (./, ../) import e from './nested/../weird/path.js' yes
Circular imports a.js → b.js → a.js yes
Duplicate imports import x from './foo.js' twice yes (deduped)

All resolved imports are:

Unsupported import patterns

The handler intentionally does not process or rewrite the following:

Pattern type Example Reason
CSS imports import './styles.css' CSS is not rewritten or versioned
JSON imports import data from './data.json' Not part of the JS pipeline
Bare module imports import React from 'react' Cannot resolve without node_modules
Dynamic imports import('./foo.js') Not matched by the static import detection
Extensionless imports import x from './foo' Resolver requires a .js extension
Directory imports import utils from './utils' No index.js resolution is performed

These imports remain unchanged in the output.

JavaScript combining

JavaScript combining is supported, but it is not equivalent to bundling.
When multiple JS files are combined, the handler simply concatenates their contents in the order provided.

Because of this:

Combining JavaScript is therefore only suitable when the files are already structured in a way that allows safe concatenation.

Recommendation:
Use JavaScript combining only for files that do not rely on ES module ordering, or when using a modifier that explicitly supports import rewriting. Without such a modifier, JS files are processed individually, and combining is primarily intended for CSS assets.

Renderer

PHP Renderer

The PHP renderer uses native PHP as its templating language, so there is no new syntax to learn.
It also integrates with the Dir Service, which provides a simple and flexible way to organize and prioritize your template directories.

Chain Renderer

The chain renderer allows you to combine multiple renderers into a single rendering pipeline.
If the first renderer cannot handle a view, the next renderer in the chain is tried, and so on.
This makes it easy to mix different rendering engines (e.g., PHP, Twig) in the same application.

View

Usage

The View class ties everything together: a renderer, shared data, and asset management.
It provides a simple API for rendering templates, passing data, registering view aliases, and hooking into the rendering process with event callbacks.

Auto Rendering Views

You may automatically render a view before or after another view is rendered.
This is useful for injecting reusable UI fragments (meta tags, banners, notifications, tracking scripts) without modifying templates.

View Callbacks (on)

You may hook into the rendering process of a specific view and modify its data before it is rendered.
This is useful for preparing dynamic data, registering view aliases, or conditionally preventing rendering.

Wildcard Example

Example with key and add()

This example registers an alias so that rendering comments.writing will load the comments/writing view.

Template

A template is simply a PHP file rendered by the view system.
You can access the $view instance inside any template, allowing you to escape values, include subviews, register assets, or conditionally render content.

Macros

Macros allow you to extend the View class with your own custom helper methods.
This makes it easy to add reusable functionality directly on the view instance without creating subclasses.

Tags Attributes Macro

The Tags Attributes macro provides a convenient way to collect and manage HTML attributes for specific tags.
By registering the macro on the view instance, you can easily retrieve an AttributesInterface object and work with attributes in a structured way.

Check out the Tag Service - Attributes Interface to learn more about how attributes work in general.

Credits


All versions of service-view with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4
psr/log Version ^3.0
tobento/service-macro Version ^2.0
tobento/service-filesystem Version ^2.0
tobento/service-dir Version ^2.0
tobento/service-support Version ^2.0
tobento/service-tag Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tobento/service-view contains the following files

Loading the files please wait ...