Download the PHP package dedsecteam17/soft-mapper without Composer

On this page you can find all versions of the php package dedsecteam17/soft-mapper. 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 soft-mapper

Soft-Mapper

PHP Version Status Version Packagist Packagist Downloads

A lightweight, powerful, and easy-to-use PHP ORM (Object-Relational Mapping) library for MySQL databases. Soft-Mapper provides a clean and intuitive interface for database operations with built-in security features and advanced ORM capabilities.

🚀 What's New in v2.0

Version 2.0 brings 27 new methods and advanced ORM features that make Soft-Mapper comparable to Laravel's Eloquent:

📚 Documentation:

Table of Contents

Features

Core Features

Advanced Features ⭐ NEW

Requirements

Installation

Using Composer (Recommended)

Install via Composer:

Then include the autoloader in your project:

Manual Installation

  1. Clone this repository or download the files:

  2. Include the library in your project:

Using as a Git Submodule

Then include in your code:

Quick Start

Configuration

Database Configuration

Edit env.php to configure your database connection:

Environment-Specific Configuration

For production environments, consider using environment variables:

Usage

Creating Models

Each model represents a database table. Extend the SoftMapper class:

Basic CRUD Operations

Create (Insert)

Insert new records into the database:

Read (Select)

Find by ID:

Get All Records:

Get Single Record:

Select Specific Columns:

Update

Update existing records:

Update Multiple Records:

Delete

Delete records from the database:

Delete Multiple Records:

Advanced Queries

WHERE Clauses

Simple WHERE:

Multiple Conditions with AND:

Using Different Operators:

ORDER BY

Order Descending:

Order Ascending:

LIMIT

Limit Results:

Pagination Example:

Combining Multiple Clauses

Aggregate Functions

COUNT

Count all records:

Count with GROUP BY:

SUM, AVG, MIN, MAX

HAVING Clause

Use HAVING with aggregate functions:

Advanced Features

Automatic Timestamps

Enable automatic timestamp management for created_at and updated_at columns:

Soft Deletes

Soft delete marks records as deleted without removing them from the database:

Custom Primary Keys

Override the default 'id' primary key:

Pagination with OFFSET

Full pagination support:

Batch Insert

Insert multiple records efficiently:

Advanced WHERE Clauses

WHERE IN

WHERE NOT IN

WHERE BETWEEN

WHERE NULL / WHERE NOT NULL

Query Scopes

Define reusable query constraints:

JOIN Operations

Perform table joins:

Helper Methods

first()

Get the first record:

count()

Count records:

exists()

Check if records exist:

pluck()

Get a single column's values:

Transaction Support

Manage database transactions:

Raw Queries

Execute custom SQL:

Chunking

Process large datasets efficiently:

Update or Create

Update existing record or create new one:

Distinct Results

Get unique records:

Get Last Insert ID

ORM Relationships

Soft-Mapper now supports defining and querying relationships between models, making it easy to work with related data.

Defining Relationships

Define relationships in your model classes:

Loading Relationships

Lazy Loading (load relationships as needed):

Eager Loading (load relationships efficiently for multiple records):

Many-to-Many Operations

Manage many-to-many relationships with pivot table operations:

Complete Example

📚 For complete relationship documentation, see RELATIONSHIPS.md

API Reference

Core Methods

Method Parameters Returns Description
all() None $this Selects all records from table
select() array $columns, string $aggregate, string $parameter $this Select specific columns with optional aggregate
find() mixed $id object\|null Find record by primary key
insert() None bool Insert new record using $columns array
update() None $this Update records (use with where())
delete() bool $force $this Delete records (supports soft delete)
where() array $conditions $this Add WHERE conditions
orderBy() string $column, string $direction $this Order results
groupBy() string $column $this Group results
having() array $conditions $this Add HAVING conditions
limit() int $number $this Limit number of results
offset() int $number $this Offset for pagination
getAll() None array Execute query and fetch all results
get() None object\|null Execute query and fetch single result
execute() None bool Execute query (for UPDATE/DELETE)

Advanced Methods

