Skip to content

Instantly share code, notes, and snippets.


Mostafa Soufi mostafasoufi

View GitHub Profile
davejamesmiller /
Last active May 4, 2021
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

arubacao / latlong.php
Last active Apr 28, 2021
Latitude Longitude Regular Expression Validation PHP
View latlong.php
* Validates a given latitude $lat
* @param float|int|string $lat Latitude
* @return bool `true` if $lat is valid, `false` if not
function validateLatitude($lat) {
return preg_match('/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$/', $lat);
theMikeD / acf.php
Last active Dec 19, 2018
Changes the folder where ACF loads and saves the JSON file to and from
View acf.php
add_filter('acf/settings/save_json', 'cnmd_set_acf_json_save_folder');
add_filter('acf/settings/load_json', 'cnmd_add_acf_json_load_folder');
* Set a new location to save ACF field group JSON
* @param string $path
* @return string
james2doyle / simple-json-reponse.php
Last active Apr 30, 2021
A simple JSON response function for PHP. Used in various PhileCMS plugins.
View simple-json-reponse.php
function json_response($code = 200, $message = null)
// clear the old headers
// set the actual code
// set the header to make sure cache is forced
header("Cache-Control: no-transform,public,max-age=300,s-maxage=900");
yaronguez / ACF Country List
Created Feb 17, 2015
Country list formatted for Advanced Custom Fields select dropdown
View ACF Country List
afghanistan : Afghanistan
albania : Albania
algeria : Algeria
american_samoa : American Samoa
andorra : Andorra
angola : Angola
anguilla : Anguilla
antigua_and_barbuda : Antigua and Barbuda
argentina : Argentina
armenia : Armenia
rileypaulsen / functions.php
Created Aug 19, 2014
Add Advanced Custom Fields Fields to the WP REST API
View functions.php
function wp_api_encode_acf($data,$post,$context){
$data['meta'] = array_merge($data['meta'],get_fields($post['ID']));
return $data;
if( function_exists('get_fields') ){
add_filter('json_prepare_post', 'wp_api_encode_acf', 10, 3);
alexpchin /
Created Jun 1, 2014
Add Existing Project To Git Repo

#Adding an existing project to GitHub using the command line

Simple steps to add existing project to Github.

1. Create a new repository on GitHub.

In Terminal, change the current working directory to your local project.

##2. Initialize the local directory as a Git repository.

git init
amacgregor / UserSingleton.php
Last active Mar 9, 2021
PHP Singleton pattern example
View UserSingleton.php
/** Example taken from **/
class User
// Hold an instance of the class
private static $instance;
// The singleton method
llbbl /
Last active Apr 29, 2021 — forked from ziadoz/
Awesome PHP Libraries and Resources

Awesome PHP

A list of amazingly awesome PHP libraries, resources and shiny things.


  • Composer
  • Composer Related
  • Frameworks
  • Micro Frameworks
reaneyk / gist:6604607
Created Sep 18, 2013
Example PHP Interface class
View gist:6604607
//Define a new Interface for all 'shapes' to inherit
interface Shape {
//Define the methods required for classes to implement
public function getColor();
public function setColor($color);