idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
54,000
|
public static function fromData ( array $ data ) { $ class = get_called_class ( ) ; $ isDynamic = is_a ( $ class , DynamicEntity :: class , true ) ; $ entity = ( new \ ReflectionClass ( $ class ) ) -> newInstanceWithoutConstructor ( ) ; object_set_properties ( $ entity , $ data , $ isDynamic ) ; if ( method_exists ( $ entity , '__construct' ) ) { $ entity -> __construct ( ) ; } $ entity -> markNew ( false ) ; return $ entity ; }
|
Create an entity from persisted data .
|
54,001
|
public function markAsPersisted ( ) : void { $ this -> markNew ( false ) ; $ this -> dispatchEvent ( new Event \ Persisted ( $ this ) ) ; }
|
Mark entity as persisted .
|
54,002
|
public function validate ( $ page , Constraint $ constraint ) { if ( ! $ page instanceof CreateAction && ! $ page instanceof Page ) { throw new \ InvalidArgumentException ( sprintf ( '%s can only validate %s or %s objects; %s given.' , self :: class , Page :: class , CreateAction :: class , is_object ( $ page ) ? get_class ( $ page ) : gettype ( $ page ) ) ) ; } if ( $ actualPage = $ this -> pageLoader -> retrieveByPath ( $ page instanceof CreateAction ? $ page -> getFullPath ( ) : $ page -> getPath ( ) ) ) { $ this -> context -> buildViolation ( $ constraint -> message ) -> atPath ( 'path' ) -> setParameter ( '{{ name }}' , $ actualPage -> getName ( ) ) -> setParameter ( '{{ path }}' , $ actualPage -> getPath ( ) ) -> setParameter ( '{{ parent }}' , $ actualPage -> getParent ( ) -> getName ( ) ) -> addViolation ( ) ; } }
|
Validate given page path is unique . Works with page create action too .
|
54,003
|
public function unfold ( $ start_value ) { if ( count ( $ this -> contents ( ) ) > 0 ) { throw new \ LogicException ( "Can't unfold into non-empty directory '" . $ this -> path ( ) . "'." ) ; } return new Unfolder ( $ this , $ start_value ) ; }
|
Get an object that can unfold a directory structure in this directory .
|
54,004
|
public static final function ana ( \ Closure $ unfolder , $ start_value ) { $ unfolded = $ unfolder ( $ start_value ) ; if ( $ unfolded -> isFile ( ) ) { return $ unfolded ; } return new GenericFixedFDirectory ( $ unfolded -> fmap ( function ( $ value ) use ( $ unfolder ) { return self :: ana ( $ unfolder , $ value ) ; } ) ) ; }
|
As we have an unfix and an underlying fmap from FDirectory we could also implement the anamorphism .
|
54,005
|
public function dispatch ( array $ events ) { foreach ( $ events as $ event ) { $ eventName = $ this -> getEventName ( $ event ) ; $ this -> app -> fireEvent ( $ eventName , $ event ) ; $ this -> app -> logEvent ( $ eventName . ' was fired.' ) ; } }
|
Dispatch all events .
|
54,006
|
public function add ( FormField $ field ) { if ( $ this -> owner -> hasTabSet ( ) ) { $ before = ( $ this -> tab == "Main" && $ this -> owner -> dataFieldByName ( "Content" ) ) ? "Content" : null ; $ this -> owner -> addFieldToTab ( "Root.{$this->tab}" , $ field , $ before ) ; } else { $ this -> owner -> push ( $ field ) ; } }
|
Adds a FormField to the FieldList
|
54,007
|
public function group ( ) { $ group = FieldGroup :: create ( ) ; $ group -> FieldList = $ this -> owner ; $ this -> add ( $ group ) ; return $ group ; }
|
Adds a FieldGroup to the FieldList
|
54,008
|
public function allMethodNames ( ) { $ methods = array ( 'add' , 'tab' , 'field' , 'configure' , 'group' , 'hasmanygrid' , 'imageupload' , 'removefield' , 'addfield' ) ; foreach ( SS_ClassLoader :: instance ( ) -> getManifest ( ) -> getDescendantsOf ( "FormField" ) as $ field ) { $ methods [ ] = strtolower ( preg_replace ( '/Field$/' , "" , $ field ) ) ; } return $ methods ; }
|
Defines all possible methods for this class . Used to support wildcard methods
|
54,009
|
public function listAction ( Request $ request ) { return $ this -> render ( 'SynapseAdminBundle:Skeleton:list.html.twig' , array ( 'skeletons' => $ this -> container -> get ( 'synapse.template.loader' ) -> retrieveAll ( array ( 'scope' => TemplateInterface :: GLOBAL_SCOPE , ) ) , ) ) ; }
|
Skeletons listing action .
|
54,010
|
public function initAction ( Request $ request ) { $ form = $ this -> container -> get ( 'form.factory' ) -> createNamed ( 'skeleton' , GlobalCreationType :: class , null , array ( 'action' => $ this -> container -> get ( 'router' ) -> generate ( 'synapse_admin_skeleton_init' ) , 'method' => 'POST' , 'csrf_protection' => false , ) ) ; if ( $ request -> request -> has ( 'skeleton' ) ) { $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { return $ this -> redirect ( $ this -> container -> get ( 'router' ) -> generate ( 'synapse_admin_skeleton_edition' , array ( 'id' => $ form -> getData ( ) -> getId ( ) ) ) ) ; } } return $ this -> render ( 'SynapseAdminBundle:Skeleton:create.html.twig' , array ( 'form' => $ form -> createView ( ) , ) ) ; }
|
Skeleton initialization action .
|
54,011
|
public function beginSession ( $ callback , array $ scope = [ ] ) { $ requestUrl = $ this -> config [ 'request_url' ] ; if ( 0 < count ( $ scope ) ) { $ requestUrl .= ( ( false === strpos ( $ requestUrl , '?' ) ) ? '?' : '&' ) . 'scope=' . rawurlencode ( implode ( ' ' , $ scope ) ) ; } $ response = $ this -> sendCustomOauthPostRequest ( $ requestUrl , [ 'callback' => $ callback , 'token' => null , 'token_secret' => null , ] ) ; parse_str ( $ response -> getBody ( ) , $ responseData ) ; if ( ! isset ( $ responseData [ 'oauth_callback_confirmed' ] ) ) { throw new UnexpectedValueException ( 'Oauth exchange is missing `oauth_callback_confirmed`.' ) ; } elseif ( ! isset ( $ responseData [ 'oauth_token' ] ) ) { throw new UnexpectedValueException ( 'Oauth exchange is missing `oauth_token`.' ) ; } elseif ( ! isset ( $ responseData [ 'oauth_token_secret' ] ) ) { throw new UnexpectedValueException ( 'Oauth exchange is missing `oauth_token_secret`.' ) ; } if ( 'true' !== $ responseData [ 'oauth_callback_confirmed' ] ) { throw new UnexpectedValueException ( 'Oauth exchange must have `oauth_callback_confirmed` as `true`.' ) ; } $ this -> authentication -> getTokenStorage ( ) -> setRequestToken ( $ responseData [ 'oauth_token' ] ) ; $ this -> authentication -> getTokenStorage ( ) -> setRequestTokenSecret ( $ responseData [ 'oauth_token_secret' ] ) ; $ redirect = $ this -> config [ 'authorize_url' ] ; $ redirect .= ( ( false === strpos ( $ redirect , '?' ) ) ? '?' : '&' ) . 'oauth_token=' . rawurlencode ( $ this -> authentication -> getTokenStorage ( ) -> getRequestToken ( ) ) ; return $ redirect ; }
|
Start setting up a new OAuth session .
|
54,012
|
public function confirmSession ( $ token , $ verifier ) { if ( $ this -> authentication -> getTokenStorage ( ) -> getRequestToken ( ) != $ token ) { throw new LogicException ( 'The request tokens do not match.' ) ; } $ response = $ this -> sendCustomOauthPostRequest ( $ this -> config [ 'access_url' ] , [ 'verifier' => $ verifier , 'token' => $ this -> authentication -> getTokenStorage ( ) -> getRequestToken ( ) , 'token_secret' => $ this -> authentication -> getTokenStorage ( ) -> getRequestTokenSecret ( ) , ] ) ; if ( 200 == $ response -> getStatusCode ( ) ) { parse_str ( $ response -> getBody ( ) , $ responseData ) ; if ( ! isset ( $ responseData [ 'oauth_token' ] ) ) { throw new UnexpectedValueException ( 'Oauth exchange is missing `oauth_token`.' ) ; } elseif ( ! isset ( $ responseData [ 'oauth_token_secret' ] ) ) { throw new UnexpectedValueException ( 'Oauth exchange is missing `oauth_token_secret`.' ) ; } $ this -> authentication -> getTokenStorage ( ) -> setAccessToken ( $ responseData [ 'oauth_token' ] ) ; $ this -> authentication -> getTokenStorage ( ) -> setAccessTokenSecret ( $ responseData [ 'oauth_token_secret' ] ) ; $ this -> authentication -> getTokenStorage ( ) -> setRequestToken ( null ) ; $ this -> authentication -> getTokenStorage ( ) -> setRequestTokenSecret ( null ) ; $ this -> authentication -> getTokenStorage ( ) -> save ( ) ; $ this -> authentication -> resetOauth ( ) ; } else { throw new RuntimeException ( 'Bad response' ) ; } }
|
Finish an OAuth session converting the request to access tokens .
|
54,013
|
protected function convertPathsToNames ( $ tags ) { if ( $ tags ) { $ aliases = array ( ) ; foreach ( $ tags as $ tag ) { if ( ! empty ( $ tag -> path ) ) { if ( $ pathParts = explode ( '/' , $ tag -> path ) ) { $ aliases = array_merge ( $ aliases , $ pathParts ) ; } } } if ( $ aliases ) { $ aliases = array_unique ( $ aliases ) ; $ db = $ this -> form -> getDb ( ) ; $ query = $ db -> getQuery ( true ) -> select ( 'alias, title' ) -> from ( '#__tags' ) -> where ( 'alias IN (' . implode ( ',' , array_map ( array ( $ db , 'quote' ) , $ aliases ) ) . ')' ) ; $ db -> setQuery ( $ query ) ; try { $ aliasesMapper = $ db -> loadAssocList ( 'alias' ) ; } catch ( \ RuntimeException $ e ) { return false ; } if ( $ aliasesMapper ) { foreach ( $ tags as $ tag ) { $ namesPath = array ( ) ; if ( ! empty ( $ tag -> path ) ) { if ( $ pathParts = explode ( '/' , $ tag -> path ) ) { foreach ( $ pathParts as $ alias ) { if ( isset ( $ aliasesMapper [ $ alias ] ) ) { $ namesPath [ ] = $ aliasesMapper [ $ alias ] [ 'title' ] ; } else { $ namesPath [ ] = $ alias ; } } $ tag -> text = implode ( '/' , $ namesPath ) ; } } } } } } return $ tags ; }
|
Function pour convertir des chemins de tags en chemin de noms .
|
54,014
|
private function doLoadFromDescriptors ( MetadataInterface $ metadata , array $ descriptors ) : void { foreach ( $ descriptors as $ descriptor ) { $ processor = $ this -> processorFactory -> getProcessor ( $ descriptor ) ; if ( null === $ processor ) { continue ; } $ processor -> process ( $ metadata , $ descriptor ) ; } }
|
Call processors .
|
54,015
|
public final function setX ( float $ x ) : self { $ this -> coordinates [ self :: X ] = $ this -> gf -> getPrecisionModel ( ) -> makePrecise ( $ x ) ; return $ this ; }
|
Sets the x - coordinate value of this Point .
|
54,016
|
public function setY ( float $ y ) : self { $ this -> coordinates [ self :: Y ] = $ this -> gf -> getPrecisionModel ( ) -> makePrecise ( $ y ) ; return $ this ; }
|
Sets the y - coordinate value of this Point .
|
54,017
|
public function setZ ( float $ z ) : self { if ( ! $ this -> is3D ( ) ) { throw GeometryException :: coordinateNotSupported ( 'z' ) ; } $ this -> coordinates [ self :: Z ] = $ this -> gf -> getPrecisionModel ( ) -> makePrecise ( $ z ) ; return $ this ; }
|
Sets the z - coordinate value of this Point .
|
54,018
|
public function setM ( float $ m ) : self { if ( ! $ this -> isMeasured ( ) ) { throw GeometryException :: coordinateNotSupported ( 'm' ) ; } $ this -> coordinates [ self :: M ] = $ this -> gf -> getPrecisionModel ( ) -> makePrecise ( $ m ) ; return $ this ; }
|
Sets the m - coordinate value of this Point .
|
54,019
|
public function isEmpty ( ) : bool { foreach ( $ this -> coordinates as $ value ) { if ( is_nan ( $ value ) ) { return true ; } } return false ; }
|
Indicates whether this Point is empty .
|
54,020
|
protected function event ( $ name , $ type , $ object , $ event ) { if ( is_null ( $ this -> triggers ) ) { return ; } $ event = ucfirst ( $ event ) ; $ deprecatedEvent = strtolower ( $ event ) ; if ( method_exists ( $ this -> triggers , "{$name}{$event}" ) ) { call_user_func ( array ( $ this -> triggers , "{$name}{$event}" ) , $ object ) ; } elseif ( method_exists ( $ this -> triggers , "{$name}_{$deprecatedEvent}" ) ) { call_user_func ( array ( $ this -> triggers , "{$name}_{$deprecatedEvent}" ) , $ object ) ; } if ( $ type ) { $ type = ucfirst ( $ type ) ; if ( method_exists ( $ this -> triggers , "{$name}{$type}{$event}" ) ) { call_user_func ( array ( $ this -> triggers , "{$name}{$type}{$event}" ) , $ object ) ; } elseif ( method_exists ( $ this -> triggers , "{$name}_{$type}_{$deprecatedEvent}" ) ) { call_user_func ( array ( $ this -> triggers , "{$name}_{$type}_{$deprecatedEvent}" ) , $ object ) ; } } }
|
Calls trigger events
|
54,021
|
public function delete ( string $ key ) : bool { $ file = $ this -> cacheFile ( $ key ) ; if ( is_file ( $ file ) ) { return unlink ( $ file ) ; } return false ; }
|
Delete from cache
|
54,022
|
protected function fileWrite ( string $ file , string $ data ) : bool { $ fh = fopen ( $ file , 'c' ) ; flock ( $ fh , LOCK_EX ) ; chmod ( $ file , 0774 ) ; ftruncate ( $ fh , 0 ) ; fwrite ( $ fh , $ data ) ; flock ( $ fh , LOCK_UN ) ; fclose ( $ fh ) ; return true ; }
|
Write on file
|
54,023
|
public function deleteAction ( $ zoneId , $ componentId , Request $ request ) { if ( ! $ zone = $ this -> container -> get ( 'synapse.zone.loader' ) -> retrieve ( $ zoneId ) ) { throw new NotFoundHttpException ( sprintf ( 'No zone found under id "%s"' , $ zoneId ) ) ; } if ( ! $ component = $ this -> container -> get ( 'synapse.component.loader' ) -> retrieve ( $ componentId ) ) { throw new NotFoundHttpException ( sprintf ( 'No component found under id "%s"' , $ componentId ) ) ; } $ this -> container -> get ( 'synapse.zone.domain' ) -> removeComponent ( $ zone , $ component ) ; return new RedirectResponse ( $ request -> server -> get ( 'HTTP_REFERER' ) ) ; }
|
Component deletion action .
|
54,024
|
public function beforeTraverse ( array $ nodes ) { $ keyedNodes = [ ] ; foreach ( $ nodes as $ node ) { $ hashFunc = $ node -> getType ( ) . 'Hash' ; if ( ! method_exists ( $ this , $ hashFunc ) ) { $ keyedNodes [ ] = $ node ; continue ; } $ keyedNodes [ $ this -> $ hashFunc ( $ node ) ] = $ node ; } return $ keyedNodes ; }
|
Turn numbers into unique string .
|
54,025
|
public function getBySession ( SessionEntity $ session ) { foreach ( $ this -> getDbConnection ( ) -> fetchAll ( 'SELECT oc.id, oc.name FROM oauth_client oc INNER JOIN oauth_session os ON(oc.id = os.client_id) WHERE os.id = :id' , [ 'id' => $ session -> getId ( ) ] ) as $ row ) { if ( $ row ) { return ( new ClientEntity ( $ this -> server ) ) -> hydrate ( [ 'id' => $ row [ 'id' ] , 'name' => $ row [ 'name' ] ] ) ; } } return null ; }
|
Get the client associated with a session
|
54,026
|
public function escapeHtmlAttrCallback ( $ matches ) { static $ entityMap = array ( 34 => 'quot' , 38 => 'amp' , 60 => 'lt' , 62 => 'gt' , ) ; $ chr = $ matches [ 0 ] ; $ ord = ord ( $ chr ) ; if ( ( $ ord <= 0x1f && $ chr != "\t" && $ chr != "\n" && $ chr != "\r" ) || ( $ ord >= 0x7f && $ ord <= 0x9f ) ) { return '�' ; } if ( strlen ( $ chr ) == 1 ) { $ hex = strtoupper ( substr ( '00' . bin2hex ( $ chr ) , - 2 ) ) ; } else { $ chr = $ this -> convertEncoding ( $ chr , 'UTF-16BE' , 'UTF-8' ) ; $ hex = strtoupper ( substr ( '0000' . bin2hex ( $ chr ) , - 4 ) ) ; } $ int = hexdec ( $ hex ) ; if ( array_key_exists ( $ int , $ entityMap ) ) { return sprintf ( '&%s;' , $ entityMap [ $ int ] ) ; } return sprintf ( '&#x%s;' , $ hex ) ; }
|
This function is adapted from code coming from Zend Framework .
|
54,027
|
protected function validateSchema ( \ DOMDocument $ dom ) { try { $ valid = $ dom -> schemaValidate ( $ this -> schema ) ; return $ valid ; } catch ( \ Exception $ e ) { } throw new InvalidConfigurationSchema ( 'Schema is not valid' ) ; }
|
validate the xsd schema
|
54,028
|
public function load ( $ default = null ) { if ( file_exists ( $ this -> xmlfile ) ) { if ( ! $ this -> cache -> isNew ( $ this -> xmlfile ) ) { return $ this -> cache -> get ( ) ; } $ data = $ this -> parse ( ) ; $ this -> cache -> write ( $ data ) ; return $ data ; } return $ default ; }
|
load the xml configuration .
|
54,029
|
protected function getSimpleXmlObject ( ) { $ dom = new \ DOMDocument ; $ dom -> load ( $ this -> xmlfile ) ; if ( $ this -> validateSchema ( $ dom ) ) { return simplexml_import_dom ( $ dom , $ this -> simplexmlclass ) ; } }
|
get the SimpleXmlObject
|
54,030
|
public function setSimpleXmlClass ( $ simplexmlclass ) { $ interfaces = class_implements ( $ simplexmlclass ) ; $ interface = sprintf ( '%s\%s' , __NAMESPACE__ , 'SimpleXmlConfigInterface' ) ; if ( ! in_array ( $ interface , $ interfaces ) ) { throw new \ InvalidArgumentException ( sprintf ( 'SimpleXml class must implement %s' , $ interface ) ) ; } $ this -> simplexmlclass = $ simplexmlclass ; }
|
set the SimpleXml class
|
54,031
|
public function getData ( ) { $ data = GuzzleHttp \ json_decode ( $ this -> response -> getBody ( ) , true ) ; if ( ! isset ( $ data [ "result" ] ) ) { throw new EndpointException ( "Invalid result structure: " . $ this -> response -> getBody ( ) ) ; } $ this -> checkStatus ( $ data [ "result" ] ) ; return $ data ; }
|
Gets JSON data as array
|
54,032
|
private function checkStatus ( $ expectedStatus ) { $ status = $ this -> response -> getStatusCode ( ) ; if ( $ status != $ expectedStatus ) { throw new EndpointException ( "Unexpected HTTP status {$status} " . $ this -> response -> getReasonPhrase ( ) ) ; } }
|
Checks HTTP status
|
54,033
|
public static function getByName ( $ name ) { $ name = ( string ) $ name ; $ class = get_called_class ( ) ; if ( isset ( self :: $ instances [ $ class ] [ $ name ] ) ) { return self :: $ instances [ $ class ] [ $ name ] ; } $ const = $ class . '::' . $ name ; if ( ! defined ( $ const ) ) { throw new \ InvalidArgumentException ( $ const . ' not defined' ) ; } return self :: $ instances [ $ class ] [ $ name ] = new $ class ( constant ( $ const ) ) ; }
|
Get an enumerator instance by the constant name
|
54,034
|
public static function getByValue ( $ value ) { $ class = get_called_class ( ) ; $ constants = array_flip ( static :: getConstants ( ) ) ; if ( isset ( $ constants [ $ value ] ) ) { return self :: $ instances [ $ class ] [ $ constants [ $ value ] ] = new $ class ( $ value ) ; } else { throw new \ InvalidArgumentException ( '"' . $ value . '" not defined' ) ; } }
|
Get an enumerator instance by the constant value
|
54,035
|
public static function has ( $ value ) { if ( $ value instanceof static && get_class ( $ value ) === get_called_class ( ) ) { return true ; } $ class = get_called_class ( ) ; $ constants = static :: detectConstants ( $ class ) ; return in_array ( $ value , $ constants , true ) ; }
|
Is the given value part of this enumeration
|
54,036
|
private static function detectConstants ( $ class ) { if ( ! isset ( self :: $ constants [ $ class ] ) ) { $ reflection = new \ ReflectionClass ( $ class ) ; $ constants = $ reflection -> getConstants ( ) ; $ notUnique = [ ] ; foreach ( $ constants as $ value ) { $ names = array_keys ( $ constants , $ value , true ) ; if ( count ( $ names ) > 1 ) { $ notUnique [ var_export ( $ value , true ) ] = $ names ; } } if ( ! empty ( $ notUnique ) ) { throw new \ LogicException ( 'All possible values needs to be unique. The following are not unique: ' . implode ( ', ' , array_map ( function ( $ names ) use ( $ constants ) { return implode ( '/' , $ names ) . '=' . var_export ( $ constants [ $ names [ 0 ] ] , true ) ; } , $ notUnique ) ) ) ; } while ( ( $ reflection = $ reflection -> getParentClass ( ) ) && $ reflection -> name !== __CLASS__ ) { $ constants = $ reflection -> getConstants ( ) + $ constants ; } self :: $ constants [ $ class ] = $ constants ; } return self :: $ constants [ $ class ] ; }
|
Detect all available constants by the given class
|
54,037
|
protected function matchUAAgainstKey ( $ key , $ userAgent = null ) { $ key = Inflector :: lower ( $ key ) ; $ _rules = array_change_key_case ( $ this -> getRules ( ) ) ; if ( Arrays :: exists ( $ key , $ _rules ) ) { if ( empty ( $ _rules [ $ key ] ) ) { return null ; } return $ this -> match ( $ _rules [ $ key ] , $ userAgent ) ; } return false ; }
|
Search for a certain key in the rules array . If the key is found the try to match the corresponding regex agains the User - Agent .
|
54,038
|
public function isMobile ( $ userAgent = null , $ httpHeaders = null ) { if ( $ httpHeaders ) { $ this -> setHttpHeaders ( $ httpHeaders ) ; } if ( $ userAgent ) { $ this -> setUserAgent ( $ userAgent ) ; } $ this -> setDetectionType ( self :: DETECTION_TYPE_MOBILE ) ; if ( $ this -> checkHttpHeadersForMobile ( ) ) { return true ; } else { return $ this -> matchDetectionRulesAgainstUA ( ) ; } }
|
Check if the device is mobile . Returns true if any type of mobile device detected including special ones
|
54,039
|
public function convert ( AccessInterface $ object , $ field , $ value , $ conversion ) { $ type = $ this -> getFieldType ( $ object , $ field ) ; if ( isset ( $ this -> filters [ $ type ] ) ) { if ( $ conversion == self :: SETTER ) { $ value = $ this -> filters [ $ type ] -> convertToSetterValue ( $ this , $ object , $ field , $ value ) ; } else if ( $ conversion == self :: GETTER ) { $ value = $ this -> filters [ $ type ] -> convertToGetterValue ( $ this , $ object , $ field , $ value ) ; } } if ( $ type == 'integer' && $ value == '' ) { return NULL ; } return $ value ; }
|
Convert a value
|
54,040
|
public function fill ( AccessInterface $ object , $ data = array ( ) , $ files = array ( ) ) { $ data = array_replace_recursive ( $ files , $ data ) ; $ allowed = $ object -> loadFillableFields ( $ this ) ; foreach ( $ data as $ name => $ value ) { if ( in_array ( $ name , $ allowed ) ) { $ this -> set ( $ object , $ name , $ value ) ; } } return $ object ; }
|
Set all fields of an object with the supplied data
|
54,041
|
public function getFieldType ( $ object , $ field ) { $ metadata = $ this -> manager -> getClassMetadata ( get_class ( $ object ) ) ; if ( $ metadata -> hasField ( $ field ) ) { return $ metadata -> getTypeOfField ( $ field ) ; } else if ( $ metadata -> hasAssociation ( $ field ) && $ metadata -> isSingleValuedAssociation ( $ field ) ) { return self :: ASSOCIATION_TO_ONE ; } else if ( $ metadata -> hasAssociation ( $ field ) && $ metadata -> isCollectionValuedAssociation ( $ field ) ) { return self :: ASSOCIATION_TO_MANY ; } return null ; }
|
Gets the type of a field . Treats associations as types .
|
54,042
|
static function set ( ) { $ info = debug_backtrace ( ) ; self :: $ data [ ] = [ 'time' => time ( ) , 'microtime' => microtime ( true ) , 'text' => ( count ( $ info [ 0 ] [ 'args' ] ) ? $ info [ 0 ] [ 'args' ] : '' ) , 'file' => $ info [ 0 ] [ 'file' ] , 'line' => $ info [ 0 ] [ 'line' ] , ] ; }
|
empty for Unix Timestamp
|
54,043
|
public function set ( $ value , $ key = null ) { if ( is_null ( $ key ) ) { $ this -> registry [ ] = $ value ; } else { $ this -> registry [ $ key ] = $ value ; } return $ this ; }
|
Sets the value in the registry by key . Returns the current object .
|
54,044
|
public function delete ( $ key ) { if ( $ this -> has ( $ key ) ) { unset ( $ this -> registry [ $ key ] ) ; return true ; } return false ; }
|
Delete an record from the registry by key . Returns the delete status .
|
54,045
|
protected function runScp ( $ file , $ destination_path , $ server = null , $ verbose = false ) { $ recursive_option = '' ; if ( is_dir ( $ file ) ) { $ recursive_option = ' -r' ; } $ server = $ server ? $ server : $ this -> hostNameForConfigFile ( ) ; $ ssh_config_file = $ _SERVER [ 'HOME' ] . '/.ssh/config' ; $ full_command = "scp -F ${ssh_config_file}$recursive_option $file $server:$destination_path" ; if ( $ verbose ) { $ this -> info ( $ full_command ) ; } passthru ( $ full_command ) ; }
|
Runs scp .
|
54,046
|
protected function runSSH ( $ command , $ server = null ) { $ server = $ server ? $ server : $ this -> hostNameForConfigFile ( ) ; $ ssh_config_file = $ _SERVER [ 'HOME' ] . '/.ssh/config' ; $ full_command = "ssh -F $ssh_config_file -t $server '$command'" ; $ this -> info ( $ full_command ) ; passthru ( $ full_command ) ; }
|
Runs ssh command on server .
|
54,047
|
protected function execSSH ( $ command , $ server = null ) { $ server = $ server ? $ server : $ this -> hostNameForConfigFile ( ) ; $ ssh_config_file = $ _SERVER [ 'HOME' ] . '/.ssh/config' ; $ full_command = "ssh -F $ssh_config_file -t $server '$command'" ; $ this -> info ( $ full_command ) ; return shell_exec ( $ full_command ) ; }
|
Exec ssh command on server .
|
54,048
|
public function shortClassName ( ) { if ( ! isset ( $ this -> _data [ 'shortClassName' ] ) ) { $ this -> _data [ 'shortClassName' ] = \ Yii :: $ app -> czaHelper -> naming -> shortClassName ( $ this ) ; } return $ this -> _data [ 'shortClassName' ] ; }
|
Returns the form name that this widget class should use .
|
54,049
|
public function add ( $ step , $ callback ) { ( new \ Phramework \ Validate \ EnumValidator ( [ self :: STEP_BEFORE_AUTHENTICATION_CHECK , self :: STEP_AFTER_AUTHENTICATION_CHECK , self :: STEP_AFTER_CALL_URISTRATEGY , self :: STEP_BEFORE_CALL_URISTRATEGY , self :: STEP_BEFORE_CLOSE , self :: STEP_FINALLY , self :: STEP_ERROR ] ) ) -> parse ( $ step ) ; if ( ! is_callable ( $ callback ) ) { throw new \ Exception ( Phramework :: getTranslated ( 'Callback is not callable' ) ) ; } if ( ! isset ( $ this -> stepCallback [ $ step ] ) ) { $ this -> stepCallback [ $ step ] = [ ] ; } $ this -> stepCallback [ $ step ] [ ] = $ callback ; }
|
Add a step callback
|
54,050
|
public function configureApplication ( ) { $ config = file_get_contents ( $ this -> paths [ 'app' ] . '/config/config.yml' ) ; $ config = $ this -> parser -> parse ( $ config ) ; $ this -> project_name = $ config [ 'application' ] [ 'project_name' ] ; $ this -> routeCollection = $ this -> bindRouteCollection ( $ this -> project_name ) ; $ this -> addDbParams ( $ config [ 'database' ] [ 'default' ] , $ config [ 'database' ] [ 'types' ] ) ; $ this -> createBaseEm ( $ config [ 'application' ] [ 'environment' ] ) ; }
|
Configure the Umbrella Application
|
54,051
|
public function bindPaths ( array $ paths ) { foreach ( $ paths as $ key => $ val ) { $ paths [ $ key ] = realpath ( $ val ) ; } return $ paths ; }
|
Connect app paths to the Application
|
54,052
|
public function createBaseEm ( $ env ) { if ( $ env == 'dev' ) { $ devEnv = true ; } else { $ devEnv = false ; } AnnotationRegistry :: registerFile ( $ this -> paths [ 'root' ] . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php' ) ; AnnotationRegistry :: registerAutoloadNamespace ( 'Symfony\Component\Validator\Constraints' , $ this -> paths [ 'root' ] . '/vendor/symfony/validator' ) ; $ reader = new FileCacheReader ( new AnnotationReader ( ) , $ this -> paths [ 'app' ] . '/cache/doctrine/annotations' , $ debug = true ) ; $ driverImpl = new \ Doctrine \ ORM \ Mapping \ Driver \ AnnotationDriver ( $ reader , array ( $ this -> paths [ 'src' ] . "/Model" ) ) ; $ config = Setup :: createAnnotationMetadataConfiguration ( array ( $ this -> paths [ 'src' ] . "/Model" ) , $ devEnv ) ; $ config -> setMetadataDriverImpl ( $ driverImpl ) ; $ conn = $ this -> getParams ( ) ; $ this -> em = EntityManager :: create ( $ conn , $ config ) ; }
|
Create the base Doctrine EntityManager
|
54,053
|
public function bindRouteCollection ( $ name = "" ) { $ routeCollection = new RouteCollection ( $ this -> paths [ 'app' ] . '/routes.yml' , $ this -> paths , $ name , $ this -> parser ) ; return $ routeCollection ; }
|
Bind RouteCollection to app
|
54,054
|
public function parseUri ( ) { $ uri = ( isset ( $ _SERVER [ 'REQUEST_URI' ] ) ? $ _SERVER [ 'REQUEST_URI' ] : null ) ; if ( isset ( $ uri ) ) { $ uri = '/' . ltrim ( trim ( $ uri ) , '/' ) ; $ uri = filter_var ( $ uri , FILTER_SANITIZE_URL ) ; return $ uri ; } else { throw new Exception ( "Error parsing URI please check your URI." , 1 ) ; } }
|
Parse the URL
|
54,055
|
public function registerBackend ( AbstractBackend $ backend ) { if ( in_array ( $ backend , $ this -> backends , TRUE ) ) { throw new InvalidArgumentException ( 'Duplicate backend: ' . get_class ( $ backend ) ) ; } else { $ this -> backends [ ] = $ backend ; if ( $ this -> debug_logger ) { $ backend -> setDebugLogger ( $ this -> debug_logger ) ; } } return $ this ; }
|
Register a new backend
|
54,056
|
public function getMachine ( string $ type ) { foreach ( $ this -> backends as $ b => $ backend ) { $ m = $ backend -> getMachine ( $ this , $ type ) ; if ( $ m !== null ) { return $ m ; } } return null ; }
|
Obtain machine from backends .
|
54,057
|
public function ref ( ... $ argv ) : Reference { $ type = $ argv [ 0 ] ; if ( $ type instanceof Reference ) { if ( count ( $ argv ) != 1 ) { throw new InvalidArgumentException ( 'The first argument is a Reference and more than one argument given.' ) ; } return clone $ type ; } if ( is_array ( $ type ) ) { if ( count ( $ argv ) != 1 ) { throw new InvalidArgumentException ( 'The first argument is an array and more than one argument given.' ) ; } } foreach ( $ this -> backends as $ b => $ backend ) { $ id = array_slice ( $ argv , 1 ) ; if ( $ backend -> inferMachineType ( $ argv , $ type , $ id ) ) { $ m = $ backend -> getMachine ( $ this , $ type ) ; if ( $ m === null ) { throw new RuntimeException ( 'Cannot create machine: ' . $ type ) ; } $ ref = $ m -> ref ( $ id ) ; if ( $ this -> debug_logger ) { $ this -> debug_logger -> afterReferenceCreated ( $ backend , $ ref ) ; } if ( $ this -> after_reference_created ) { $ this -> after_reference_created -> emit ( $ ref ) ; } return $ ref ; } } throw new InvalidReferenceException ( 'Cannot infer machine type: ' . $ type ) ; }
|
Get reference to state machine instance of given type and id .
|
54,058
|
public function nullRef ( string $ type ) : Reference { foreach ( $ this -> backends as $ b => $ backend ) { $ m = $ backend -> getMachine ( $ this , $ type ) ; if ( $ m !== null ) { $ ref = $ m -> nullRef ( ) ; if ( $ this -> debug_logger ) { $ this -> debug_logger -> afterReferenceCreated ( $ backend , $ ref ) ; } if ( $ this -> after_reference_created ) { $ this -> after_reference_created -> emit ( $ ref ) ; } return $ ref ; } } throw new RuntimeException ( 'Cannot create machine: ' . $ type ) ; }
|
Get reference to non - existent state machine instance of given type . You may want to invoke create or similar transition using this reference .
|
54,059
|
public static function glob ( string $ pattern , int $ flag = 0 , array $ data = [ ] ) { $ paths = glob ( $ pattern , $ flag ) ; extract ( $ data ) ; foreach ( $ paths as $ path ) { require ( $ path ) ; } }
|
Use glob to include multiple files
|
54,060
|
private function generateHeader ( ) { $ this -> logger -> debug ( "Generating raw frame header" ) ; $ this -> logger -> debug ( "Generated frame 1st byte: " . decbin ( $ this -> firstFrameByte ) . ", 2nd: " . decbin ( $ this -> secondFrameByte ) ) ; $ header = chr ( $ this -> firstFrameByte ) . chr ( $ this -> secondFrameByte ) ; if ( $ this -> payloadLengthDiscriminator === 126 ) { $ this -> logger -> debug ( "Encoding length as 16bit" ) ; $ header .= pack ( "n" , $ this -> payloadLength ) ; } elseif ( $ this -> payloadLengthDiscriminator === 127 ) { $ this -> logger -> debug ( "Encoding length as 64bit" ) ; $ highMap = 0xffffffff00000000 ; $ lowMap = 0x00000000ffffffff ; $ higher = ( $ this -> payloadLength & $ highMap ) >> 32 ; $ lower = $ this -> payloadLength & $ lowMap ; $ header .= pack ( 'NN' , $ higher , $ lower ) ; } else { $ this -> logger -> debug ( "Length encoded as 7bit" ) ; } if ( $ this -> secondFrameByte & 128 ) { $ this -> logger -> debug ( "Attaching masking key" ) ; $ header .= ord ( $ this -> maskingKey ) ; } return $ header ; }
|
Generates raw frame headers .
|
54,061
|
public function contents ( ) { $ contents = $ this -> filesystem ( ) -> listContents ( $ this -> path ( ) ) ; $ returns = array ( ) ; foreach ( $ contents as $ content ) { $ returns [ ] = $ this -> flightcontrol -> get ( $ content [ "path" ] ) ; } return $ returns ; }
|
Get the objects inside the directory .
|
54,062
|
public function insertByAna ( \ Closure $ unfolder , $ start_value ) { $ insert = FixedFDirectory :: ana ( $ unfolder , $ start_value ) ; if ( $ insert -> isFile ( ) ) { throw new \ LogicException ( "Expected generated root node to be a directory, not a file." ) ; } $ inserter = array ( ) ; $ inserter [ 0 ] = function ( $ path , FixedFDirectory $ directory ) use ( & $ inserter ) { foreach ( $ directory -> contents ( ) as $ content ) { $ new_path = $ path . "/" . $ content -> name ( ) ; if ( $ content -> isFile ( ) ) { $ this -> filesystem ( ) -> write ( $ new_path , $ content -> content ( ) ) ; } else { $ this -> filesystem ( ) -> createDir ( $ new_path ) ; $ inserter [ 0 ] ( $ new_path , $ content ) ; } } } ; $ inserter [ 0 ] ( $ this -> path ( ) , $ insert ) ; }
|
Create a directory structure with an anamorphism an insert it in place of this directory .
|
54,063
|
public function getContents ( $ type , $ index = null , $ order = true ) { $ contents = [ ] ; $ files = $ this -> listFiles ( $ type ) ; foreach ( $ files as $ file ) { $ content = $ this -> load ( $ file ) ; $ contents [ $ this -> getIndex ( $ file , $ content , $ index ) ] = $ content ; } if ( $ order !== null ) { $ order ? ksort ( $ contents ) : krsort ( $ contents ) ; } return $ contents ; }
|
Get all contents for the given type
|
54,064
|
public function listContents ( $ type ) { $ names = [ ] ; $ files = $ this -> listFiles ( $ type ) ; foreach ( $ files as $ file ) { $ names [ ] = static :: getName ( $ file ) ; } return $ names ; }
|
List of content names for the given type
|
54,065
|
public function getContent ( $ type , $ name ) { $ finder = $ this -> listFiles ( $ type ) -> name ( $ name . '.*' ) ; if ( ! $ finder -> count ( ) ) { throw new Exception ( sprintf ( 'No content directory find for type "%s" and name "%s" (in "%s").' , $ type , $ name , $ this -> directory ) ) ; } foreach ( $ finder as $ file ) { return $ this -> load ( $ file ) ; } return null ; }
|
Get the content for the given type and name
|
54,066
|
public static function getName ( SplFileInfo $ file ) { $ name = $ file -> getRelativePathname ( ) ; return substr ( $ name , 0 , strrpos ( $ name , '.' ) ) ; }
|
Get the name of a file
|
54,067
|
public static function getFormat ( SplFileInfo $ file ) { $ name = $ file -> getRelativePathname ( ) ; $ ext = substr ( $ name , strrpos ( $ name , '.' ) + 1 ) ; switch ( $ ext ) { case 'md' : return 'markdown' ; case 'yml' : return 'yaml' ; default : return $ ext ; } }
|
Get the format of a file from its extension
|
54,068
|
protected function listFiles ( $ type ) { if ( ! isset ( $ this -> cache [ 'files' ] [ $ type ] ) ) { $ path = sprintf ( '%s/%s' , $ this -> directory , $ type ) ; if ( ! $ this -> files -> exists ( $ path ) ) { throw new Exception ( sprintf ( 'No content directory found for type "%s" (in "%s").' , $ type , $ this -> directory ) ) ; } $ finder = new Finder ( ) ; $ this -> cache [ 'files' ] [ $ type ] = $ finder -> files ( ) -> in ( $ path ) ; } return clone $ this -> cache [ 'files' ] [ $ type ] ; }
|
List files for the given type
|
54,069
|
protected function getIndex ( SplFileInfo $ file , $ content , $ key = null ) { if ( $ key === null || ! isset ( $ content [ $ key ] ) ) { return static :: getName ( $ file ) ; } $ index = $ content [ $ key ] ; if ( $ index instanceof DateTime ) { return $ index -> format ( 'U' ) ; } return ( string ) $ index ; }
|
Get index of the given content for content lists
|
54,070
|
protected function load ( SplFileInfo $ file ) { $ path = $ file -> getPathName ( ) ; if ( ! isset ( $ this -> cache [ 'contents' ] [ $ path ] ) ) { $ data = $ this -> decoder -> decode ( $ file -> getContents ( ) , static :: getFormat ( $ file ) ) ; $ context = [ 'file' => $ file , 'data' => $ data ] ; if ( is_array ( $ data ) ) { foreach ( $ this -> handlers as $ property => $ handler ) { if ( $ handler -> isSupported ( $ data ) ) { $ value = isset ( $ data [ $ property ] ) ? $ data [ $ property ] : null ; $ data [ $ property ] = $ handler -> handle ( $ value , $ context ) ; } } } $ this -> cache [ 'contents' ] [ $ path ] = $ data ; } return $ this -> cache [ 'contents' ] [ $ path ] ; }
|
Get the file content
|
54,071
|
public function xhrFileUploadAction ( Request $ request ) { if ( ! $ request -> files -> has ( 'file' ) ) { return new JsonResponse ( array ( 'error' => 400 , 'error_message' => 'File to upload have to be under "file" key.' , ) , 400 ) ; } try { return new JsonResponse ( array ( 'file' => $ this -> container -> get ( 'synapse.media.domain' ) -> upload ( $ request -> files -> get ( 'file' ) ) -> normalize ( ) , ) , 201 ) ; } catch ( UnsupportedFileException $ e ) { return new JsonResponse ( array ( 'error' => 400 , 'error_message' => 'File isnt supported by Synapse.' , 'error_full_message' => $ e -> getMessage ( ) , ) , 400 ) ; } }
|
Media upload action throught XmlHttpRequest .
|
54,072
|
protected function assignGroupsToAssignment ( ) { $ assignment = fp_env ( 'ACACHA_FORGE_ASSIGNMENT' ) ; foreach ( $ this -> groups as $ group ) { $ uri = str_replace ( '{assignment}' , $ assignment , config ( 'forge-publish.assign_group_to_assignment_uri' ) ) ; $ uri = str_replace ( '{group}' , $ group , $ uri ) ; $ url = config ( 'forge-publish.url' ) . $ uri ; try { $ response = $ this -> http -> post ( $ url , [ 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest' , 'Authorization' => 'Bearer ' . fp_env ( 'ACACHA_FORGE_ACCESS_TOKEN' ) ] ] ) ; } catch ( \ Exception $ e ) { if ( $ e -> getResponse ( ) -> getStatusCode ( ) == 422 ) { $ this -> error ( 'The group is already assigned' ) ; return ; } $ this -> error ( 'And error occurs connecting to the api url: ' . $ url ) ; $ this -> error ( 'Status code: ' . $ e -> getResponse ( ) -> getStatusCode ( ) . ' | Reason : ' . $ e -> getResponse ( ) -> getReasonPhrase ( ) ) ; return [ ] ; } } }
|
Assign groups to assignment
|
54,073
|
protected function askForGroups ( ) { $ default = 0 ; $ groups = $ this -> groups ( ) ; $ group_names = collect ( $ groups ) -> pluck ( 'name' ) -> toArray ( ) ; $ selected_group_names = $ this -> choice ( 'Groups?' , $ group_names , $ default , null , true ) ; $ groups = collect ( $ groups ) -> filter ( function ( $ group ) use ( $ selected_group_names ) { return in_array ( $ group -> name , $ selected_group_names ) ; } ) ; return $ groups -> pluck ( 'id' ) ; }
|
Ask for groups .
|
54,074
|
public function getFunction ( ) { return function ( $ pathName ) { $ data = $ this -> context -> getData ( ) ; if ( array_key_exists ( 'sys_pathNames' , $ data ) ) { if ( array_key_exists ( $ pathName , $ data [ 'sys_pathNames' ] ) ) { return $ this -> context -> renderString ( $ data [ 'sys_pathNames' ] [ $ pathName ] ) ; } return '' ; } return '' ; } ; }
|
Gets the function that is passed to the rendering environment .
|
54,075
|
public function revokeAccessToken ( ) { $ grantType = $ this -> getRequest ( ) -> request -> get ( 'grant_type' ) ? $ this -> getRequest ( ) -> request -> get ( 'grant_type' ) : 'password' ; $ token = $ this -> getRequest ( ) -> request -> get ( 'token' ) ; if ( is_null ( $ token ) ) { throw new Exception \ InvalidRequestException ( 'token' ) ; } $ token_type_hint = $ this -> getRequest ( ) -> request -> get ( 'token_type_hint' ) ; if ( ! is_null ( $ token_type_hint ) && $ token_type_hint == 'refresh_token' ) { $ authorization = ! empty ( Request :: header ( ) [ 'authorization' ] [ 0 ] ) ? str_replace ( 'Bearer ' , '' , Request :: header ( ) [ 'authorization' ] [ 0 ] ) : null ; if ( is_null ( $ authorization ) ) { throw new Exception \ InvalidRequestException ( 'access_token' ) ; } } if ( ! in_array ( $ grantType , array_keys ( $ this -> grantTypes ) ) ) { throw new Exception \ UnsupportedGrantTypeException ( $ grantType ) ; } if ( $ grantType != 'password' && $ grantType != 'refresh_token' ) { throw new Exception \ UnsupportedRevokeTypeException ; } return $ this -> getGrantType ( $ grantType ) -> revokeFlow ( ) ; }
|
Revoke a access token
|
54,076
|
public function processResponse ( ) { $ rawResponse = $ this -> rawResponse ; if ( empty ( $ rawResponse ) ) { return ; } $ responseData = unpack ( "Ccommand/Cstatus/Nidentifier" , $ rawResponse ) ; $ this -> validateResponse ( $ responseData ) ; $ statusCode = $ responseData [ 'status' ] ; $ errorDescription = self :: $ responseDescription [ $ statusCode ] ; if ( $ statusCode == self :: ERROR_INVALID_TOKEN_SIZE || $ statusCode == self :: ERROR_INVALID_TOKEN ) { $ recipients = $ this -> recipients ; $ recipients -> current ( ) -> setIdentifierStatus ( RecipientDevice :: DEVICE_NOT_REGISTERED ) ; throw new InvalidRecipientException ( $ errorDescription , $ recipients ) ; } throw new DispatchMessageException ( $ errorDescription , $ statusCode ) ; }
|
Unpacks and process response data
|
54,077
|
public function validateResponse ( $ responseData ) { if ( $ responseData === false ) { throw new RuntimeException ( 'Unable to unpack response data' ) ; } if ( self :: ERROR_RESPONSE_COMMAND != $ responseData [ 'command' ] ) { throw new RuntimeException ( "Invalid APNS response packet command" ) ; } return $ this ; }
|
Validates response data
|
54,078
|
public function setCallArgument ( $ arg ) { $ this -> call_argument = $ arg ; $ this -> args = [ $ this -> call_function , $ this -> call_argument ] ; }
|
Set argument for call function
|
54,079
|
public static function generate_nested_array ( $ array_map , $ map_keys , $ bind_value ) { $ reference = & $ array_map ; while ( count ( $ map_keys ) > 0 ) { $ new_map = array_shift ( $ map_keys ) ; if ( ! is_array ( $ reference ) ) { $ reference = array ( ) ; } $ reference = & $ reference [ $ new_map ] ; } $ reference = $ bind_value ; return $ array_map ; }
|
get a nested key based array
|
54,080
|
public static function validate_ip ( $ ip = '' ) { if ( empty ( $ ip ) ) return false ; return ( ip2long ( $ ip ) !== false ) ? true : false ; }
|
returns if an IP is valid
|
54,081
|
public static function clean_up_path ( $ path ) { if ( empty ( $ path ) ) return '' ; if ( strpos ( $ path , '\\' ) !== false ) { return str_replace ( "\\\\" , "\\" , $ path ) ; } else { return str_replace ( "//" , "/" , $ path ) ; } }
|
removes multiple slashes and backslashes
|
54,082
|
public static function trim_array ( $ array ) { if ( empty ( $ array ) || ! is_array ( $ array ) ) return $ array ; foreach ( $ array as $ key => $ value ) { $ array [ $ key ] = trim ( $ value ) ; } unset ( $ key , $ value ) ; return $ array ; }
|
trims the content of an array
|
54,083
|
public static function php_number_format ( $ number ) { preg_match ( '/[.,](\d+)$/' , $ number , $ matches ) ; $ num_decimals = strlen ( $ matches [ 1 ] ) ; return preg_replace ( '/[.,]/' , '' , $ number ) / pow ( 10 , $ num_decimals ) ; }
|
Take a number an re - format the number to the target decimal separator
|
54,084
|
public static function updateQS ( $ key , $ value , $ reverseorder = false , $ qs = '' ) { if ( empty ( $ qs ) ) { $ qs = $ _SERVER [ 'QUERY_STRING' ] ; } if ( $ reverseorder ) { if ( preg_match ( "/ascdesc=ASC/" , $ qs ) ) { $ qs = self :: updateQS ( 'ascdesc' , 'DESC' , 0 , $ qs ) ; } else { $ qs = self :: updateQS ( 'ascdesc' , 'ASC' , 0 , $ qs ) ; } } if ( ! $ qs ) { if ( $ value ) { return "$key=$value" ; } else { return "" ; } } if ( preg_match ( "/$key=/" , $ qs ) ) { if ( $ value ) { return preg_replace ( "/$key=[^&]+/" , "$key=$value" , $ qs ) ; } else { return preg_replace ( "/$key=[^&]?/" , "" , $ qs ) ; } } else { if ( $ value ) { return $ qs . "&$key=$value" ; } else { return $ qs ; } } }
|
update a parameter in a query string with a new value
|
54,085
|
public static function array_diff_multi ( $ array1 , $ array2 ) { $ res = array ( ) ; foreach ( $ array1 as $ entry ) { if ( ! in_array ( $ entry , $ array2 ) ) { $ res [ ] = $ entry ; } } return $ res ; }
|
Array_Diff Implementation for multi - dimensional arrays Can only handle 2 arrays
|
54,086
|
public static function usortByArrayKey ( & $ array , $ key , $ asc = SORT_ASC ) { $ sort_flags = array ( SORT_ASC , SORT_DESC ) ; if ( ! in_array ( $ asc , $ sort_flags ) ) throw new InvalidArgumentException ( 'sort flag only accepts SORT_ASC or SORT_DESC' ) ; $ cmp = function ( array $ a , array $ b ) use ( $ key , $ asc , $ sort_flags ) { if ( ! is_array ( $ key ) ) { if ( ! isset ( $ a [ $ key ] ) || ! isset ( $ b [ $ key ] ) ) { throw new \ Exception ( 'attempting to sort on non-existent keys' ) ; } if ( $ a [ $ key ] == $ b [ $ key ] ) return 0 ; return ( $ asc == SORT_ASC xor $ a [ $ key ] < $ b [ $ key ] ) ? 1 : - 1 ; } else { foreach ( $ key as $ sub_key => $ sub_asc ) { if ( ! in_array ( $ sub_asc , $ sort_flags ) ) { $ sub_key = $ sub_asc ; $ sub_asc = $ asc ; } if ( ! isset ( $ a [ $ sub_key ] ) || ! isset ( $ b [ $ sub_key ] ) ) { throw new \ Exception ( 'attempting to sort on non-existent keys' ) ; } if ( $ a [ $ sub_key ] == $ b [ $ sub_key ] ) continue ; return ( $ sub_asc == SORT_ASC xor $ a [ $ sub_key ] < $ b [ $ sub_key ] ) ? 1 : - 1 ; } return 0 ; } } ; usort ( $ array , $ cmp ) ; }
|
Sort an array by a key
|
54,087
|
public static function make_bitly_url ( $ url , $ login = '' , $ appkey = 'R_f0b76fa0948d2cb9f223fb5387ad09ba' , $ format = 'xml' ) { $ bitly = 'http://api.bitly.com/v3/shorten?longUrl=' . urlencode ( $ url ) . '&login=' . urlencode ( $ login ) . '&apiKey=' . $ appkey . '&format=' . $ format ; $ response = file_get_contents ( $ bitly ) ; if ( strtolower ( $ format ) == 'json' ) { $ json = @ json_decode ( $ response , true ) ; return $ json [ 'results' ] [ $ url ] [ 'shortUrl' ] ; } else { $ xml = simplexml_load_string ( $ response ) ; return Config :: get ( 'bitly_url' ) . $ xml -> data -> hash ; } }
|
generates a bitly url
|
54,088
|
public static function assignByKey ( $ array , $ key , $ group = false ) { if ( empty ( $ array ) ) return $ array ; $ res = array ( ) ; foreach ( $ array as $ subthing ) { $ idx = null ; if ( is_object ( $ subthing ) && property_exists ( $ subthing , $ key ) ) { $ idx = $ subthing -> $ key ; } elseif ( is_array ( $ subthing ) && isset ( $ subthing [ $ key ] ) ) { $ idx = $ subthing [ $ key ] ; } if ( $ idx !== null ) { if ( ! $ group ) { $ res [ $ idx ] = $ subthing ; } else { if ( ! isset ( $ res [ $ idx ] ) ) $ res [ $ idx ] = array ( ) ; $ res [ $ idx ] [ ] = $ subthing ; } } } return $ res ; }
|
Turn an array into an associative array assigned by the given key
|
54,089
|
protected function initStream ( $ stream ) { expect_type ( $ stream , [ 'stream resource' , 'string' ] , \ TypeError :: class , "Expected stream resource or uri (string), %s given" ) ; if ( is_string ( $ stream ) ) { $ stream = $ this -> openStream ( $ stream ) ; } $ meta = stream_get_meta_data ( $ stream ) ; if ( $ meta [ 'mode' ] === 'r' ) { throw new \ InvalidArgumentException ( "Stream \"{$meta['uri']}\" is not writable" ) ; } return $ stream ; }
|
Initialize a stream
|
54,090
|
protected function assertAttached ( ) : void { if ( ! isset ( $ this -> stream ) ) { throw new \ BadMethodCallException ( "Stream is not attached" ) ; } if ( ! is_resource ( $ this -> stream ) ) { throw new \ RuntimeException ( "Stream has closed unexpectedly" ) ; } }
|
Assert that a stream is attached .
|
54,091
|
public function detach ( ) { $ this -> assertAttached ( ) ; $ stream = $ this -> stream ; $ this -> stream = null ; return $ stream ; }
|
Detach the stream resource . The object is no longer usable .
|
54,092
|
public function getDependencies ( ) : array { $ dependencies = [ ] ; foreach ( $ this -> config [ 'dependencies' ] as $ dependency ) { $ dependencies [ ] = $ this -> wire ( $ dependency ) ; } return $ dependencies ; }
|
Class names of all view dependencies .
|
54,093
|
public function getEngines ( ) : array { $ engines = [ ] ; foreach ( $ this -> config [ 'engines' ] as $ engine ) { $ engines [ ] = $ this -> wire ( $ engine ) ; } return $ engines ; }
|
Get all the engines associated with view component .
|
54,094
|
public function resolve ( ContentInterface $ content ) { $ contentType = $ this -> contentTypeLoader -> retrieveAll ( ) -> filter ( function ( ContentTypeInterface $ contentType ) use ( $ content ) { return is_a ( $ content , $ contentType -> getContentClass ( ) ) ; } ) -> first ( ) ; if ( ! $ contentType ) { throw new InvalidContentException ( sprintf ( 'No content type registered for "%s" content, check you configuration.' , is_string ( $ content ) ? $ content : get_class ( $ content ) ) ) ; } return $ this -> wrap ( $ contentType , $ content ) ; }
|
Resolve given Content into Synapse internal content class .
|
54,095
|
public function postCreate ( PostRequest $ request ) { $ command = new CreatePostCommand ( $ request -> all ( ) ) ; try { $ this -> bus -> execute ( $ command ) ; } catch ( ValidationException $ e ) { return Redirect :: to ( \ OogleeBConfig :: get ( 'config.post_routes.base_uri_admin' ) . '/post/create' ) -> withErrors ( $ e -> getErrors ( ) ) ; } catch ( \ DomainException $ e ) { return Redirect :: to ( \ OogleeBConfig :: get ( 'config.post_routes.base_uri_admin' ) . '/post/create' ) -> withErrors ( $ e -> getErrors ( ) ) ; } return Redirect :: to ( \ OogleeBConfig :: get ( 'config.post_routes.base_uri_admin' ) . '/posts' ) -> with ( [ 'message' => 'success!' ] ) ; }
|
Create new Post
|
54,096
|
public function createCopy ( ) : AbstractResize { $ this -> createCanvas ( ) ; $ this -> intermediate [ 'copy' ] = imagecreatefrompng ( $ this -> source [ 'path' ] . $ this -> source [ 'file' ] ) ; if ( $ this -> intermediate [ 'copy' ] === false ) { throw new \ Exception ( 'Call to imagecreatefrompng failed' ) ; } $ this -> resampleCopy ( ) ; return $ this ; }
|
Create the image in the required format
|
54,097
|
protected function saveFile ( ) : AbstractResize { $ result = imagepng ( $ this -> canvas [ 'canvas' ] , $ this -> path . $ this -> file , $ this -> canvas [ 'quality' ] ) ; if ( $ result === false ) { throw new \ Exception ( 'Unable to save new image' ) ; } return $ this ; }
|
Attempt to save the new image file
|
54,098
|
public static function getPackageInfo ( $ format = 'v/p (\vn)' ) { try { $ v = self :: getPackageVendor ( ) ; } catch ( LogicException $ vendorException ) { } try { $ p = self :: getPackageName ( ) ; } catch ( LogicException $ packageException ) { if ( isset ( $ vendorException ) ) { $ packageException = new LogicException ( $ packageException -> getMessage ( ) , $ packageException -> getCode ( ) , $ vendorException ) ; } } try { $ n = self :: getPackageVersion ( ) ; } catch ( LogicException $ versionException ) { if ( isset ( $ packageException ) ) { throw new LogicException ( $ versionException -> getMessage ( ) , $ versionException -> getCode ( ) , $ packageException ) ; } if ( isset ( $ vendorException ) ) { throw new LogicException ( $ versionException -> getMessage ( ) , $ versionException -> getCode ( ) , $ vendorException ) ; } throw $ versionException ; } if ( isset ( $ packageException ) ) { throw $ packageException ; } if ( isset ( $ vendorException ) ) { throw $ vendorException ; } $ toLowerCase = function ( $ value , $ snake = false ) { $ whitespace = [ "\xC2\xA0" , "\xE2\x80\x80" , "\xE2\x80\x81" , "\xE2\x80\x82" , "\xE2\x80\x83" , "\xE2\x80\x84" , "\xE2\x80\x85" , "\xE2\x80\x86" , "\xE2\x80\x87" , "\xE2\x80\x88" , "\xE2\x80\x89" , "\xE2\x80\x8A" , "\xE2\x80\xAF" , "\xE2\x81\x9F" , "\xE3\x80\x80" , ] ; $ value = str_replace ( $ whitespace , '-' , $ value ) ; $ value = preg_replace ( '/[^\x20-\x7E]/u' , '' , $ value ) ; $ value = preg_replace ( '![^-\pL\pN\s]+!u' , '' , $ value ) ; if ( $ snake ) { $ value = preg_replace ( '/(.)(?=[A-Z])/u' , '$1-' , $ value ) ; } $ value = preg_replace ( '![-\s]+!u' , '-' , $ value ) ; $ value = mb_strtolower ( $ value , 'UTF-8' ) ; return $ value ; } ; $ replacements = [ '/^(?<!\\\)n$/i' => $ n , '/^(?<!\\\)v$/' => $ toLowerCase ( $ v ) , '/^(?<!\\\)p$/' => $ toLowerCase ( $ p , true ) , '/^(?<!\\\)V$/' => $ v , '/^(?<!\\\)P$/' => $ p , ] ; $ parts = preg_split ( '/((?<!\\\)[v,p,n])/i' , $ format , - 1 , PREG_SPLIT_DELIM_CAPTURE ) ; foreach ( $ parts as & $ part ) { foreach ( $ replacements as $ pattern => $ replacement ) { if ( preg_match ( $ pattern , $ part ) ) { $ part = $ replacement ; break ; } } } $ info = str_replace ( '\\' , '' , implode ( $ parts ) ) ; return $ info ; }
|
Get the Package info in a given format .
|
54,099
|
public function insert ( ... $ field_values ) { if ( $ this -> is_done ) { throw new RuntimeException ( 'This batch insert is already done' ) ; } if ( count ( $ field_values ) == $ this -> fields_num ) { $ this -> rows [ ] = $ this -> connection -> prepare ( $ this -> row_prepare_pattern , ... $ field_values ) ; if ( count ( $ this -> rows ) == $ this -> rows_per_batch ) { $ this -> flush ( ) ; } } else { throw new BadMethodCallException ( 'Number of arguments does not match number of fields' ) ; } }
|
Insert a row with the given field values .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.