Method Parameters Returns Description
withTrashed() None $this Include soft deleted records
onlyTrashed() None $this Get only soft deleted records
restore() None $this Restore soft deleted records
insertMany() array $records bool Insert multiple records at once
whereIn() string $column, array $values $this WHERE IN clause
whereNotIn() string $column, array $values $this WHERE NOT IN clause
whereBetween() string $column, mixed $start, mixed $end $this WHERE BETWEEN clause
whereNull() string $column $this WHERE NULL clause
whereNotNull() string $column $this WHERE NOT NULL clause
first() None object\|null Get the first record
count() None int Count records
exists() None bool Check if records exist
pluck() string $column array Get single column values
scope() string $name, callable $callback void Define a query scope
applyScope() string $name, ...$args $this Apply a query scope
beginTransaction() None bool Start a database transaction
commit() None bool Commit a database transaction
rollback() None bool Rollback a database transaction
raw() string $query, array $params mixed Execute raw SQL query
lastInsertId() None string Get last inserted ID
chunk() int $size, callable $callback void Process results in chunks
join() string $table, string $first, string $op, string $second, string $type $this Join tables
leftJoin() string $table, string $first, string $op, string $second $this LEFT JOIN
rightJoin() string $table, string $first, string $op, string $second $this RIGHT JOIN
distinct() None $this Get distinct records
updateOrCreate() array $attributes, array $values bool Update existing or create new record

Relationship Methods

Method Parameters Returns Description
hasOne() string $class, string $foreign_key, string $local_key $this Define one-to-one relationship
hasMany() string $class, string $foreign_key, string $local_key $this Define one-to-many relationship
belongsTo() string $class, string $foreign_key, string $owner_key $this Define inverse relationship
belongsToMany() string $class, string $pivot, string $foreign_key, string $related_key $this Define many-to-many relationship
loadRelation() string $name, object $record object Load a relationship for a record
with() array $relations $this Eager load relationships
attach() mixed $id, mixed $related_id, string $relation, array $pivot_data bool Attach in many-to-many
detach() mixed $id, string $relation, mixed $related_id bool Detach in many-to-many
sync() mixed $id, array $related_ids, string $relation bool Sync many-to-many relationships

Condition Array Format

For where() and having() methods:

Supported Operators: =, >, <, >=, <=, !=, <>

Logical Operators: AND, OR

Examples

See the example.php file for complete working examples. Here are some real-world scenarios:

Blog Post Management

User Management

Security

SQL Injection Protection

Soft-Mapper uses PDO prepared statements for all database queries, which automatically protects against SQL injection attacks. User input is never directly concatenated into SQL queries.

Best Practices

  1. Never expose database credentials: Keep env.php outside your web root or use environment variables
  2. Validate user input: Even though SQL injection is prevented, validate data types and formats
  3. Hash passwords: Always use password_hash() for storing passwords
  4. Sanitize output: Use htmlspecialchars() when displaying data in HTML
  5. Use HTTPS: Encrypt data in transit
  6. Implement access controls: Check user permissions before database operations

Example with validation:

Troubleshooting

Common Issues

1. PDO Connection Error

Solution: Check your database configuration in env.php. Ensure MySQL is running.

2. Table doesn't exist

Solution: Verify that $table_name in your model matches your actual database table name.

3. Column not found

Solution: Ensure column names in $columns array match your database schema.

4. Class 'PDO' not found

Solution: Enable the PDO and PDO_MySQL extensions in your php.ini:

Debug Mode

To see the generated SQL queries, you can temporarily add debugging to the SoftMapper class:

Getting Help

If you encounter issues:

  1. Check the examples section
  2. Review your database configuration
  3. Verify your table and column names
  4. Check PHP and MySQL versions meet requirements
  5. Open an issue on GitHub

Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes: Implement your feature or bug fix
  4. Test your changes: Ensure everything works as expected
  5. Commit your changes: git commit -m 'Add amazing feature'
  6. Push to the branch: git push origin feature/amazing-feature
  7. Open a Pull Request

Development Guidelines

License

This project is open source and available under the MIT License. Feel free to use, modify, and distribute this software.

Author

Mohammed Elamin


Star this Repository ⭐

If you find Soft-Mapper useful, please consider giving it a star on GitHub. It helps others discover the project!

Support

For questions, issues, or feature requests, please visit:


Happy Coding! 🚀


All versions of soft-mapper with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
ext-pdo Version *
ext-pdo_mysql Version *
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 dedsecteam17/soft-mapper contains the following files

Loading the files please wait ...