idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
5,700
public function save ( $ fields = null ) { $ settings = static :: _model ( ) ; if ( is_null ( $ fields ) ) { $ fields = array_keys ( $ settings [ 'defaults' ] ) ; } elseif ( ! is_array ( $ fields ) ) { $ fields = array ( $ fields ) ; } $ pkey = $ this -> _data_store [ $ settings [ 'primary_key' ] ] ; $ data = array ( ) ; foreach ( $ fields as $ field ) { $ data [ $ field ] = $ this -> _data_store [ $ field ] ; } if ( array_key_exists ( $ settings [ 'primary_key' ] , $ data ) ) { unset ( $ data [ $ settings [ 'primary_key' ] ] ) ; } $ data = $ this -> _before_save ( $ data ) ; foreach ( $ data as $ key => $ value ) { if ( array_key_exists ( $ key , $ settings [ 'types' ] ) ) { $ data [ $ key ] = $ this -> _type_assignment_set ( $ settings [ 'types' ] [ $ key ] , $ value ) ; } } if ( $ settings [ 'timestamps' ] === true ) { if ( array_key_exists ( 'created_at' , $ data ) ) { if ( $ data [ 'created_at' ] < 1 ) { $ this -> _data_store [ 'created_at' ] = $ data [ 'created_at' ] = time ( ) ; } } if ( array_key_exists ( 'modified_at' , $ data ) ) { $ this -> _data_store [ 'modified_at' ] = $ data [ 'modified_at' ] = time ( ) ; } } if ( ! is_null ( $ pkey ) && $ pkey > 0 ) { $ query = DB :: update ( $ settings [ 'table' ] , $ data ) -> where ( $ settings [ 'primary_key' ] , $ pkey ) ; } else { $ query = DB :: insert ( $ settings [ 'table' ] , $ data ) ; } if ( $ query instanceof Query_Insert ) { $ this -> _data_store [ $ settings [ 'primary_key' ] ] = $ query -> run ( ) ; } else { $ query -> run ( ) ; } $ this -> _after_save ( ) ; return $ this ; }
save an model
5,701
public function delete ( ) { $ settings = static :: _model ( ) ; $ result = DB :: delete ( $ settings [ 'table' ] ) -> where ( $ settings [ 'primary_key' ] , $ this -> _data_store [ $ settings [ 'primary_key' ] ] ) -> limit ( 1 ) -> run ( $ settings [ 'handler' ] ) ; $ this -> _data_store [ $ cache [ 'primary_key' ] ] = null ; return $ result ; }
Delete the current model from the database
5,702
public function navigation ( ) { if ( $ this -> validCache ( $ this -> nav ) ) { $ value = $ this -> nav ; } else { $ value = $ this -> getCache ( ) ; if ( ! $ this -> validCache ( $ value ) ) { $ value = $ this -> sendGet ( ) ; $ this -> setCache ( $ value ) ; } } $ this -> nav = $ value ; return $ value ; }
Get the page navigation .
5,703
protected function validCache ( $ value ) { if ( is_null ( $ value ) || ! is_array ( $ value ) || empty ( $ value ) ) { return false ; } return true ; }
Check of the nav var is not corrupt .
5,704
public function renderCommand ( $ reference = null ) { $ references = $ reference !== null ? [ $ reference ] : array_keys ( $ this -> settings [ 'commandReferences' ] ) ; $ this -> renderReferences ( $ references ) ; }
Renders command reference documentation from source code .
5,705
protected function renderReferences ( $ references ) { foreach ( $ references as $ reference ) { $ this -> outputLine ( 'Rendering Reference "%s"' , [ $ reference ] ) ; $ this -> renderReference ( $ reference ) ; } }
Render a set of CLI command references to reStructuredText .
5,706
private function createCreateForm ( Scope $ scope ) { $ form = $ this -> createForm ( new ScopeType ( ) , $ scope , array ( 'action' => $ this -> generateUrl ( 'admin_scope_create' ) , 'method' => 'POST' , ) ) ; $ form -> add ( 'submit' , 'submit' , array ( 'label' => 'Create' ) ) ; return $ form ; }
Creates a form to create a Scope entity .
5,707
public function newAction ( ) { $ scope = new Scope ( ) ; $ form = $ this -> createCreateForm ( $ scope ) ; return $ this -> render ( 'ChillMainBundle:Scope:new.html.twig' , array ( 'entity' => $ scope , 'form' => $ form -> createView ( ) , ) ) ; }
Displays a form to create a new Scope entity .
5,708
private function createEditForm ( Scope $ scope ) { $ form = $ this -> createForm ( new ScopeType ( ) , $ scope , array ( 'action' => $ this -> generateUrl ( 'admin_scope_update' , array ( 'id' => $ scope -> getId ( ) ) ) , 'method' => 'PUT' , ) ) ; $ form -> add ( 'submit' , 'submit' , array ( 'label' => 'Update' ) ) ; return $ form ; }
Creates a form to edit a Scope entity .
5,709
protected function fileMatchesMoreSpecificExtension ( string $ filename , string $ extension ) : bool { return array_reduce ( $ this -> extensions , function ( $ match , $ compare ) use ( $ filename , $ extension ) { if ( $ match || $ compare === $ extension || strlen ( $ compare ) < strlen ( $ extension ) ) { return $ match ; } return $ filename === basename ( $ filename , ".{$compare}" ) . ".{$compare}" ; } , false ) ; }
Determines if a file matches another more specific extension
5,710
protected function mergeConfigs ( array $ old , array $ new ) : array { foreach ( $ new as $ key => $ val ) { if ( ! array_key_exists ( $ key , $ old ) || ! is_array ( $ old [ $ key ] ) || ! is_array ( $ val ) ) { $ old [ $ key ] = $ val ; continue ; } if ( is_int ( $ key ) ) { $ old [ ] = $ val ; continue ; } $ old [ $ key ] = $ this -> mergeConfigs ( $ old [ $ key ] , $ val ) ; } return $ old ; }
Recusively merges configs together
5,711
public static function getMappings ( ) { $ basePath = self :: getBasePath ( ) ; return array ( realpath ( $ basePath . 'Address/Resources/config/doctrine/model' ) => 'LMammino\EFoundation\Address\Model' , realpath ( $ basePath . 'Attribute/Resources/config/doctrine/model' ) => 'LMammino\EFoundation\Attribute\Model' , realpath ( $ basePath . 'Cart/Resources/config/doctrine/model' ) => 'LMammino\EFoundation\Cart\Model' , realpath ( $ basePath . 'Order/Resources/config/doctrine/model' ) => 'LMammino\EFoundation\Order\Model' , realpath ( $ basePath . 'Price/Resources/config/doctrine/model' ) => 'LMammino\EFoundation\Price\Model' , realpath ( $ basePath . 'Product/Resources/config/doctrine/model' ) => 'LMammino\EFoundation\Product\Model' , realpath ( $ basePath . 'Variation/Resources/config/doctrine/model' ) => 'LMammino\EFoundation\Variation\Model' , ) ; }
Get the mapping
5,712
public function PrimaryImage ( ) { $ image = $ this -> owner -> Image ( ) ; if ( $ image -> exists ( ) ) { return $ image ; } $ product = $ this -> owner -> AllProducts ( ) -> first ( ) ; if ( ! empty ( $ product ) ) { return $ product -> PrimaryImage ( ) ; } return Helper :: generate_no_image ( ) ; }
Gets the main image to use for this category this can either be the selected image an image from the first product or the default no - product image .
5,713
public static function decode ( ResponseInterface $ response ) : array { $ contents = $ response -> getBody ( ) -> getContents ( ) ; $ decoded = json_decode ( $ contents , true ) ; $ response -> getBody ( ) -> rewind ( ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE || ! is_array ( $ decoded ) ) { throw new JsonException ( json_last_error_msg ( ) ) ; } return $ decoded ; }
Json decode an http response .
5,714
public function addQuery ( DBUtilQuery $ query ) { if ( $ query -> getName ( ) !== null ) { $ this -> _queryQueue [ $ query -> getName ( ) ] = $ query ; } else { $ this -> _queryQueue [ ] = $ query ; } new Logger ( 'Query added to the queue.' , Logger :: DEBUG , __CLASS__ , __LINE__ ) ; return $ this ; }
Adds a query with it s parameters to the query queue .
5,715
public function addQueries ( $ queries ) { if ( is_array ( $ queries ) ) { foreach ( $ queries as $ query ) { $ this -> addQuery ( $ query ) ; } new Logger ( 'Queries added to the queue.' , Logger :: DEBUG , __CLASS__ , __LINE__ ) ; return $ this ; } new Logger ( 'Failed to add to the queue.' , Logger :: ERROR , __CLASS__ , __LINE__ ) ; return $ this ; }
Add an array of DBUtilQuery s to the query_queue .
5,716
public function add_error ( $ key , $ message ) { $ this -> success = false ; $ this -> errors [ $ key ] [ ] = $ message ; }
Add an error to validator
5,717
public function label ( $ data , $ value = null ) { if ( ! is_null ( $ value ) && ! is_array ( $ data ) ) { $ data = array ( $ data => $ value ) ; } if ( ! is_array ( $ data ) ) { throw new \ InvalidArgumentException ( 'CCValidator::label - invalid label data given' ) ; } $ this -> labels = array_merge ( $ this -> labels , $ data ) ; }
Set a data value
5,718
public function rules ( ) { $ args = func_get_args ( ) ; $ key = array_shift ( $ args ) ; if ( ! is_array ( reset ( $ args ) ) ) { $ rules = $ args ; } else { $ rules = array_shift ( $ args ) ; } $ success = true ; foreach ( $ rules as $ rule ) { $ rule = explode ( ':' , $ rule ) ; $ params = array ( ) ; if ( array_key_exists ( 1 , $ rule ) ) { $ params = explode ( ',' , $ rule [ 1 ] ) ; } $ rule = reset ( $ rule ) ; array_unshift ( $ params , $ key ) ; if ( ! call_user_func_array ( array ( $ this , $ rule ) , $ params ) ) { $ success = false ; } } return $ success ; }
Apply multiple rules to one attribute
5,719
public function message ( ) { $ params = func_get_args ( ) ; $ message = array_shift ( $ params ) ; $ method = array_shift ( $ params ) ; if ( ! $ result = $ this -> validate ( $ method , $ params ) ) { $ key = array_shift ( $ params ) ; $ params = $ this -> get_error_message_params ( $ key , $ params ) ; foreach ( $ params as $ param => $ value ) { $ message = str_replace ( ':' . $ param , $ value , $ message ) ; } $ this -> errors [ $ key ] [ ] = $ message ; } return $ result ; }
Run the validation with a custom message
5,720
protected function validate ( $ method , $ params ) { $ reverse = false ; if ( substr ( $ method , 0 , 4 ) === 'not_' ) { $ reverse = true ; $ method = substr ( $ method , 4 ) ; } if ( array_key_exists ( $ method , static :: $ rules ) ) { return $ this -> apply_rule ( $ method , static :: $ rules [ $ method ] , $ params , $ reverse ) ; } if ( method_exists ( $ this , 'rule_' . $ method ) ) { return $ this -> apply_rule ( $ method , array ( $ this , 'rule_' . $ method ) , $ params , $ reverse ) ; } throw new \ BadMethodCallException ( "CCValidator - Invalid rule or method '" . $ method . "'." ) ; }
Run an validation call
5,721
protected function proof_result ( $ rule , $ key , $ result ) { if ( $ result === false ) { $ this -> failed [ $ key ] [ ] = $ rule ; } if ( $ this -> success === true ) { return $ this -> success = $ result ; } return $ result ; }
Proof a single result and update the success property
5,722
protected function apply_rule ( $ rule , $ callback , $ params , $ reverse ) { $ data_key = array_shift ( $ params ) ; if ( ! array_key_exists ( $ data_key , $ this -> data ) ) { return $ this -> proof_result ( $ rule , $ data_key , ( $ reverse ? true : false ) ) ; } $ call_arguments = array ( $ data_key , $ this -> data [ $ data_key ] ) ; $ call_arguments = array_merge ( $ call_arguments , $ params ) ; $ result = ( bool ) call_user_func_array ( $ callback , $ call_arguments ) ; if ( $ reverse ) { $ result = ! $ result ; } return $ this -> proof_result ( $ rule , $ data_key , $ result ) ; }
Apply an rule executes the rule and runs the result proof
5,723
protected function get_error_message_params ( $ key , $ params ) { if ( isset ( $ this -> labels [ $ key ] ) ) { $ field = $ this -> labels [ $ key ] ; } else { $ field = ucfirst ( str_replace ( array ( '_' , '-' ) , ' ' , $ key ) ) ; } return array_merge ( array ( 'field' => $ field ) , $ params ) ; }
Get the parameter array for the error messages
5,724
protected function generate_error_message ( $ rule , $ key , $ params ) { $ params = $ this -> get_error_message_params ( $ key , $ params ) ; return __ ( ClanCats :: $ config -> get ( 'validation.language_prefix' ) . '.' . $ rule , $ params ) ; }
Generate the error message for an rule
5,725
public function rule_required ( $ key , $ value ) { if ( is_null ( $ value ) ) { return false ; } elseif ( is_string ( $ value ) && trim ( $ value ) == '' ) { return false ; } return true ; }
Check if the field is set an not empty
5,726
public function rule_between_num ( $ key , $ value , $ min , $ max ) { if ( ! $ this -> rule_min_num ( $ key , $ value , $ min ) ) { return false ; } if ( ! $ this -> rule_max_num ( $ key , $ value , $ max ) ) { return false ; } return true ; }
Is the given number between min and max
5,727
public function rule_min ( $ key , $ value , $ min ) { return $ this -> rule_min_num ( $ key , strlen ( $ value ) , $ min ) ; }
Is the given string at least some size
5,728
public function rule_max ( $ key , $ value , $ max ) { return $ this -> rule_max_num ( $ key , strlen ( $ value ) , $ max ) ; }
Is the given string max some size
5,729
public function rule_between ( $ key , $ value , $ min , $ max ) { return $ this -> rule_between_num ( $ key , strlen ( $ value ) , $ min , $ max ) ; }
Is the given string between min and max
5,730
public function rule_date_format ( $ key , $ value , $ format = 'd/m/Y' ) { return date ( $ format , strtotime ( trim ( $ value ) ) ) == trim ( $ value ) ; }
Check if valid date format
5,731
protected function get ( $ data , string $ key ) { $ dot = $ data instanceof Dot ? $ data : new Dot ( $ data ) ; if ( isset ( $ dot [ $ key ] ) ) { return $ dot [ $ key ] ; } throw new UnexpectedResponseException ( sprintf ( 'Missing key \'%s\' in data' ) ) ; }
Extract data from an array using dot notation . Throws an exception when the provided key does not exist .
5,732
public function notify ( $ eventName , array $ params = array ( ) ) { $ this -> dispatcher -> notify ( $ e = $ this -> createEvent ( $ eventName , $ params ) ) ; return $ e ; }
Creates and dispatches an event
5,733
public function notifyUntil ( $ eventName , array $ params = array ( ) , $ callback = null ) { $ this -> dispatcher -> notifyUntil ( $ e = $ this -> createEvent ( $ eventName , $ params ) , $ callback ) ; return $ e ; }
Creates and dispatches an event until it has been processed .
5,734
public static function make ( Client $ httpClient , array $ params = [ ] ) { $ instance = new static ( $ httpClient ) ; $ instance -> configure ( $ params ) ; return $ instance ; }
Create a new resource instance .
5,735
public function send ( ) { $ request = $ this -> createRequest ( ) ; $ response = $ this -> httpClient -> sendRequest ( $ request ) ; return $ this -> mapResponse ( ( array ) $ this -> parseResponse ( $ response ) ) ; }
Send a new request .
5,736
public function getPreparedData ( ) { $ params = $ this -> getData ( ) ; if ( $ this -> authorize ) { $ params = array_merge ( $ params , $ this -> authenticationData ( $ params ) ) ; } return $ params ; }
Get the request data for authorized or not .
5,737
public function __isset ( $ name ) { if ( $ this -> thawedObject === null ) { if ( $ name === $ this -> storage -> getFreezer ( ) -> getIdProperty ( ) ) { return true ; } } return isset ( $ this -> replaceProxy ( 2 ) -> { $ name } ) ; }
Delegates the property isset check to the real object and tries to replace the lazy proxy object with it .
5,738
protected function replaceProxy ( $ offset ) { $ object = $ this -> getObject ( ) ; $ trace = debug_backtrace ( ) ; if ( isset ( $ trace [ $ offset ] [ 'object' ] ) ) { $ reflector = new \ ReflectionObject ( $ trace [ $ offset ] [ 'object' ] ) ; foreach ( $ reflector -> getProperties ( ) as $ property ) { $ property -> setAccessible ( true ) ; if ( $ property -> getValue ( $ trace [ $ offset ] [ 'object' ] ) === $ this ) { $ property -> setValue ( $ trace [ $ offset ] [ 'object' ] , $ object ) ; break ; } } } return $ object ; }
Tries to replace the lazy proxy object with the real object .
5,739
public function newVar ( $ str ) { $ str = trim ( $ str ) ; if ( preg_match ( '/^[a-zA-Z0-9\'_][a-zA-Z0-9\'_-]*$/' , $ str ) ) return new Atom ( EXPR_VAR , $ str ) ; else { return false ; } }
Creates a new variable atom subsequent to validating that the string is correct for a variable
5,740
protected static function buildExecutionContext ( Schema $ schema , $ root , Document $ ast , $ operationName = NULL , array $ args = NULL , & $ errors ) { $ operations = [ ] ; $ fragments = [ ] ; foreach ( $ ast -> get ( 'definitions' ) as $ statement ) { switch ( $ statement :: KIND ) { case Node :: KIND_OPERATION_DEFINITION : $ operations [ $ statement -> get ( 'name' ) ? $ statement -> get ( 'name' ) -> get ( 'value' ) : '' ] = $ statement ; break ; case Node :: KIND_FRAGMENT_DEFINITION : $ fragments [ $ statement -> get ( 'name' ) -> get ( 'value' ) ] = $ statement ; break ; } } if ( ! $ operationName && count ( $ operations ) !== 1 ) { throw new \ Exception ( 'Must provide operation name if query contains multiple operations' ) ; } $ name = $ operationName ? : key ( $ operations ) ; if ( ! isset ( $ operations [ $ name ] ) ) { throw new \ Exception ( 'Unknown operation name: ' . $ name ) ; } $ operation = $ operations [ $ name ] ; $ variables = Values :: getVariableValues ( $ schema , $ operation -> get ( 'variableDefinitions' ) ? : [ ] , $ args ? : [ ] ) ; $ context = new ExecutionContext ( $ schema , $ fragments , $ root , $ operation , $ variables , $ errors ) ; return $ context ; }
Constructs a ExecutionContext object from the arguments passed to execute which we will pass throughout the other execution methods .
5,741
protected static function executeOperation ( ExecutionContext $ context , $ root , OperationDefinition $ operation ) { $ type = self :: getOperationRootType ( $ context -> schema , $ operation ) ; $ fields = self :: collectFields ( $ context , $ type , $ operation -> get ( 'selectionSet' ) , new \ ArrayObject ( ) , new \ ArrayObject ( ) ) ; if ( $ operation -> get ( 'operation' ) === 'mutation' ) { return self :: executeFieldsSerially ( $ context , $ type , $ root , $ fields -> getArrayCopy ( ) ) ; } return self :: executeFields ( $ context , $ type , $ root , $ fields ) ; }
Implements the Evaluating operations section of the spec .
5,742
protected static function getOperationRootType ( Schema $ schema , OperationDefinition $ operation ) { switch ( $ operation -> get ( 'operation' ) ) { case 'query' : return $ schema -> getQueryType ( ) ; case 'mutation' : $ mutationType = $ schema -> getMutationType ( ) ; if ( ! $ mutationType ) { throw new \ Exception ( 'Schema is not configured for mutations.' ) ; } return $ mutationType ; } throw new \ Exception ( 'Can only execute queries and mutations.' ) ; }
Extracts the root type of the operation from the schema .
5,743
protected static function executeFieldsSerially ( ExecutionContext $ context , ObjectType $ parent , $ source , $ fields ) { $ results = [ ] ; foreach ( $ fields as $ response => $ asts ) { $ result = self :: resolveField ( $ context , $ parent , $ source , $ asts ) ; if ( $ result !== self :: $ UNDEFINED ) { $ results [ $ response ] = $ result ; } } return $ results ; }
Implements the Evaluating selection sets section of the spec for write mode .
5,744
protected static function executeFields ( ExecutionContext $ context , ObjectType $ parent , $ source , $ fields ) { return self :: executeFieldsSerially ( $ context , $ parent , $ source , $ fields ) ; }
Implements the Evaluating selection sets section of the spec for read mode .
5,745
protected static function collectFields ( ExecutionContext $ context , ObjectType $ type , SelectionSet $ set , $ fields , $ visited ) { $ count = count ( $ set -> get ( 'selections' ) ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ selection = $ set -> get ( 'selections' ) [ $ i ] ; switch ( $ selection :: KIND ) { case Node :: KIND_FIELD : if ( ! self :: shouldIncludeNode ( $ context , $ selection -> get ( 'directives' ) ) ) { continue ; } $ name = self :: getFieldEntryKey ( $ selection ) ; if ( ! isset ( $ fields [ $ name ] ) ) { $ fields [ $ name ] = new \ ArrayObject ( ) ; } $ fields [ $ name ] [ ] = $ selection ; break ; case Node :: KIND_INLINE_FRAGMENT : if ( ! self :: shouldIncludeNode ( $ context , $ selection -> get ( 'directives' ) ) || ! self :: doesFragmentConditionMatch ( $ context , $ selection , $ type ) ) { continue ; } self :: collectFields ( $ context , $ type , $ selection -> get ( 'selectionSet' ) , $ fields , $ visited ) ; break ; case Node :: KIND_FRAGMENT_SPREAD : $ fragName = $ selection -> get ( 'name' ) -> get ( 'value' ) ; if ( ! empty ( $ visited [ $ fragName ] ) || ! self :: shouldIncludeNode ( $ context , $ selection -> get ( 'directives' ) ) ) { continue ; } $ visited [ $ fragName ] = TRUE ; $ fragment = isset ( $ context -> fragments [ $ fragName ] ) ? $ context -> fragments [ $ fragName ] : NULL ; if ( ! $ fragment || ! self :: shouldIncludeNode ( $ context , $ fragment -> get ( 'directives' ) ) || ! self :: doesFragmentConditionMatch ( $ context , $ fragment , $ type ) ) { continue ; } self :: collectFields ( $ context , $ type , $ fragment -> get ( 'selectionSet' ) , $ fields , $ visited ) ; break ; } } return $ fields ; }
Given a selectionSet adds all of the fields in that selection to the passed in map of fields and returns it at the end .
5,746
protected static function shouldIncludeNode ( ExecutionContext $ exeContext , $ directives ) { $ skip = Directive :: skipDirective ( ) ; $ include = Directive :: includeDirective ( ) ; foreach ( $ directives as $ directive ) { if ( $ directive -> get ( 'name' ) -> get ( 'value' ) === $ skip -> getName ( ) ) { $ values = Values :: getArgumentValues ( $ skip -> getArguments ( ) , $ directive -> get ( 'arguments' ) , $ exeContext -> variables ) ; return empty ( $ values [ 'if' ] ) ; } if ( $ directive -> get ( 'name' ) -> get ( 'value' ) === $ include -> getName ( ) ) { $ values = Values :: getArgumentValues ( $ skip -> getArguments ( ) , $ directive -> get ( 'arguments' ) , $ exeContext -> variables ) ; return ! empty ( $ values [ 'if' ] ) ; } } return TRUE ; }
Determines if a field should be included based on
5,747
protected static function doesFragmentConditionMatch ( ExecutionContext $ context , $ fragment , ObjectType $ type ) { $ typeCondition = $ fragment -> get ( 'typeCondition' ) ; if ( ! $ typeCondition ) { return TRUE ; } $ conditionalType = TypeInfo :: typeFromAST ( $ context -> schema , $ typeCondition ) ; if ( $ conditionalType -> getName ( ) === $ type -> getName ( ) ) { return TRUE ; } if ( $ conditionalType instanceof InterfaceType || $ conditionalType instanceof UnionType ) { return $ conditionalType -> isPossibleType ( $ type ) ; } return FALSE ; }
Determines if a fragment is applicable to the given type .
5,748
protected static function getFieldEntryKey ( Field $ node ) { return $ node -> get ( 'alias' ) ? $ node -> get ( 'alias' ) -> get ( 'value' ) : $ node -> get ( 'name' ) -> get ( 'value' ) ; }
Implements the logic to compute the key of a given field s entry
5,749
protected static function resolveField ( ExecutionContext $ context , ObjectType $ parent , $ source , $ asts ) { $ definition = self :: getFieldDefinition ( $ context -> schema , $ parent , $ asts [ 0 ] ) ; if ( ! $ definition ) { return self :: $ UNDEFINED ; } if ( $ definition -> getType ( ) instanceof NonNullModifier ) { return self :: resolveFieldOrError ( $ context , $ parent , $ source , $ asts , $ definition ) ; } try { $ result = self :: resolveFieldOrError ( $ context , $ parent , $ source , $ asts , $ definition ) ; return $ result ; } catch ( \ Exception $ error ) { $ context -> errors [ ] = $ error ; return NULL ; } }
A wrapper function for resolving the field that catches the error and adds it to the context s global if the error is not rethrowable .
5,750
protected static function resolveFieldOrError ( ExecutionContext $ context , ObjectType $ parent , $ source , $ asts , FieldDefinition $ definition ) { $ ast = $ asts [ 0 ] ; $ type = $ definition -> getType ( ) ; $ resolver = $ definition -> getResolveCallback ( ) ? : [ __CLASS__ , 'defaultResolveFn' ] ; $ data = $ definition -> getResolveData ( ) ; $ args = Values :: getArgumentValues ( $ definition -> getArguments ( ) , $ ast -> get ( 'arguments' ) , $ context -> variables ) ; try { $ result = call_user_func ( $ resolver , $ source , $ args , $ context -> root , $ ast , $ type , $ parent , $ context -> schema , $ data ) ; } catch ( \ Exception $ error ) { throw $ error ; } return self :: completeField ( $ context , $ type , $ asts , $ result ) ; }
Resolves the field on the given source object .
5,751
public static function defaultResolveFn ( $ source , $ args , $ root , $ ast ) { $ property = NULL ; $ key = $ ast -> get ( 'name' ) -> get ( 'value' ) ; if ( ( is_array ( $ source ) || $ source instanceof \ ArrayAccess ) && isset ( $ source [ $ key ] ) ) { $ property = $ source [ $ key ] ; } else if ( is_object ( $ source ) && property_exists ( $ source , $ key ) ) { if ( $ key !== 'ofType' ) { $ property = $ source -> { $ key } ; } } return is_callable ( $ property ) ? call_user_func ( $ property , $ source ) : $ property ; }
If a resolve function is not given then a default resolve behavior is used which takes the property of the source object of the same name as the field and returns it as the result or if it s a function returns the result of calling that function .
5,752
public function htmlEncode ( $ data ) { switch ( gettype ( $ data ) ) { case 'array' : foreach ( $ data as $ key => $ value ) { $ data [ $ key ] = $ this -> htmlEncode ( $ value ) ; } break ; case 'object' : $ data = clone $ data ; foreach ( $ data as $ key => $ value ) { $ data -> $ key = $ this -> htmlEncode ( $ value ) ; } break ; case 'string' : default : $ data = htmlentities ( $ data , ENT_QUOTES , 'UTF-8' ) ; break ; } return $ data ; }
Recursively make a value safe for HTML
5,753
public function htmlDecode ( $ data ) { switch ( gettype ( $ data ) ) { case 'array' : foreach ( $ data as $ key => $ value ) { $ data [ $ key ] = $ this -> htmlDecode ( $ value ) ; } break ; case 'object' : $ data = clone $ data ; foreach ( $ data as $ key => $ value ) { $ data -> $ key = $ this -> htmlDecode ( $ value ) ; } break ; case 'string' : default : $ data = html_entity_decode ( $ data , ENT_QUOTES , 'UTF-8' ) ; break ; } return $ data ; }
Recursively decode an HTML encoded value
5,754
public function get ( $ variable , $ htmlEncode = true ) { $ value = null ; if ( isset ( $ this -> variables [ $ variable ] ) ) { $ value = $ this -> variables [ $ variable ] [ $ htmlEncode ? 'safe' : 'unsafe' ] ; } return $ value ; }
Get a view variable
5,755
public function set ( $ variable , $ value = null ) { $ this -> variables [ $ variable ] = array ( 'safe' => $ this -> htmlEncode ( $ value ) , 'unsafe' => $ value ) ; return $ this ; }
Set a view variable
5,756
public function setVariables ( $ variables = [ ] ) { foreach ( $ variables as $ variable => $ value ) { $ this -> set ( $ variable , $ value ) ; } }
Set all variables
5,757
public function render ( $ file = '' ) { $ viewManager = $ this -> config -> get ( 'view_manager' ) ; if ( $ viewManager [ 'template_path_stack' ] ) { $ file = $ viewManager [ 'template_path_stack' ] . '/' . $ file ; } $ fileInfo = pathinfo ( $ file ) ; if ( ! isset ( $ fileInfo [ 'extension' ] ) || $ fileInfo [ 'extension' ] != 'phtml' ) { $ file = $ file . '.phtml' ; } if ( is_file ( $ file ) ) { if ( ! headers_sent ( ) ) { header ( 'X-Generator: JiNexus Framework' ) ; } ob_start ( ) ; include $ file ; ob_end_flush ( ) ; } else { throw new Exception ( 'View not found' ) ; } }
Render a file
5,758
public function path ( ) { $ clean = function ( $ v ) { return str_replace ( '/' , '' , $ v ) ; } ; return join ( '/' , array_map ( $ clean , $ this -> groups ) ) ; }
Returns a complete path
5,759
public function unregister ( $ alias ) { unset ( $ this -> files [ $ alias ] ) ; $ key = array_search ( $ alias , $ this -> enqueued ) ; if ( $ key !== FALSE ) { unset ( $ this -> enqueued [ $ key ] ) ; } return $ this ; }
Entfernt eine registrierte Datei
5,760
public static function start ( $ key , $ attr = array ( ) ) { $ attributes = array ( ) ; $ attributes [ 'role' ] = 'form' ; if ( ! is_null ( $ key ) ) { static :: $ id_prefix = $ attributes [ 'id' ] = static :: form_id ( 'form' , $ key ) ; } $ attributes = array_merge ( $ attributes , $ attr ) ; return '<form' . HTML :: attr ( $ attributes ) . '>' ; }
Open a new form This will set the current form to this one
5,761
public static function capture ( $ callback = null , $ key = null , $ attr = null ) { if ( is_callable ( $ attr ) && ! is_callable ( $ callback ) ) { $ new_attr = $ key ; $ key = $ callback ; $ callback = $ attr ; $ attr = $ new_attr ; } $ form = new static ; if ( is_null ( $ callback ) ) { throw new Exception ( 'Cannot use capture without a callback or string given.' ) ; } if ( ! is_array ( $ attr ) ) { $ attr = array ( ) ; } return static :: start ( $ key , $ attr ) . \ CCStr :: capture ( $ callback , array ( $ form ) ) . static :: end ( ) ; }
Create a new from instance
5,762
public static function build_id ( $ type , $ name ) { if ( ! is_null ( static :: $ id_prefix ) ) { return static :: $ id_prefix . '-' . static :: form_id ( $ type , $ name ) ; } return static :: form_id ( $ type , $ name ) ; }
Format an id by configartion with the current form prefix
5,763
public static function make_input ( $ id , $ key , $ value = null , $ type = 'text' , $ attr = array ( ) ) { $ element = HTML :: tag ( 'input' , array_merge ( array ( 'id' => $ id , 'name' => $ key , 'type' => $ type ) , $ attr ) ) ; if ( ! is_null ( $ value ) ) { $ element -> value ( _e ( $ value ) ) ; } if ( ! static :: $ builder_enabled ) { return $ element ; } return Builder :: handle ( 'form_input' , $ element ) ; }
make an input
5,764
public static function make_label ( $ id , $ key , $ text = null , $ attr = array ( ) ) { if ( is_null ( $ text ) ) { $ text = $ key ; } $ element = HTML :: tag ( 'label' , $ text , array_merge ( array ( 'id' => $ id , 'for' => static :: build_id ( 'input' , $ key ) ) , $ attr ) ) ; if ( ! static :: $ builder_enabled ) { return $ element ; } return Builder :: handle ( 'form_label' , $ element ) ; }
make a label
5,765
public static function make_checkbox ( $ id , $ key , $ text = '' , $ active = false , $ attr = array ( ) ) { $ element = HTML :: tag ( 'input' , array_merge ( array ( 'id' => $ id , 'name' => $ key , 'type' => 'checkbox' ) , $ attr ) ) ; $ element -> checked ( ( bool ) $ active ) ; $ element = HTML :: tag ( 'label' , $ element -> render ( ) . ' ' . $ text ) ; if ( ! static :: $ builder_enabled ) { return $ element ; } return Builder :: handle ( 'form_checkbox' , $ element ) ; }
make a checkbox
5,766
public static function make_select ( $ id , $ name , array $ options , $ selected = array ( ) , $ size = 1 ) { if ( ! is_array ( $ selected ) ) { $ selected = array ( $ selected ) ; } $ buffer = "" ; foreach ( $ options as $ key => $ option ) { if ( ! ( $ option instanceof HTML ) ) { $ option = HTML :: tag ( 'option' , $ option ) -> value ( $ key ) ; } if ( in_array ( $ key , $ selected ) ) { $ option -> selected ( true ) ; } $ buffer .= $ option -> render ( ) ; } $ element = HTML :: tag ( 'select' , $ buffer , array ( 'id' => $ id , 'name' => $ name , 'size' => $ size , ) ) ; if ( ! static :: $ builder_enabled ) { return $ element ; } return Builder :: handle ( 'form_select' , $ element ) ; }
generate an select
5,767
public function renderCollectionCommand ( $ collection ) { if ( ! isset ( $ this -> settings [ 'collections' ] [ $ collection ] ) ) { $ this -> outputLine ( 'Collection "%s" is not configured' , [ $ collection ] ) ; $ this -> quit ( 1 ) ; } if ( ! isset ( $ this -> settings [ 'collections' ] [ $ collection ] [ 'references' ] ) ) { $ this -> outputLine ( 'Collection "%s" does not have any references' , [ $ collection ] ) ; $ this -> quit ( 1 ) ; } $ references = $ this -> settings [ 'collections' ] [ $ collection ] [ 'references' ] ; $ this -> renderReferences ( $ references ) ; }
Renders a configured collection of reference documentation from source code .
5,768
protected function renderReference ( $ reference ) { if ( ! isset ( $ this -> settings [ 'references' ] [ $ reference ] ) ) { $ this -> outputLine ( 'Reference "%s" is not configured' , [ $ reference ] ) ; $ this -> quit ( 1 ) ; } $ referenceConfiguration = $ this -> settings [ 'references' ] [ $ reference ] ; $ affectedClassNames = $ this -> getAffectedClassNames ( $ referenceConfiguration [ 'affectedClasses' ] ) ; $ parserClassName = $ referenceConfiguration [ 'parser' ] [ 'implementationClassName' ] ; $ parserOptions = isset ( $ referenceConfiguration [ 'parser' ] [ 'options' ] ) ? $ referenceConfiguration [ 'parser' ] [ 'options' ] : [ ] ; $ classParser = new $ parserClassName ( $ parserOptions ) ; $ classReferences = [ ] ; foreach ( $ affectedClassNames as $ className ) { $ classReferences [ $ className ] = $ classParser -> parse ( $ className ) ; } usort ( $ classReferences , function ( ClassReference $ a , ClassReference $ b ) { if ( $ a -> getTitle ( ) == $ b -> getTitle ( ) ) { return 0 ; } return ( $ a -> getTitle ( ) < $ b -> getTitle ( ) ) ? - 1 : 1 ; } ) ; $ standaloneView = new \ Neos \ FluidAdaptor \ View \ StandaloneView ( ) ; $ templatePathAndFilename = isset ( $ referenceConfiguration [ 'templatePathAndFilename' ] ) ? $ referenceConfiguration [ 'templatePathAndFilename' ] : 'resource://Neos.DocTools/Private/Templates/ClassReferenceTemplate.txt' ; $ standaloneView -> setTemplatePathAndFilename ( $ templatePathAndFilename ) ; $ standaloneView -> assign ( 'title' , isset ( $ referenceConfiguration [ 'title' ] ) ? $ referenceConfiguration [ 'title' ] : $ reference ) ; $ standaloneView -> assign ( 'classReferences' , $ classReferences ) ; file_put_contents ( $ referenceConfiguration [ 'savePathAndFilename' ] , $ standaloneView -> render ( ) ) ; $ this -> outputLine ( 'DONE.' ) ; }
Render a reference to reStructuredText .
5,769
public function flashMessage ( $ message ) { $ sessions = $ this -> getSessions ( ) -> getSessionSection ( 'flash.message' ) ; $ sessions -> message = $ message ; $ sessions -> setExpiration ( '5 second' ) ; return $ sessions -> message ; }
Create flash message .
5,770
public function buildLogger ( $ class , Configurator $ configurator ) { if ( ! class_exists ( $ class ) || ! is_subclass_of ( $ class , Logger :: class ) ) { $ class = "\\Phassets\\Loggers\\$class" ; } if ( class_exists ( $ class ) && is_subclass_of ( $ class , Logger :: class ) ) { return new $ class ( $ configurator ) ; } return false ; }
Creates a Logger instance .
5,771
public function buildCacheAdapter ( $ class , Configurator $ configurator ) { if ( ! class_exists ( $ class ) || ! is_subclass_of ( $ class , CacheAdapter :: class ) ) { $ class = "\\Phassets\\CacheAdapters\\$class" ; } if ( class_exists ( $ class ) && is_subclass_of ( $ class , CacheAdapter :: class ) ) { return new $ class ( $ configurator ) ; } return false ; }
Creates a CacheAdapter instance .
5,772
public function buildDeployer ( $ class , Configurator $ configurator , CacheAdapter $ cacheAdapter ) { if ( ! class_exists ( $ class ) || ! is_subclass_of ( $ class , Deployer :: class ) ) { $ class = "\\Phassets\\Deployers\\$class" ; } if ( class_exists ( $ class ) && is_subclass_of ( $ class , Deployer :: class ) ) { return new $ class ( $ configurator , $ cacheAdapter ) ; } return false ; }
Creates a Deployer instance .
5,773
public function buildFilter ( $ class , Configurator $ configurator ) { if ( ! class_exists ( $ class ) || ! is_subclass_of ( $ class , Filter :: class ) ) { $ class = "\\Phassets\\Filters\\$class" ; } if ( class_exists ( $ class ) && is_subclass_of ( $ class , Filter :: class ) ) { return new $ class ( $ configurator ) ; } return false ; }
Creates a Filter instance .
5,774
public function buildAssetsMerger ( $ class , Configurator $ configurator ) { if ( ! class_exists ( $ class ) || ! is_subclass_of ( $ class , AssetsMerger :: class ) ) { $ class = "\\Phassets\\AssetsMergers\\$class" ; } if ( class_exists ( $ class ) && is_subclass_of ( $ class , AssetsMerger :: class ) ) { return new $ class ( $ configurator ) ; } return false ; }
Creates an AssetsMerger instance .
5,775
public function show ( OutputInterface $ output , array $ response ) { $ this -> printList ( $ output , [ 'Name' , 'Description' , 'Source' , 'Archive' , 'Key' , 'Type' , 'License' , 'Version' , 'Group' , 'Updated At' ] , [ 'name' , 'description' , 'links' , 'archives' , 'prod_key' , 'prod_type' , 'license_info' , 'version' , 'group_id' , 'updated_at' ] , $ response , function ( $ heading , $ value ) { if ( 'Source' === $ heading ) { if ( ! empty ( $ value ) ) { return array_pop ( $ value ) [ 'link' ] ; } } if ( 'Archive' === $ heading ) { return array_pop ( $ value ) [ 'link' ] ; } return $ value ; } ) ; $ this -> printTable ( $ output , [ 'Name' , 'Current' , 'Requested' ] , [ 'name' , 'parsed_version' , 'version' ] , $ response [ 'dependencies' ] ) ; }
output for the show API .
5,776
public function versions ( OutputInterface $ output , array $ response ) { $ this -> printList ( $ output , [ 'Name' , 'Language' , 'Key' , 'Type' , 'Version' ] , [ 'name' , 'language' , 'prod_key' , 'prod_type' , 'version' ] , $ response ) ; $ this -> printTable ( $ output , [ 'Version' , 'Released At' ] , [ 'version' , 'released_at' ] , $ response [ 'versions' ] , function ( $ key , $ value ) { if ( 'released_at' !== $ key ) { return $ value ; } return date ( 'Y-m-d H:i:s' , strtotime ( $ value ) ) ; } ) ; }
output for the versions API .
5,777
public function process ( $ source , $ force = true ) { list ( $ webRoot , $ source ) = $ this -> _findWebRoot ( $ source ) ; $ lessFile = FS :: clean ( $ webRoot . Configure :: read ( 'App.lessBaseUrl' ) . $ source , '/' ) ; $ this -> _setForce ( $ force ) ; $ less = new Less ( $ this -> _config ) ; if ( ! FS :: isFile ( $ lessFile ) ) { return null ; } list ( $ source , $ isExpired ) = $ less -> compile ( $ lessFile ) ; if ( $ isExpired ) { $ cacheId = FS :: firstLine ( $ source ) ; $ comment = '/* resource:' . str_replace ( FS :: clean ( ROOT , '/' ) , '' , $ lessFile ) . ' */' . PHP_EOL ; $ fileHead = implode ( '' , [ $ cacheId , Str :: low ( $ comment ) ] ) ; $ css = $ this -> _normalizeContent ( $ source , $ fileHead ) ; $ this -> _write ( $ source , $ css ) ; } $ source = str_replace ( FS :: clean ( APP_ROOT . '/' . Configure :: read ( 'App.webroot' ) , '/' ) , '' , $ source ) ; return $ source ; }
Process less file .
5,778
protected function _compress ( $ code , $ cacheId ) { $ code = ( string ) $ code ; $ code = preg_replace ( '#/\*[^*]*\*+([^/][^*]*\*+)*/#ius' , '' , $ code ) ; $ code = str_replace ( [ "\r\n" , "\r" , "\n" , "\t" , ' ' , ' ' , ' {' , '{ ' , ' }' , '; ' , ';;' , ';;;' , ';;;;' , ';}' ] , [ '' , '' , '' , '' , '' , '' , '{' , '{' , '}' , ';' , ';' , ';' , ';' , '}' ] , $ code ) ; $ code = preg_replace ( '#([a-z\-])(:\s*|\s*:\s*|\s*:)#ius' , '$1:' , $ code ) ; $ code = preg_replace ( '#(\s*\!important)#ius' , '!important' , $ code ) ; $ code = Str :: trim ( $ code ) ; return implode ( '' , [ $ cacheId , $ code ] ) ; }
CSS compressing .
5,779
protected function _findWebRoot ( $ source ) { $ webRootDir = Configure :: read ( 'App.webroot' ) ; $ webRoot = APP_ROOT . DS . $ webRootDir . DS ; list ( $ plugin , $ source ) = $ this -> _View -> pluginSplit ( $ source ) ; if ( $ plugin !== null && Plugin :: loaded ( $ plugin ) ) { $ webRoot = Plugin :: path ( $ plugin ) . $ webRootDir . DS ; } return [ FS :: clean ( $ webRoot , '/' ) , $ source ] ; }
Find source webroot dir .
5,780
protected function _getPlgAssetUrl ( $ path ) { $ isPlugin = false ; $ plgPaths = Configure :: read ( 'App.paths.plugins' ) ; foreach ( $ plgPaths as $ plgPath ) { $ plgPath = ltrim ( FS :: clean ( $ plgPath , '/' ) , '/' ) ; if ( preg_match ( '(' . quotemeta ( $ plgPath ) . ')' , $ path ) ) { $ path = str_replace ( $ plgPath , '' , $ path ) ; return [ true , $ path ] ; } } foreach ( Configure :: read ( 'plugins' ) as $ name => $ plgPath ) { $ plgPath = FS :: clean ( $ plgPath , '/' ) ; if ( preg_match ( '(' . quotemeta ( $ plgPath ) . ')' , $ path ) ) { $ path = Str :: low ( $ name ) . '/' . str_replace ( $ plgPath , '' , $ path ) ; return [ true , $ path ] ; } } return [ $ isPlugin , $ path ] ; }
Get plugin asset url .
5,781
protected function _normalizeContent ( $ path , $ fileHead ) { $ css = file_get_contents ( $ path ) ; if ( ! $ this -> _configRead ( 'debug' ) ) { $ css = $ this -> _compress ( $ css , $ fileHead ) ; } else { list ( $ first , $ second ) = explode ( PHP_EOL , $ css , 2 ) ; if ( preg_match ( '(\/* cacheid:)' , $ first ) ) { $ css = $ second ; } $ css = implode ( '' , [ $ fileHead , $ css ] ) ; } return $ this -> _replaceUrl ( $ css ) ; }
Normalize style file .
5,782
protected function _normalizePlgAssetUrl ( $ path ) { $ details = explode ( '/' , $ path , 3 ) ; $ pluginName = Inflector :: camelize ( trim ( $ details [ 0 ] , '/' ) ) ; if ( Plugin :: loaded ( $ pluginName ) ) { unset ( $ details [ 0 ] ) ; $ source = $ pluginName . '.' . ltrim ( implode ( '/' , $ details ) , '/' ) ; return $ this -> _getAssetUrl ( $ source ) ; } return $ this -> _getAssetUrl ( $ path ) ; }
Normalize plugin asset url .
5,783
protected function _replaceUrlCallback ( array $ match ) { $ assetPath = str_replace ( Router :: fullBaseUrl ( ) , '' , $ match [ 2 ] ) ; $ assetPath = trim ( FS :: clean ( $ assetPath , '/' ) , '/' ) ; $ appDir = trim ( FS :: clean ( APP_ROOT , '/' ) , '/' ) ; list ( $ isPlugin , $ assetPath ) = $ this -> _getPlgAssetUrl ( $ assetPath ) ; if ( ! $ isPlugin ) { $ assetPath = str_replace ( $ appDir , '' , $ assetPath ) ; } $ assetPath = str_replace ( Configure :: read ( 'App.webroot' ) , '' , $ assetPath ) ; $ assetPath = FS :: clean ( $ assetPath , '/' ) ; if ( $ isPlugin ) { return $ this -> _normalizePlgAssetUrl ( $ assetPath ) ; } return $ this -> _getAssetUrl ( $ assetPath ) ; }
Replace url callback .
5,784
protected function _write ( $ path , $ content ) { $ File = new File ( $ path ) ; $ File -> write ( $ content ) ; $ File -> exists ( ) ; }
Write content in to the file .
5,785
protected function _get_requester ( ) { $ this_class = get_class ( $ this ) ; $ this_class = explode ( '\\' , $ this_class ) ; $ this_class = array_pop ( $ this_class ) ; $ requester_class = '\Inc2734\WP_Share_Buttons\App\Model\Requester\\' . $ this_class ; if ( ! class_exists ( $ requester_class ) ) { return ; } return $ requester_class ; }
Return Requester class name
5,786
protected function saveContent ( string $ hash , string $ content ) : void { $ this -> adapter -> save ( $ this -> namespace , $ hash , $ content ) ; $ this -> cache [ $ hash ] = $ content ; }
Saves the specified content into the registry .
5,787
protected function loadContent ( string $ hash ) : ? string { if ( ! array_key_exists ( $ hash , $ this -> cache ) ) { $ content = $ this -> adapter -> load ( $ this -> namespace , $ hash ) ; $ this -> cache [ $ hash ] = is_string ( $ content ) ? $ content : null ; } return $ this -> cache [ $ hash ] ; }
Loads the content with the specified hash from the registry .
5,788
protected function deleteContent ( string $ hash ) : void { $ this -> adapter -> delete ( $ this -> namespace , $ hash ) ; unset ( $ this -> cache [ $ hash ] ) ; }
Deletes the content with the specified hash from the registry .
5,789
protected function decodeContent ( string $ content ) : array { $ result = json_decode ( $ content , true ) ; return is_array ( $ result ) ? $ result : [ ] ; }
Decodes the specified JSON content .
5,790
public function addClassToProcess ( $ className ) { if ( ! class_exists ( $ className ) ) { return false ; } $ this -> classesToProcess [ ( string ) $ className ] = true ; return true ; }
Adds a class to the list of classes to be processed
5,791
public static function instance ( ) { if ( ! isset ( self :: $ logger ) ) { self :: $ logger = new Logger ( self :: $ path ) ; } return self :: $ logger ; }
Returns Logger instance .
5,792
public function getCriteria ( ) { $ gets = $ this -> request -> get ( ) ; if ( empty ( $ this -> routeData ) ) { $ criteria = array ( ) ; } else { $ criteria = $ this -> routeData ; } foreach ( $ gets as $ key => $ value ) { if ( $ key [ 0 ] !== '!' ) { $ criteria [ $ key ] = $ value ; } } $ criteria = array_merge ( $ criteria , $ this -> getOr ( ) ) ; return $ criteria ; }
Get criteria of current request
5,793
public function create ( ) { $ entry = $ this -> collection -> newInstance ( ) -> set ( $ this -> getCriteria ( ) ) ; $ this -> data [ 'entry' ] = $ entry ; if ( $ this -> request -> isPost ( ) ) { try { $ result = $ entry -> set ( $ this -> request -> getBody ( ) ) -> save ( ) ; h ( 'notification.info' , $ this -> clazz . ' created.' ) ; h ( 'controller.create.success' , array ( 'model' => $ entry ) ) ; } catch ( Stop $ e ) { throw $ e ; } catch ( Exception $ e ) { h ( 'controller.create.error' , array ( 'model' => $ entry , 'error' => $ e , ) ) ; throw $ e ; } } }
Handle creation of new document .
5,794
public function schema ( $ schema = null ) { if ( func_num_args ( ) === 0 ) { return $ this -> collection -> schema ( ) ; } return $ this -> collection -> schema ( $ schema ) ; }
Get schema of collection
5,795
public function routeModel ( $ key ) { if ( ! isset ( $ this -> routeModels [ $ key ] ) ) { $ Clazz = Inflector :: classify ( $ key ) ; $ collection = Norm :: factory ( $ this -> schema ( $ key ) -> get ( 'foreign' ) ) ; $ this -> routeModels [ $ key ] = $ collection -> findOne ( $ this -> routeData ( $ key ) ) ; } return $ this -> routeModels [ $ key ] ; }
Register a route model .
5,796
public function dispatch ( Command $ command ) { if ( $ this -> _eventsManager -> fire ( 'command:beforeCommand' , $ command ) === false ) { return false ; } if ( $ command -> run ( $ command -> getParameters ( ) ) === false ) { return false ; } $ this -> _eventsManager -> fire ( 'command:afterCommand' , $ command ) ; return true ; }
Dispatch the Command
5,797
public function run ( ) { if ( ! isset ( $ _SERVER [ 'argv' ] [ 1 ] ) ) { $ _SERVER [ 'argv' ] [ 1 ] = 'commands' ; } $ input = $ _SERVER [ 'argv' ] [ 1 ] ; if ( in_array ( strtolower ( trim ( $ input ) ) , [ '-h' , '--help' , 'help' ] , true ) ) { $ input = $ _SERVER [ 'argv' ] [ 1 ] = 'commands' ; } if ( in_array ( strtolower ( trim ( $ input ) ) , [ '--version' , '-v' , '--info' ] , true ) ) { $ input = $ _SERVER [ 'argv' ] [ 1 ] = 'info' ; } foreach ( $ this -> _commands as $ command ) { if ( $ command -> hasIdentifier ( $ input ) ) { return $ this -> dispatch ( $ command ) ; } } $ available = [ ] ; foreach ( $ this -> _commands as $ command ) { $ providedCommands = $ command -> getCommands ( ) ; foreach ( $ providedCommands as $ alias ) { $ soundex = soundex ( $ alias ) ; if ( ! isset ( $ available [ $ soundex ] ) ) { $ available [ $ soundex ] = [ ] ; } $ available [ $ soundex ] [ ] = $ alias ; } } $ soundex = soundex ( $ input ) ; $ message = sprintf ( '%s is not a recognized command.' , $ input ) ; if ( isset ( $ available [ $ soundex ] ) ) { throw new ScriptException ( sprintf ( '%s Did you mean: %s?' , $ message , join ( ' or ' , $ available [ $ soundex ] ) ) ) ; } throw new ScriptException ( $ message ) ; }
Run the scripts
5,798
public static function fetch ( $ query , $ params = array ( ) , $ handler = null , $ arguments = array ( 'obj' ) ) { return Handler :: create ( $ handler ) -> fetch ( $ query , $ params , $ arguments ) ; }
Fetch data from an sql query Returns always an array of results
5,799
public static function run ( $ query , $ params = array ( ) , $ handler = null ) { return Handler :: create ( $ handler ) -> run ( $ query , $ params ) ; }
Run an sql statement will return the number of affected rows