1. Go to this page and download the library: Download neuron-php/core library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Neuron\Core\NArray;
// Create an array object
$arr = new NArray(['apple', 'banana', 'cherry']);
// Safe element access with defaults
$first = $arr->getElement(0, 'default'); // 'apple'
$missing = $arr->getElement(10, 'none'); // 'none'
// Transformations with method chaining
$result = $arr->filter(fn($item) => strlen($item) > 5)
->map(fn($item) => ucfirst($item))
->sort();
use Neuron\Core\NString;
$str = new NString(' Hello World ');
// Length operations
echo $str->length(); // 15
// Trimming
echo $str->trim(); // 'Hello World'
$str = new NString('The quick brown fox');
// Position-based extraction
echo $str->left(9); // 'The quick'
echo $str->right(3); // 'fox'
echo $str->mid(4, 8); // 'quick'
$str = new NString(' Hello World ');
echo $str->toUpper(); // ' HELLO WORLD '
echo $str->toLower(); // ' hello world '
$str = new NString('hello_world_example');
// Snake case to PascalCase and camelCase
echo $str->toPascalCase(); // 'HelloWorldExample'
echo $str->toCamelCase(); // 'helloWorldExample'
// PascalCase/camelCase to snake case
$camel = new NString('HelloWorldExample');
echo $camel->toSnakeCase(); // 'hello_world_example'
// Mixed case handling
$mixed = new NString('getUserID');
echo $mixed->toSnakeCase(); // 'get_user_id'
// Property hooks (PHP 8.4+)
$str = new NString('test');
$str->value = 'new value'; // Uses setter hook
echo $str->value; // Uses getter hook
// Note: NString methods return strings, not NString objects,
// so method chaining is not directly supported
use Neuron\Core\NArray;
$arr = new NArray([1, 2, 3, 4, 5]);
// Array information
echo $arr->count(); // 5
echo $arr->isEmpty(); // false
echo $arr->isNotEmpty(); // true
// Element checks
echo $arr->contains(3); // true
echo $arr->hasKey(2); // true
// Get first and last elements
echo $arr->first(); // 1
echo $arr->last(); // 5
// Find index of element
echo $arr->indexOf(3); // 2
// Remove element by value
$arr->remove(3); // Removes 3 from array
$arr = new NArray(['a' => 1, 'b' => 2, 'c' => 3]);
// Get element with default fallback
$value = $arr->getElement('a', 0); // 1
$missing = $arr->getElement('d', -1); // -1 (default)
// Check and get
if ($arr->hasKey('b')) {
$value = $arr->getElement('b');
}
use Neuron\Core\Exceptions\Base;
// All Neuron exceptions extend Base
class CustomException extends Base
{
public function __construct($message = "")
{
parent::__construct($message, 0, null);
}
}
try {
throw new CustomException("Something went wrong");
} catch (Base $e) {
// Handle any Neuron exception
echo $e->getMessage();
}
use Neuron\Core\Exceptions\NotFound;
use Neuron\Core\Exceptions\PropertyNotFound;
use Neuron\Core\Exceptions\CommandNotFound;
use Neuron\Core\Exceptions\MapNotFound;
// Generic not found
throw new NotFound("Resource not found");
// Property not found on object
throw new PropertyNotFound("Property 'email' not found on User object");
// Command not found in CLI
throw new CommandNotFound("Command 'deploy' not found");
// Route map not found
throw new MapNotFound("Route '/api/users' not found");
use Neuron\Core\Exceptions\Validation;
// Validation failure with details
$errors = [
'email' => 'Invalid email format',
'age' => 'Must be 18 or older'
];
throw new Validation("Validation failed", $errors);
use Neuron\Core\Exceptions\MissingMethod;
use Neuron\Core\Exceptions\BadRequestMethod;
// Method missing on class
throw new MissingMethod("Method 'save' not found on class User");
// Invalid HTTP request method
throw new BadRequestMethod("Method DELETE not allowed for this endpoint");
use Neuron\Core\Exceptions\RouteParam;
// Missing or invalid route parameter
throw new RouteParam("Required parameter 'id' missing from route");
use Neuron\Core\Exceptions\EmptyActionParameter;
// Action called with empty
use Neuron\Core\H\Error;
// File system errors
$code = Error::ENOENT; // 2 - No such file or directory
$code = Error::EACCES; // 13 - Permission denied
$code = Error::EEXIST; // 17 - File exists
// Memory errors
$code = Error::ENOMEM; // 12 - Out of memory
// I/O errors
$code = Error::EIO; // 5 - I/O error
$code = Error::EBUSY; // 16 - Device or resource busy
$code = Error::ENOSPC; // 28 - No space left on device
// Example usage
function readFile($path) {
if (!file_exists($path)) {
return ['error' => Error::ENOENT, 'message' => 'File not found'];
}
if (!is_readable($path)) {
return ['error' => Error::EACCES, 'message' => 'Permission denied'];
}
// Read file...
}
use PHPUnit\Framework\TestCase;
use Neuron\Core\NString;
class NStringTest extends TestCase
{
public function testCamelCase(): void
{
$str = new NString('hello_world');
$this->assertEquals('HelloWorld', $str->toCamelCase());
$this->assertEquals('helloWorld', $str->toCamelCase(false));
}
public function testStringExtraction(): void
{
$str = new NString('Hello World');
$this->assertEquals('Hello', $str->left(5));
$this->assertEquals('World', $str->right(5));
$this->assertEquals('llo W', $str->mid(2, 6));
}
}
// Use NString for complex string manipulation
$email = new NString(' [email protected] ');
$normalized = $email->trim()->toLower();
// Chain operations for readability
$slug = (new NString('Product Name 2024'))
->toLower()
->replace(' ', '-')
->replace('2024', '');
// Use NArray for safe array access
$config = new NArray($configData);
$dbHost = $config->getElement('host', 'localhost');
// Leverage functional programming
$activeUsers = (new NArray($users))
->filter(fn($u) => $u['active'])
->map(fn($u) => $u['email'])
->unique();
// Use specific exceptions for clarity
try {
$property = $object->getProperty('nonexistent');
} catch (PropertyNotFound $e) {
// Handle missing property
$property = $defaultValue;
} catch (Base $e) {
// Handle other Neuron exceptions
$logger->error($e->getMessage());
}
// Leverage PHP 8.4+ features
function processArray(NArray $data): NArray
{
return $data->filter(fn($item) => $item !== null)
->map(fn($item) => processItem($item));
}
// Used by Validation component
use Neuron\Core\Exceptions\Validation;
class EmailValidator
{
public function validate($value): void
{
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
throw new Validation("Invalid email format");
}
}
}
// Used by Data component
use Neuron\Core\NArray;
class DataFilter
{
public function filterData(array $data): NArray
{
return (new NArray($data))
->filter(fn($item) => $item !== null)
->unique();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.